tests/index.jsView |
---|
47 | 47 … | data: Buffer.from('test code'), |
48 | 48 … | ports: [portRef2] |
49 | 49 … | }) |
50 | 50 … | |
51 | | - rootContainer.createInstance(testVMContainer.typeId, initMessage) |
| 51 … | + await rootContainer.createInstance(testVMContainer.typeId, initMessage) |
52 | 52 … | |
53 | 53 … | await rootContainer.ports.bind('first', portRef1) |
54 | 54 … | message = rootContainer.createMessage() |
55 | 55 … | rootContainer.send(portRef1, message) |
56 | 56 … | |
57 | 57 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
58 | 58 … | t.deepEquals(stateRoot, expectedState, 'expected root!') |
59 | | - t.equals(hypervisor.scheduler.oldest(), 0) |
| 59 … | + t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
60 | 60 … | } catch (e) { |
61 | 61 … | console.log(e) |
62 | 62 … | } |
63 | 63 … | }) |
79 | 79 … | const root = await hypervisor.createInstance(testVMContainer.typeId) |
80 | 80 … | const [portRef1, portRef2] = root.ports.createChannel() |
81 | 81 … | |
82 | 82 … | await root.ports.bind('one', portRef1) |
83 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
| 83 … | + await root.createInstance(testVMContainer.typeId, root.createMessage({ |
84 | 84 … | ports: [portRef2] |
85 | 85 … | })) |
86 | 86 … | |
87 | 87 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
93 | 93 … | console.log(e) |
94 | 94 … | } |
95 | 95 … | }) |
96 | 96 … | |
97 | | - tape('one child contract with saturated ports', async t => { |
98 | | - t.plan(2) |
99 | | - let message |
100 | | - const expectedState = { |
101 | | - '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU' |
102 | | - } |
103 | | - |
104 | | - class testVMContainer2 extends BaseContainer { |
105 | | - onMessage (m) { |
106 | | - t.true(m === message, 'should recive a message') |
107 | | - } |
108 | | - static get typeId () { |
109 | | - return 99 |
110 | | - } |
111 | | - } |
112 | | - |
113 | | - class testVMContainer extends BaseContainer { |
114 | | - onMessage (m) { |
115 | | - const [portRef1, portRef2] = this.kernel.ports.createChannel() |
116 | | - this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
117 | | - ports: [portRef2] |
118 | | - })) |
119 | | - this.kernel.incrementTicks(2) |
120 | | - this.kernel.send(portRef1, m) |
121 | | - return this.kernel.ports.bind('child', portRef1) |
122 | | - } |
123 | | - } |
124 | | - |
125 | | - const hypervisor = new Hypervisor(node.dag) |
126 | | - hypervisor.registerContainer(testVMContainer) |
127 | | - hypervisor.registerContainer(testVMContainer2) |
128 | | - |
129 | | - const root = await hypervisor.createInstance(testVMContainer.typeId) |
130 | | - const [portRef1, portRef2] = root.ports.createChannel() |
131 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
132 | | - ports: [portRef2] |
133 | | - })) |
134 | | - |
135 | | - await root.ports.bind('first', portRef1) |
136 | | - message = root.createMessage({ |
137 | | - data: 'test' |
138 | | - }) |
139 | | - |
140 | | - root.send(portRef1, message) |
141 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
142 | | - |
143 | | - t.deepEquals(stateRoot, expectedState, 'expected state') |
144 | | - |
145 | | - |
146 | | - }) |
147 | | - |
148 | 97 … | tape('one child contract', async t => { |
149 | 98 … | t.plan(4) |
150 | 99 … | let message |
151 | 100 … | const expectedState = { |
170 | 119 … | } |
171 | 120 … | } |
172 | 121 … | |
173 | 122 … | class testVMContainer extends BaseContainer { |
174 | | - onMessage (m) { |
| 123 … | + async onMessage (m) { |
175 | 124 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
176 | | - this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
| 125 … | + await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
177 | 126 … | ports: [portRef2] |
178 | 127 … | })) |
179 | | - this.kernel.send(portRef1, m) |
| 128 … | + await this.kernel.send(portRef1, m) |
180 | 129 … | this.kernel.incrementTicks(1) |
181 | 130 … | return this.kernel.ports.bind('child', portRef1) |
182 | 131 … | } |
183 | 132 … | } |
188 | 137 … | |
189 | 138 … | let root = await hypervisor.createInstance(testVMContainer.typeId) |
190 | 139 … | const rootId = root.id |
191 | 140 … | const [portRef1, portRef2] = root.ports.createChannel() |
192 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
| 141 … | + await root.createInstance(testVMContainer.typeId, root.createMessage({ |
193 | 142 … | ports: [portRef2] |
194 | 143 … | })) |
195 | 144 … | |
196 | 145 … | await root.ports.bind('first', portRef1) |
197 | 146 … | message = root.createMessage() |
198 | 147 … | |
199 | | - root.send(portRef1, message) |
| 148 … | + await root.send(portRef1, message) |
200 | 149 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
201 | 150 … | t.true(hasResolved, 'should resolve before generating the state root') |
202 | 151 … | |
203 | 152 … | |
242 | 191 … | const message3 = this.kernel.createMessage({ |
243 | 192 … | ports: [portRef6] |
244 | 193 … | }) |
245 | 194 … | |
246 | | - this.kernel.createInstance(Root.typeId, message1) |
247 | | - this.kernel.createInstance(Root.typeId, message2) |
248 | | - this.kernel.createInstance(Root.typeId, message3) |
| 195 … | + await Promise.all([ |
| 196 … | + this.kernel.createInstance(Root.typeId, message1), |
| 197 … | + this.kernel.createInstance(Root.typeId, message2), |
| 198 … | + this.kernel.createInstance(Root.typeId, message3) |
| 199 … | + ]) |
249 | 200 … | |
250 | 201 … | throw new Error('it is a trap!!!') |
251 | 202 … | } |
252 | 203 … | } |
262 | 213 … | '/': 'zdpuAoifKuJkWz9Fjvt79NmGq3tcefhfCyq8iM8YhcFdV9bmZ' |
263 | 214 … | }, 'should revert the state') |
264 | 215 … | }) |
265 | 216 … | |
266 | | - tape('message should arrive in the correct oder if sent in order', async t => { |
| 217 … | + tape('recieving older messages', async t => { |
267 | 218 … | t.plan(2) |
268 | 219 … | let runs = 0 |
269 | 220 … | |
270 | 221 … | class Root extends BaseContainer { |
271 | | - onMessage (m) { |
| 222 … | + async onMessage (m) { |
272 | 223 … | if (!runs) { |
273 | 224 … | runs++ |
274 | | - |
275 | 225 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
276 | 226 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
277 | 227 … | |
278 | 228 … | const message1 = this.kernel.createMessage({ |
281 | 231 … | const message2 = this.kernel.createMessage({ |
282 | 232 … | ports: [portRef4] |
283 | 233 … | }) |
284 | 234 … | |
285 | | - this.kernel.createInstance(First.typeId, message1) |
286 | | - this.kernel.createInstance(Second.typeId, message2) |
287 | | - |
288 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
289 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
290 | | - return Promise.all( |
291 | | - this.kernel.ports.bind('two', portRef3), |
292 | | - this.kernel.ports.bind('one', portRef1) |
293 | | - ) |
| 235 … | + await Promise.all([ |
| 236 … | + this.kernel.createInstance(First.typeId, message1), |
| 237 … | + this.kernel.send(portRef1, this.kernel.createMessage()), |
| 238 … | + this.kernel.send(portRef3, this.kernel.createMessage()), |
| 239 … | + this.kernel.ports.bind('one', portRef1), |
| 240 … | + this.kernel.ports.bind('two', portRef3) |
| 241 … | + ]) |
| 242 … | + return this.kernel.createInstance(Waiter.typeId, message2) |
294 | 243 … | } else if (runs === 1) { |
295 | 244 … | runs++ |
296 | 245 … | t.equals(m.data, 'first', 'should recive the first message') |
297 | 246 … | } else if (runs === 2) { |
298 | | - t.equals(m.data, 'second', 'should recived the second message') |
299 | | - } |
300 | | - } |
301 | | - } |
302 | | - |
303 | | - class First extends BaseContainer { |
304 | | - onMessage (m) { |
305 | | - this.kernel.incrementTicks(2) |
306 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
307 | | - data: 'first' |
308 | | - })) |
309 | | - } |
310 | | - |
311 | | - static get typeId () { |
312 | | - return 99 |
313 | | - } |
314 | | - } |
315 | | - |
316 | | - class Second extends BaseContainer { |
317 | | - onMessage (m) { |
318 | | - this.kernel.incrementTicks(3) |
319 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
320 | | - data: 'second' |
321 | | - })) |
322 | | - } |
323 | | - |
324 | | - static get typeId () { |
325 | | - return 299 |
326 | | - } |
327 | | - } |
328 | | - |
329 | | - const hypervisor = new Hypervisor(node.dag) |
330 | | - |
331 | | - hypervisor.registerContainer(Root) |
332 | | - hypervisor.registerContainer(First) |
333 | | - hypervisor.registerContainer(Second) |
334 | | - |
335 | | - const root = await hypervisor.createInstance(Root.typeId) |
336 | | - |
337 | | - const [portRef1, portRef2] = root.ports.createChannel() |
338 | | - root.createInstance(Root.typeId, root.createMessage({ |
339 | | - ports: [portRef2] |
340 | | - })) |
341 | | - |
342 | | - await root.ports.bind('first', portRef1) |
343 | | - const message = root.createMessage() |
344 | | - root.send(portRef1, message) |
345 | | - }) |
346 | | - |
347 | | - tape('message should arrive in the correct oder if sent in order', async t => { |
348 | | - t.plan(2) |
349 | | - let runs = 0 |
350 | | - |
351 | | - class Root extends BaseContainer { |
352 | | - onMessage (m) { |
353 | | - if (!runs) { |
354 | 247 … | runs++ |
355 | | - |
356 | | - const [portRef1, portRef2] = this.kernel.ports.createChannel() |
357 | | - const [portRef3, portRef4] = this.kernel.ports.createChannel() |
358 | | - |
359 | | - const message1 = this.kernel.createMessage({ |
360 | | - ports: [portRef2] |
361 | | - }) |
362 | | - const message2 = this.kernel.createMessage({ |
363 | | - ports: [portRef4] |
364 | | - }) |
365 | | - |
366 | | - this.kernel.createInstance(First.typeId, message1) |
367 | | - this.kernel.createInstance(Second.typeId, message2) |
368 | | - |
369 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
370 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
371 | | - |
372 | | - return Promise.all([ |
373 | | - this.kernel.ports.bind('one', portRef1), |
374 | | - this.kernel.ports.bind('two', portRef3) |
375 | | - ]) |
376 | | - } else if (runs === 1) { |
| 248 … | + t.equals(m.data, 'second', 'should recive the second message') |
| 249 … | + } else if (runs === 3) { |
377 | 250 … | runs++ |
378 | | - t.equals(m.data, 'second', 'should recived the second message') |
379 | | - } else if (runs === 2) { |
380 | | - t.equals(m.data, 'first', 'should recive the first message') |
| 251 … | + |
381 | 252 … | } |
382 | 253 … | } |
383 | | - |
384 | 254 … | static get typeId () { |
385 | | - return 99 |
| 255 … | + return 299 |
386 | 256 … | } |
387 | 257 … | } |
388 | 258 … | |
389 | 259 … | class First extends BaseContainer { |
390 | 260 … | onMessage (m) { |
391 | 261 … | this.kernel.incrementTicks(2) |
392 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
393 | | - data: 'first' |
| 262 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 263 … | + data: 'second' |
394 | 264 … | })) |
395 | 265 … | } |
396 | | - |
397 | 266 … | static get typeId () { |
398 | | - return 299 |
| 267 … | + return 29 |
399 | 268 … | } |
400 | 269 … | } |
401 | 270 … | |
402 | | - class Second extends BaseContainer { |
| 271 … | + class Waiter extends BaseContainer { |
403 | 272 … | onMessage (m) { |
404 | | - this.kernel.incrementTicks(1) |
405 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
406 | | - data: 'second' |
407 | | - })) |
| 273 … | + return new Promise((resolve, reject) => { |
| 274 … | + setTimeout(() => { |
| 275 … | + this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 276 … | + data: 'first' |
| 277 … | + })).then(resolve) |
| 278 … | + }, 200) |
| 279 … | + }) |
408 | 280 … | } |
409 | 281 … | } |
410 | 282 … | |
411 | | - const hypervisor = new Hypervisor(node.dag) |
| 283 … | + try { |
| 284 … | + const hypervisor = new Hypervisor(node.dag) |
412 | 285 … | |
413 | | - hypervisor.registerContainer(Root) |
414 | | - hypervisor.registerContainer(First) |
415 | | - hypervisor.registerContainer(Second) |
| 286 … | + hypervisor.registerContainer(Root) |
| 287 … | + hypervisor.registerContainer(First) |
| 288 … | + hypervisor.registerContainer(Waiter) |
416 | 289 … | |
417 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 290 … | + const root = await hypervisor.createInstance(Root.typeId) |
| 291 … | + const [portRef1, portRef2] = root.ports.createChannel() |
418 | 292 … | |
419 | | - const [portRef1, portRef2] = root.ports.createChannel() |
420 | | - root.createInstance(Root.typeId, root.createMessage({ |
421 | | - ports: [portRef2] |
422 | | - })) |
423 | | - |
424 | | - await root.ports.bind('first', portRef1) |
425 | | - const message = root.createMessage() |
426 | | - root.send(portRef1, message) |
427 | | - }) |
428 | | - |
429 | | - tape('message should arrive in the correct oder if sent in order', async t => { |
430 | | - t.plan(2) |
431 | | - let runs = 0 |
432 | | - |
433 | | - class Root extends BaseContainer { |
434 | | - onMessage (m) { |
435 | | - if (!runs) { |
436 | | - runs++ |
437 | | - const [portRef1, portRef2] = this.kernel.ports.createChannel() |
438 | | - const [portRef3, portRef4] = this.kernel.ports.createChannel() |
439 | | - |
440 | | - const message1 = this.kernel.createMessage({ |
441 | | - ports: [portRef2] |
442 | | - }) |
443 | | - const message2 = this.kernel.createMessage({ |
444 | | - ports: [portRef4] |
445 | | - }) |
446 | | - |
447 | | - this.kernel.createInstance(First.typeId, message1) |
448 | | - this.kernel.createInstance(Second.typeId, message2) |
449 | | - |
450 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
451 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
452 | | - |
453 | | - this.kernel.incrementTicks(6) |
454 | | - |
455 | | - return Promise.all([ |
456 | | - this.kernel.ports.bind('one', portRef1), |
457 | | - this.kernel.ports.bind('two', portRef3) |
458 | | - ]) |
459 | | - } else if (runs === 1) { |
460 | | - runs++ |
461 | | - t.equals(m.data, 'first', 'should recive the first message') |
462 | | - } else if (runs === 2) { |
463 | | - t.equals(m.data, 'second', 'should recived the second message') |
464 | | - } |
465 | | - } |
466 | | - static get typeId () { |
467 | | - return 299 |
468 | | - } |
469 | | - } |
470 | | - |
471 | | - class First extends BaseContainer { |
472 | | - onMessage (m) { |
473 | | - this.kernel.incrementTicks(1) |
474 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
475 | | - data: 'first' |
| 293 … | + const message = root.createMessage() |
| 294 … | + await Promise.all([ |
| 295 … | + root.send(portRef1, message), |
| 296 … | + root.ports.bind('first', portRef1), |
| 297 … | + root.createInstance(Root.typeId, root.createMessage({ |
| 298 … | + ports: [portRef2] |
476 | 299 … | })) |
477 | | - } |
478 | | - static get typeId () { |
479 | | - return 2 |
480 | | - } |
| 300 … | + ]) |
| 301 … | + } catch (e) { |
| 302 … | + console.log(e) |
481 | 303 … | } |
482 | | - |
483 | | - class Second extends BaseContainer { |
484 | | - onMessage (m) { |
485 | | - this.kernel.incrementTicks(2) |
486 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
487 | | - data: 'second' |
488 | | - })) |
489 | | - } |
490 | | - } |
491 | | - |
492 | | - const hypervisor = new Hypervisor(node.dag) |
493 | | - |
494 | | - hypervisor.registerContainer(Root) |
495 | | - hypervisor.registerContainer(First) |
496 | | - hypervisor.registerContainer(Second) |
497 | | - |
498 | | - const root = await hypervisor.createInstance(Root.typeId) |
499 | | - const [portRef1, portRef2] = root.ports.createChannel() |
500 | | - root.createInstance(Root.typeId, root.createMessage({ |
501 | | - ports: [portRef2] |
502 | | - })) |
503 | | - |
504 | | - await root.ports.bind('first', portRef1) |
505 | | - const message = root.createMessage() |
506 | | - root.send(portRef1, message) |
507 | 304 … | }) |
508 | 305 … | |
509 | 306 … | tape('saturation', async t => { |
510 | | - t.plan(2) |
| 307 … | + t.plan(3) |
511 | 308 … | let runs = 0 |
512 | 309 … | |
513 | 310 … | class Root extends BaseContainer { |
514 | | - onMessage (m) { |
| 311 … | + onIdle () {} |
| 312 … | + async onMessage (m) { |
515 | 313 … | if (!runs) { |
516 | 314 … | runs++ |
517 | 315 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
518 | 316 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
523 | 321 … | const message2 = this.kernel.createMessage({ |
524 | 322 … | ports: [portRef4] |
525 | 323 … | }) |
526 | 324 … | |
527 | | - this.kernel.createInstance(First.typeId, message1) |
528 | | - this.kernel.createInstance(Second.typeId, message2) |
529 | | - |
530 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
531 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
532 | | - |
533 | 325 … | this.kernel.incrementTicks(6) |
534 | 326 … | return Promise.all([ |
| 327 … | + this.kernel.createInstance(First.typeId, message1), |
| 328 … | + this.kernel.createInstance(Second.typeId, message2), |
| 329 … | + this.kernel.send(portRef1, this.kernel.createMessage()), |
| 330 … | + this.kernel.send(portRef3, this.kernel.createMessage()), |
535 | 331 … | this.kernel.ports.bind('one', portRef1), |
536 | 332 … | this.kernel.ports.bind('two', portRef3) |
537 | 333 … | ]) |
538 | 334 … | } else if (runs === 1) { |
539 | 335 … | runs++ |
540 | 336 … | t.equals(m.data, 'first', 'should recive the first message') |
541 | 337 … | } else if (runs === 2) { |
542 | 338 … | runs++ |
543 | | - t.equals(m.data, 'second', 'should recived the second message') |
| 339 … | + t.equals(m.data, 'second', 'should recive the second message') |
| 340 … | + } else if (runs === 3) { |
| 341 … | + runs++ |
| 342 … | + t.equals(m.data, 'third', 'should recived the third message') |
544 | 343 … | } |
545 | 344 … | } |
546 | 345 … | static get typeId () { |
547 | 346 … | return 299 |
550 | 349 … | |
551 | 350 … | class First extends BaseContainer { |
552 | 351 … | onMessage (m) { |
553 | 352 … | this.kernel.incrementTicks(2) |
554 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
555 | | - data: 'first' |
| 353 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 354 … | + data: 'second' |
556 | 355 … | })) |
557 | 356 … | } |
558 | 357 … | static get typeId () { |
559 | 358 … | return 29 |
562 | 361 … | |
563 | 362 … | class Second extends BaseContainer { |
564 | 363 … | onMessage (m) { |
565 | 364 … | this.kernel.incrementTicks(3) |
566 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
567 | | - data: 'second' |
| 365 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 366 … | + data: 'third' |
568 | 367 … | })) |
569 | 368 … | } |
570 | 369 … | static get typeId () { |
571 | 370 … | return 2 |
572 | 371 … | } |
573 | 372 … | } |
574 | 373 … | |
575 | 374 … | class Waiter extends BaseContainer { |
576 | | - onCreation () { |
| 375 … | + onCreation (m) { |
577 | 376 … | return new Promise((resolve, reject) => { |
578 | 377 … | setTimeout(() => { |
579 | | - resolve() |
| 378 … | + this.kernel.send(m.ports[0], this.kernel.createMessage({ |
| 379 … | + data: 'first' |
| 380 … | + })).then(resolve) |
580 | 381 … | }, 200) |
581 | 382 … | }) |
582 | 383 … | } |
583 | 384 … | } |
584 | 385 … | |
585 | | - const hypervisor = new Hypervisor(node.dag) |
| 386 … | + try { |
| 387 … | + const hypervisor = new Hypervisor(node.dag) |
586 | 388 … | |
587 | | - hypervisor.registerContainer(Root) |
588 | | - hypervisor.registerContainer(First) |
589 | | - hypervisor.registerContainer(Second) |
590 | | - hypervisor.registerContainer(Waiter) |
| 389 … | + hypervisor.registerContainer(Root) |
| 390 … | + hypervisor.registerContainer(First) |
| 391 … | + hypervisor.registerContainer(Second) |
| 392 … | + hypervisor.registerContainer(Waiter) |
591 | 393 … | |
592 | | - const root = await hypervisor.createInstance(Root.typeId) |
593 | | - const [portRef1, portRef2] = root.ports.createChannel() |
| 394 … | + let root = await hypervisor.createInstance(Root.typeId) |
| 395 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 396 … | + const [portRef3, portRef4] = root.ports.createChannel() |
594 | 397 … | |
595 | | - const message = root.createMessage() |
596 | | - root.send(portRef1, message) |
597 | | - await root.ports.bind('first', portRef1) |
598 | | - root.createInstance(Root.typeId, root.createMessage({ |
599 | | - ports: [portRef2] |
600 | | - })) |
601 | | - |
602 | | - const [portRef3, portRef4] = root.ports.createChannel() |
603 | | - await root.ports.bind('sencond', portRef3) |
604 | | - root.createInstance(Waiter.typeId, root.createMessage({ |
605 | | - ports: [portRef4] |
606 | | - })) |
607 | | - |
608 | | - root.incrementTicks(100) |
609 | | - root.send(portRef1, root.createMessage({data: 'testss'})) |
610 | | - hypervisor.scheduler.done(root.id) |
611 | | - }) |
612 | | - |
613 | | - tape('message should arrive in the correct order, even in a tie of ticks', async t => { |
614 | | - t.plan(2) |
615 | | - |
616 | | - let runs = 0 |
617 | | - |
618 | | - class Root extends BaseContainer { |
619 | | - onMessage (m) { |
620 | | - if (!runs) { |
621 | | - runs++ |
622 | | - const [portRef1, portRef2] = this.kernel.ports.createChannel() |
623 | | - const [portRef3, portRef4] = this.kernel.ports.createChannel() |
624 | | - |
625 | | - const message1 = this.kernel.createMessage({ |
626 | | - ports: [portRef2] |
627 | | - }) |
628 | | - const message2 = this.kernel.createMessage({ |
629 | | - ports: [portRef4] |
630 | | - }) |
631 | | - |
632 | | - this.kernel.createInstance(First.typeId, message1) |
633 | | - this.kernel.createInstance(Second.typeId, message2) |
634 | | - |
635 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
636 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
637 | | - |
638 | | - this.kernel.incrementTicks(6) |
639 | | - return Promise.all([ |
640 | | - this.kernel.ports.bind('two', portRef3), |
641 | | - this.kernel.ports.bind('one', portRef1) |
642 | | - ]) |
643 | | - } else if (runs === 1) { |
644 | | - runs++ |
645 | | - t.equals(m.data, 'second', 'should recived the second message') |
646 | | - } else if (runs === 2) { |
647 | | - t.equals(m.data, 'first', 'should recive the first message') |
648 | | - } |
649 | | - } |
650 | | - static get typeId () { |
651 | | - return 299 |
652 | | - } |
653 | | - } |
654 | | - |
655 | | - class First extends BaseContainer { |
656 | | - onMessage (m) { |
657 | | - this.kernel.incrementTicks(2) |
658 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
659 | | - data: 'first' |
| 398 … | + const message = root.createMessage() |
| 399 … | + await Promise.all([ |
| 400 … | + root.send(portRef1, message), |
| 401 … | + root.ports.bind('first', portRef1), |
| 402 … | + root.createInstance(Root.typeId, root.createMessage({ |
| 403 … | + ports: [portRef2] |
| 404 … | + })), |
| 405 … | + root.ports.bind('sencond', portRef3), |
| 406 … | + root.createInstance(Waiter.typeId, root.createMessage({ |
| 407 … | + ports: [portRef4] |
660 | 408 … | })) |
661 | | - } |
662 | | - static get typeId () { |
663 | | - return 29 |
664 | | - } |
665 | | - } |
| 409 … | + ]) |
666 | 410 … | |
667 | | - class Second extends BaseContainer { |
668 | | - onMessage (m) { |
669 | | - this.kernel.incrementTicks(2) |
670 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
671 | | - data: 'second' |
672 | | - })) |
673 | | - } |
674 | | - static get typeId () { |
675 | | - return 2 |
676 | | - } |
| 411 … | + |
| 412 … | + root.incrementTicks(100) |
| 413 … | + await root.send(portRef1, root.createMessage({data: 'testss'})) |
| 414 … | + root.shutdown() |
| 415 … | + } catch (e) { |
| 416 … | + console.log(e) |
677 | 417 … | } |
678 | | - |
679 | | - const hypervisor = new Hypervisor(node.dag) |
680 | | - |
681 | | - hypervisor.registerContainer(Root) |
682 | | - hypervisor.registerContainer(First) |
683 | | - hypervisor.registerContainer(Second) |
684 | | - |
685 | | - const root = await hypervisor.createInstance(Root.typeId) |
686 | | - const [portRef1, portRef2] = root.ports.createChannel() |
687 | | - const message = root.createMessage() |
688 | | - |
689 | | - root.send(portRef1, message) |
690 | | - await root.ports.bind('first', portRef1) |
691 | | - root.createInstance(Root.typeId, root.createMessage({ |
692 | | - ports: [portRef2] |
693 | | - })) |
694 | 418 … | }) |
695 | 419 … | |
696 | | - tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
697 | | - t.plan(2) |
698 | | - |
699 | | - let runs = 0 |
700 | | - |
701 | | - class Root extends BaseContainer { |
702 | | - async onMessage (m) { |
703 | | - if (!runs) { |
704 | | - runs++ |
705 | | - const [portRef1, portRef2] = this.kernel.ports.createChannel() |
706 | | - const [portRef3, portRef4] = this.kernel.ports.createChannel() |
707 | | - |
708 | | - await this.kernel.ports.bind('one', portRef1) |
709 | | - await this.kernel.ports.bind('two', portRef3) |
710 | | - |
711 | | - const message1 = this.kernel.createMessage({ |
712 | | - ports: [portRef2] |
713 | | - }) |
714 | | - const message2 = this.kernel.createMessage({ |
715 | | - ports: [portRef4] |
716 | | - }) |
717 | | - |
718 | | - this.kernel.createInstance(First.typeId, message1) |
719 | | - this.kernel.createInstance(Second.typeId, message2) |
720 | | - |
721 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
722 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
723 | | - |
724 | | - this.kernel.incrementTicks(6) |
725 | | - } else if (runs === 1) { |
726 | | - runs++ |
727 | | - t.equals(m.data, 'first', 'should recive the first message') |
728 | | - } else if (runs === 2) { |
729 | | - t.equals(m.data, 'second', 'should recived the second message') |
730 | | - } |
731 | | - } |
732 | | - static get typeId () { |
733 | | - return 299 |
734 | | - } |
735 | | - } |
736 | | - |
737 | | - class First extends BaseContainer { |
738 | | - onMessage (m) { |
739 | | - this.kernel.incrementTicks(2) |
740 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
741 | | - data: 'first' |
742 | | - })) |
743 | | - } |
744 | | - static get typeId () { |
745 | | - return 29 |
746 | | - } |
747 | | - } |
748 | | - |
749 | | - class Second extends BaseContainer { |
750 | | - onMessage (m) { |
751 | | - this.kernel.incrementTicks(2) |
752 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
753 | | - data: 'second' |
754 | | - })) |
755 | | - } |
756 | | - } |
757 | | - |
758 | | - const hypervisor = new Hypervisor(node.dag) |
759 | | - |
760 | | - hypervisor.registerContainer(Root) |
761 | | - hypervisor.registerContainer(First) |
762 | | - hypervisor.registerContainer(Second) |
763 | | - |
764 | | - const root = await hypervisor.createInstance(Root.typeId) |
765 | | - const [portRef1, portRef2] = root.ports.createChannel() |
766 | | - const message = root.createMessage() |
767 | | - |
768 | | - root.send(portRef1, message) |
769 | | - await root.ports.bind('first', portRef1) |
770 | | - root.createInstance(Root.typeId, root.createMessage({ |
771 | | - ports: [portRef2] |
772 | | - })) |
773 | | - }) |
774 | | - |
775 | 420 … | tape('send to the same container at the same time', async t => { |
776 | 421 … | t.plan(2) |
777 | 422 … | |
778 | 423 … | let runs = 0 |
779 | 424 … | let instance |
780 | 425 … | |
781 | 426 … | class Root extends BaseContainer { |
782 | | - onMessage (m) { |
| 427 … | + async onMessage (m) { |
783 | 428 … | let one = this.kernel.ports.get('one') |
784 | 429 … | if (!one) { |
785 | 430 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
786 | 431 … | const message1 = this.kernel.createMessage({ |
787 | 432 … | ports: [portRef2] |
788 | 433 … | }) |
789 | | - this.kernel.createInstance(First.typeId, message1) |
| 434 … | + await this.kernel.createInstance(First.typeId, message1) |
790 | 435 … | return this.kernel.ports.bind('one', portRef1) |
791 | 436 … | } else { |
792 | | - this.kernel.send(one, this.kernel.createMessage()) |
793 | | - this.kernel.send(one, this.kernel.createMessage()) |
| 437 … | + return Promise.all([ |
| 438 … | + this.kernel.send(one, this.kernel.createMessage()), |
| 439 … | + this.kernel.send(one, this.kernel.createMessage()) |
| 440 … | + ]) |
794 | 441 … | } |
795 | 442 … | } |
796 | 443 … | static get typeId () { |
797 | 444 … | return 299 |
808 | 455 … | } |
809 | 456 … | } |
810 | 457 … | } |
811 | 458 … | |
812 | | - const hypervisor = new Hypervisor(node.dag) |
| 459 … | + try { |
| 460 … | + const hypervisor = new Hypervisor(node.dag) |
813 | 461 … | |
814 | | - hypervisor.registerContainer(Root) |
815 | | - hypervisor.registerContainer(First) |
| 462 … | + hypervisor.registerContainer(Root) |
| 463 … | + hypervisor.registerContainer(First) |
816 | 464 … | |
817 | | - const root = await hypervisor.createInstance(Root.typeId) |
818 | | - const [portRef1, portRef2] = root.ports.createChannel() |
819 | | - await root.ports.bind('first', portRef1) |
820 | | - root.createInstance(Root.typeId, root.createMessage({ |
821 | | - ports: [portRef2] |
822 | | - })) |
| 465 … | + const root = await hypervisor.createInstance(Root.typeId) |
| 466 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 467 … | + await Promise.all([ |
| 468 … | + root.ports.bind('first', portRef1), |
| 469 … | + root.createInstance(Root.typeId, root.createMessage({ |
| 470 … | + ports: [portRef2] |
| 471 … | + })) |
| 472 … | + ]) |
823 | 473 … | |
824 | | - const message = root.createMessage() |
825 | | - root.send(portRef1, message) |
826 | | - await hypervisor.createStateRoot() |
827 | | - root.send(portRef1, root.createMessage()) |
828 | | - await hypervisor.createStateRoot() |
829 | | - t.equals(runs, 2) |
| 474 … | + const message = root.createMessage() |
| 475 … | + await root.send(portRef1, message) |
| 476 … | + await hypervisor.createStateRoot() |
| 477 … | + await root.send(portRef1, root.createMessage()) |
| 478 … | + await hypervisor.createStateRoot() |
| 479 … | + t.equals(runs, 2) |
| 480 … | + } catch (e) { |
| 481 … | + console.log(e) |
| 482 … | + } |
830 | 483 … | }) |
831 | 484 … | |
832 | 485 … | tape('checking ports', async t => { |
833 | 486 … | t.plan(4) |
874 | 527 … | const expectedSr = { |
875 | 528 … | '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
876 | 529 … | } |
877 | 530 … | class Root extends BaseContainer { |
878 | | - onMessage (m) { |
| 531 … | + async onMessage (m) { |
879 | 532 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
880 | 533 … | const message1 = this.kernel.createMessage({ |
881 | 534 … | ports: [portRef2] |
882 | 535 … | }) |
883 | 536 … | |
884 | | - this.kernel.createInstance(First.typeId, message1) |
885 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
| 537 … | + await this.kernel.createInstance(First.typeId, message1) |
| 538 … | + await this.kernel.send(portRef1, this.kernel.createMessage()) |
886 | 539 … | this.kernel.incrementTicks(6) |
887 | 540 … | return this.kernel.ports.bind('one', portRef1) |
888 | 541 … | } |
889 | 542 … | } |
890 | 543 … | |
891 | 544 … | class First extends BaseContainer { |
892 | 545 … | onMessage (m) { |
893 | 546 … | this.kernel.incrementTicks(2) |
894 | | - this.kernel.ports.delete('root') |
| 547 … | + return this.kernel.ports.delete('root') |
895 | 548 … | } |
896 | 549 … | static get typeId () { |
897 | 550 … | return 299 |
898 | 551 … | } |
905 | 558 … | |
906 | 559 … | const root = await hypervisor.createInstance(Root.typeId) |
907 | 560 … | const [portRef1, portRef2] = root.ports.createChannel() |
908 | 561 … | await root.ports.bind('first', portRef1) |
909 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 562 … | + await root.createInstance(Root.typeId, root.createMessage({ |
910 | 563 … | ports: [portRef2] |
911 | 564 … | })) |
912 | 565 … | |
913 | 566 … | const message = root.createMessage() |
914 | | - root.send(portRef1, message) |
| 567 … | + await root.send(portRef1, message) |
915 | 568 … | |
916 | 569 … | const sr = await hypervisor.createStateRoot() |
917 | 570 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
918 | 571 … | await hypervisor.graph.tree(sr, Infinity, true) |
925 | 578 … | '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
926 | 579 … | } |
927 | 580 … | class Root extends BaseContainer { |
928 | 581 … | onMessage (m) { |
929 | | - this.kernel.createInstance(Root.typeId) |
| 582 … | + return this.kernel.createInstance(Root.typeId) |
930 | 583 … | } |
931 | 584 … | } |
932 | 585 … | |
933 | 586 … | const hypervisor = new Hypervisor(node.dag) |
934 | | - |
935 | 587 … | hypervisor.registerContainer(Root) |
936 | 588 … | |
937 | 589 … | const root = await hypervisor.createInstance(Root.typeId) |
938 | 590 … | const [portRef1, portRef2] = root.ports.createChannel() |
939 | 591 … | await root.ports.bind('first', portRef1) |
940 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 592 … | + await root.createInstance(Root.typeId, root.createMessage({ |
941 | 593 … | ports: [portRef2] |
942 | 594 … | })) |
943 | 595 … | |
944 | 596 … | const message = root.createMessage() |
945 | | - root.send(portRef1, message) |
| 597 … | + await root.send(portRef1, message) |
946 | 598 … | const sr = await hypervisor.createStateRoot() |
947 | 599 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
948 | 600 … | |
949 | 601 … | t.end() |
955 | 607 … | } |
956 | 608 … | class Root extends BaseContainer { |
957 | 609 … | onMessage (m) { |
958 | 610 … | const [, portRef2] = this.kernel.ports.createChannel() |
959 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 611 … | + return this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
960 | 612 … | ports: [portRef2] |
961 | 613 … | })) |
962 | 614 … | } |
963 | 615 … | } |
966 | 618 … | async onInitailize (message) { |
967 | 619 … | await this.kernel.ports.bind('root', message.ports[0]) |
968 | 620 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
969 | 621 … | await this.kernel.ports.bind('child', portRef1) |
970 | | - this.kernel.createInstance(Root.typeId, this.kernel.createMessage({ |
| 622 … | + await this.kernel.createInstance(Root.typeId, this.kernel.createMessage({ |
971 | 623 … | ports: [portRef2] |
972 | 624 … | })) |
973 | 625 … | } |
974 | 626 … | static get typeId () { |
975 | 627 … | return 299 |
976 | 628 … | } |
977 | 629 … | } |
978 | 630 … | |
979 | | - const hypervisor = new Hypervisor(node.dag) |
| 631 … | + try { |
| 632 … | + const hypervisor = new Hypervisor(node.dag) |
980 | 633 … | |
981 | | - hypervisor.registerContainer(Root) |
982 | | - hypervisor.registerContainer(Sub) |
| 634 … | + hypervisor.registerContainer(Root) |
| 635 … | + hypervisor.registerContainer(Sub) |
983 | 636 … | |
984 | | - const root = await hypervisor.createInstance(Root.typeId) |
985 | | - const [portRef1, portRef2] = root.ports.createChannel() |
986 | | - await root.ports.bind('first', portRef1) |
987 | | - root.createInstance(Root.typeId, root.createMessage({ |
988 | | - ports: [portRef2] |
989 | | - })) |
| 637 … | + const root = await hypervisor.createInstance(Root.typeId) |
| 638 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 639 … | + await root.ports.bind('first', portRef1) |
| 640 … | + await root.createInstance(Root.typeId, root.createMessage({ |
| 641 … | + ports: [portRef2] |
| 642 … | + })) |
990 | 643 … | |
991 | | - root.send(portRef1, root.createMessage()) |
992 | | - const sr = await hypervisor.createStateRoot() |
| 644 … | + await root.send(portRef1, root.createMessage()) |
| 645 … | + const sr = await hypervisor.createStateRoot() |
993 | 646 … | |
994 | | - t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
995 | | - t.end() |
| 647 … | + t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
| 648 … | + t.end() |
| 649 … | + } catch (e) { |
| 650 … | + console.log(e) |
| 651 … | + } |
996 | 652 … | }) |
997 | 653 … | |
998 | 654 … | tape('should not remove connected nodes', async t => { |
999 | 655 … | const expectedSr = { |
1002 | 658 … | class Root extends BaseContainer { |
1003 | 659 … | async onMessage (m) { |
1004 | 660 … | if (m.ports.length) { |
1005 | 661 … | const port = this.kernel.ports.get('test1') |
1006 | | - this.kernel.send(port, m) |
| 662 … | + await this.kernel.send(port, m) |
1007 | 663 … | return this.kernel.ports.unbind('test1') |
1008 | 664 … | } else { |
1009 | 665 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1010 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 666 … | + await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1011 | 667 … | ports: [portRef2] |
1012 | 668 … | })) |
1013 | 669 … | await this.kernel.ports.bind('test1', portRef1) |
1014 | 670 … | |
1015 | 671 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1016 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 672 … | + await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1017 | 673 … | ports: [portRef4] |
1018 | 674 … | })) |
1019 | 675 … | await this.kernel.ports.bind('test2', portRef3) |
1020 | | - this.kernel.send(portRef3, this.kernel.createMessage({ |
| 676 … | + await this.kernel.send(portRef3, this.kernel.createMessage({ |
1021 | 677 … | data: 'getChannel' |
1022 | 678 … | })) |
1023 | 679 … | } |
1024 | 680 … | } |
1025 | 681 … | } |
1026 | 682 … | |
1027 | 683 … | class Sub extends BaseContainer { |
1028 | | - onMessage (message) { |
| 684 … | + async onMessage (message) { |
1029 | 685 … | if (message.data === 'getChannel') { |
1030 | 686 … | const ports = this.kernel.ports.createChannel() |
1031 | | - this.kernel.send(message.fromPort, this.kernel.createMessage({ |
| 687 … | + await this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1032 | 688 … | data: 'bindPort', |
1033 | 689 … | ports: [ports[1]] |
1034 | 690 … | })) |
1035 | 691 … | return this.kernel.ports.bind('channel', ports[0]) |
1049 | 705 … | |
1050 | 706 … | const root = await hypervisor.createInstance(Root.typeId) |
1051 | 707 … | const [portRef1, portRef2] = root.ports.createChannel() |
1052 | 708 … | await root.ports.bind('first', portRef1) |
1053 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 709 … | + await root.createInstance(Root.typeId, root.createMessage({ |
1054 | 710 … | ports: [portRef2] |
1055 | 711 … | })) |
1056 | 712 … | |
1057 | | - root.send(portRef1, root.createMessage()) |
| 713 … | + await root.send(portRef1, root.createMessage()) |
1058 | 714 … | const sr = await hypervisor.createStateRoot() |
1059 | 715 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1060 | 716 … | |
1061 | 717 … | |
1063 | 719 … | }) |
1064 | 720 … | |
1065 | 721 … | tape('should remove multiple subgraphs', async t => { |
1066 | 722 … | const expectedSr = { |
1067 | | - '/': 'zdpuAohccQTxM82d8N6Q82z234nQskeQoJGJu3eAVmxoQwWde' |
| 723 … | + '/': 'zdpuArkZ5yNowNnU4qJ8vayAUncgibQP9goDP1CwFxdmPJF9D' |
1068 | 724 … | } |
1069 | 725 … | class Root extends BaseContainer { |
1070 | | - async onMessage (m) { |
| 726 … | + onMessage (m) { |
1071 | 727 … | if (m.ports.length) { |
1072 | 728 … | const port = this.kernel.ports.get('test1') |
1073 | | - this.kernel.send(port, m) |
1074 | | - await this.kernel.ports.unbind('test1') |
1075 | | - await this.kernel.ports.unbind('test2') |
| 729 … | + return Promise.all([ |
| 730 … | + this.kernel.send(port, m), |
| 731 … | + this.kernel.ports.unbind('test1'), |
| 732 … | + this.kernel.ports.unbind('test2') |
| 733 … | + ]) |
1076 | 734 … | } else { |
1077 | 735 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1078 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1079 | | - ports: [portRef2] |
1080 | | - })) |
1081 | | - await this.kernel.ports.bind('test1', portRef1) |
1082 | | - |
1083 | 736 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1084 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1085 | | - ports: [portRef4] |
1086 | | - })) |
1087 | | - await this.kernel.ports.bind('test2', portRef3) |
1088 | | - this.kernel.send(portRef3, this.kernel.createMessage({ |
1089 | | - data: 'getChannel' |
1090 | | - })) |
| 737 … | + return Promise.all([ |
| 738 … | + this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 739 … | + ports: [portRef2] |
| 740 … | + })), |
| 741 … | + this.kernel.ports.bind('test1', portRef1), |
| 742 … | + this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 743 … | + ports: [portRef4] |
| 744 … | + })), |
| 745 … | + this.kernel.ports.bind('test2', portRef3), |
| 746 … | + this.kernel.send(portRef3, this.kernel.createMessage({ |
| 747 … | + data: 'getChannel' |
| 748 … | + })) |
| 749 … | + ]) |
1091 | 750 … | } |
1092 | 751 … | } |
1093 | 752 … | } |
1094 | 753 … | |
1095 | 754 … | class Sub extends BaseContainer { |
1096 | | - onMessage (message) { |
| 755 … | + async onMessage (message) { |
1097 | 756 … | if (message.data === 'getChannel') { |
1098 | 757 … | const ports = this.kernel.ports.createChannel() |
1099 | | - this.kernel.send(message.fromPort, this.kernel.createMessage({ |
| 758 … | + await this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1100 | 759 … | data: 'bindPort', |
1101 | 760 … | ports: [ports[1]] |
1102 | 761 … | })) |
1103 | 762 … | return this.kernel.ports.bind('channel', ports[0]) |
1109 | 768 … | return 299 |
1110 | 769 … | } |
|
1111 | 770 … | } |
1112 | 771 … | |
1113 | | - const hypervisor = new Hypervisor(node.dag) |
| 772 … | + try { |
| 773 … | + const hypervisor = new Hypervisor(node.dag) |
1114 | 774 … | |
1115 | | - hypervisor.registerContainer(Root) |
1116 | | - hypervisor.registerContainer(Sub) |
| 775 … | + hypervisor.registerContainer(Root) |
| 776 … | + hypervisor.registerContainer(Sub) |
1117 | 777 … | |
1118 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 778 … | + const root = await hypervisor.createInstance(Root.typeId) |
1119 | 779 … | |
1120 | | - const [portRef1, portRef2] = root.ports.createChannel() |
1121 | | - await root.ports.bind('first', portRef1) |
1122 | | - root.createInstance(Root.typeId, root.createMessage({ |
1123 | | - ports: [portRef2] |
1124 | | - })) |
| 780 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 781 … | + await Promise.all([ |
| 782 … | + root.ports.bind('first', portRef1), |
| 783 … | + root.createInstance(Root.typeId, root.createMessage({ |
| 784 … | + ports: [portRef2] |
| 785 … | + })), |
| 786 … | + root.send(portRef1, root.createMessage()) |
| 787 … | + ]) |
1125 | 788 … | |
1126 | | - root.send(portRef1, root.createMessage()) |
| 789 … | + const sr = await hypervisor.createStateRoot() |
| 790 … | + t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1127 | 791 … | |
1128 | | - const sr = await hypervisor.createStateRoot() |
1129 | | - t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1130 | | - |
1131 | | - t.end() |
| 792 … | + t.end() |
| 793 … | + } catch (e) { |
| 794 … | + console.log(e) |
| 795 … | + } |
1132 | 796 … | }) |
1133 | 797 … | |
1134 | 798 … | tape('response ports', async t => { |
1135 | 799 … | t.plan(2) |