Commit d0da8197e290a0f7d27a4b08cbc89d00cf1ca258
clean up tests a bit
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 8/11/2017, 2:48:43 AM
Parent: 2fb975398cfb471a241d9576050158a86e8eff04
Files changed
tests/index.js | changed |
tests/index.js | ||
---|---|---|
@@ -93,62 +93,8 @@ | ||
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 | - async onMessage (m) { | |
115 | - const [portRef1, portRef2] = this.kernel.ports.createChannel() | |
116 | - await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ | |
117 | - ports: [portRef2] | |
118 | - })) | |
119 | - this.kernel.incrementTicks(2) | |
120 | - | |
121 | - return Promise.all([ | |
122 | - this.kernel.send(portRef1, m), | |
123 | - this.kernel.ports.bind('child', portRef1) | |
124 | - ]) | |
125 | - } | |
126 | - } | |
127 | - | |
128 | - const hypervisor = new Hypervisor(node.dag) | |
129 | - hypervisor.registerContainer(testVMContainer) | |
130 | - hypervisor.registerContainer(testVMContainer2) | |
131 | - | |
132 | - const root = await hypervisor.createInstance(testVMContainer.typeId) | |
133 | - const [portRef1, portRef2] = root.ports.createChannel() | |
134 | - await root.createInstance(testVMContainer.typeId, root.createMessage({ | |
135 | - ports: [portRef2] | |
136 | - })) | |
137 | - | |
138 | - await root.ports.bind('first', portRef1) | |
139 | - message = root.createMessage({ | |
140 | - data: 'test' | |
141 | - }) | |
142 | - | |
143 | - await root.send(portRef1, message) | |
144 | - const stateRoot = await hypervisor.createStateRoot(Infinity) | |
145 | - | |
146 | - t.deepEquals(stateRoot, expectedState, 'expected state') | |
147 | - // await hypervisor.graph.tree(stateRoot, Infinity, true) | |
148 | - // console.log(JSON.stringify(stateRoot, null, 2)) | |
149 | - }) | |
150 | - | |
151 | 97 … | tape('one child contract', async t => { |
152 | 98 … | t.plan(4) |
153 | 99 … | let message |
154 | 100 … | const expectedState = { |
@@ -267,17 +213,16 @@ | ||
267 | 213 … | '/': 'zdpuAoifKuJkWz9Fjvt79NmGq3tcefhfCyq8iM8YhcFdV9bmZ' |
268 | 214 … | }, 'should revert the state') |
269 | 215 … | }) |
270 | 216 … | |
271 | - tape('message should arrive in the correct oder if sent in order', async t => { | |
217 … | + tape('recieving older messages', async t => { | |
272 | 218 … | t.plan(2) |
273 | 219 … | let runs = 0 |
274 | 220 … | |
275 | 221 … | class Root extends BaseContainer { |
276 | 222 … | async onMessage (m) { |
277 | 223 … | if (!runs) { |
278 | 224 … | runs++ |
279 | - | |
280 | 225 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
281 | 226 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
282 | 227 … | |
283 | 228 … | const message1 = this.kernel.createMessage({ |
@@ -286,233 +231,81 @@ | ||
286 | 231 … | const message2 = this.kernel.createMessage({ |
287 | 232 … | ports: [portRef4] |
288 | 233 … | }) |
289 | 234 … | |
290 | - await this.kernel.createInstance(First.typeId, message1) | |
291 | - await this.kernel.createInstance(Second.typeId, message2) | |
292 | - | |
293 | - return Promise.all( | |
235 … | + await Promise.all([ | |
236 … | + this.kernel.createInstance(First.typeId, message1), | |
294 | 237 … | this.kernel.send(portRef1, this.kernel.createMessage()), |
295 | 238 … | this.kernel.send(portRef3, this.kernel.createMessage()), |
296 | - this.kernel.ports.bind('two', portRef3), | |
297 | - this.kernel.ports.bind('one', portRef1) | |
298 | - ) | |
239 … | + this.kernel.ports.bind('one', portRef1), | |
240 … | + this.kernel.ports.bind('two', portRef3) | |
241 … | + ]) | |
242 … | + return this.kernel.createInstance(Waiter.typeId, message2) | |
299 | 243 … | } else if (runs === 1) { |
300 | 244 … | runs++ |
301 | 245 … | t.equals(m.data, 'first', 'should recive the first message') |
302 | 246 … | } else if (runs === 2) { |
303 | - t.equals(m.data, 'second', 'should recived the second message') | |
304 | - } | |
305 | - } | |
306 | - } | |
307 | - | |
308 | - class First extends BaseContainer { | |
309 | - onMessage (m) { | |
310 | - this.kernel.incrementTicks(2) | |
311 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
312 | - data: 'first' | |
313 | - })) | |
314 | - } | |
315 | - | |
316 | - static get typeId () { | |
317 | - return 99 | |
318 | - } | |
319 | - } | |
320 | - | |
321 | - class Second extends BaseContainer { | |
322 | - onMessage (m) { | |
323 | - this.kernel.incrementTicks(3) | |
324 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
325 | - data: 'second' | |
326 | - })) | |
327 | - } | |
328 | - | |
329 | - static get typeId () { | |
330 | - return 299 | |
331 | - } | |
332 | - } | |
333 | - | |
334 | - const hypervisor = new Hypervisor(node.dag) | |
335 | - | |
336 | - hypervisor.registerContainer(Root) | |
337 | - hypervisor.registerContainer(First) | |
338 | - hypervisor.registerContainer(Second) | |
339 | - | |
340 | - const root = await hypervisor.createInstance(Root.typeId) | |
341 | - | |
342 | - const [portRef1, portRef2] = root.ports.createChannel() | |
343 | - await root.createInstance(Root.typeId, root.createMessage({ | |
344 | - ports: [portRef2] | |
345 | - })) | |
346 | - | |
347 | - await root.ports.bind('first', portRef1) | |
348 | - const message = root.createMessage() | |
349 | - root.send(portRef1, message) | |
350 | - }) | |
351 | - | |
352 | - tape('message should arrive in the correct oder if sent in order', async t => { | |
353 | - t.plan(2) | |
354 | - let runs = 0 | |
355 | - | |
356 | - class Root extends BaseContainer { | |
357 | - async onMessage (m) { | |
358 | - if (!runs) { | |
359 | 247 … | runs++ |
360 | - | |
361 | - const [portRef1, portRef2] = this.kernel.ports.createChannel() | |
362 | - const [portRef3, portRef4] = this.kernel.ports.createChannel() | |
363 | - | |
364 | - const message1 = this.kernel.createMessage({ | |
365 | - ports: [portRef2] | |
366 | - }) | |
367 | - const message2 = this.kernel.createMessage({ | |
368 | - ports: [portRef4] | |
369 | - }) | |
370 | - | |
371 | - await this.kernel.createInstance(First.typeId, message1) | |
372 | - await this.kernel.createInstance(Second.typeId, message2) | |
373 | - | |
374 | - this.kernel.send(portRef1, this.kernel.createMessage()) | |
375 | - this.kernel.send(portRef3, this.kernel.createMessage()) | |
376 | - | |
377 | - return Promise.all([ | |
378 | - this.kernel.ports.bind('one', portRef1), | |
379 | - this.kernel.ports.bind('two', portRef3) | |
380 | - ]) | |
381 | - } else if (runs === 1) { | |
248 … | + t.equals(m.data, 'second', 'should recive the second message') | |
249 … | + } else if (runs === 3) { | |
382 | 250 … | runs++ |
383 | - t.equals(m.data, 'second', 'should recived the second message') | |
384 | - } else if (runs === 2) { | |
385 | - t.equals(m.data, 'first', 'should recive the first message') | |
251 … | + // t.equals(m.data, 'third', 'should recived the second message') | |
386 | 252 … | } |
387 | 253 … | } |
388 | - | |
389 | 254 … | static get typeId () { |
390 | - return 99 | |
255 … | + return 299 | |
391 | 256 … | } |
392 | 257 … | } |
393 | 258 … | |
394 | 259 … | class First extends BaseContainer { |
395 | 260 … | onMessage (m) { |
396 | 261 … | this.kernel.incrementTicks(2) |
397 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
398 | - data: 'first' | |
262 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
263 … | + data: 'second' | |
399 | 264 … | })) |
400 | 265 … | } |
401 | - | |
402 | 266 … | static get typeId () { |
403 | - return 299 | |
267 … | + return 29 | |
404 | 268 … | } |
405 | 269 … | } |
406 | 270 … | |
407 | - class Second extends BaseContainer { | |
271 … | + class Waiter extends BaseContainer { | |
408 | 272 … | onMessage (m) { |
409 | - this.kernel.incrementTicks(1) | |
410 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
411 | - data: 'second' | |
412 | - })) | |
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 … | + }) | |
413 | 280 … | } |
414 | 281 … | } |
415 | 282 … | |
416 | - const hypervisor = new Hypervisor(node.dag) | |
283 … | + try { | |
284 … | + const hypervisor = new Hypervisor(node.dag) | |
417 | 285 … | |
418 | - hypervisor.registerContainer(Root) | |
419 | - hypervisor.registerContainer(First) | |
420 | - hypervisor.registerContainer(Second) | |
286 … | + hypervisor.registerContainer(Root) | |
287 … | + hypervisor.registerContainer(First) | |
288 … | + hypervisor.registerContainer(Waiter) | |
421 | 289 … | |
422 | - const root = await hypervisor.createInstance(Root.typeId) | |
290 … | + const root = await hypervisor.createInstance(Root.typeId) | |
291 … | + const [portRef1, portRef2] = root.ports.createChannel() | |
423 | 292 … | |
424 | - const [portRef1, portRef2] = root.ports.createChannel() | |
425 | - await root.createInstance(Root.typeId, root.createMessage({ | |
426 | - ports: [portRef2] | |
427 | - })) | |
428 | - | |
429 | - await root.ports.bind('first', portRef1) | |
430 | - const message = root.createMessage() | |
431 | - root.send(portRef1, message) | |
432 | - }) | |
433 | - | |
434 | - tape('message should arrive in the correct oder if sent in order', async t => { | |
435 | - t.plan(2) | |
436 | - let runs = 0 | |
437 | - | |
438 | - class Root extends BaseContainer { | |
439 | - onMessage (m) { | |
440 | - if (!runs) { | |
441 | - runs++ | |
442 | - const [portRef1, portRef2] = this.kernel.ports.createChannel() | |
443 | - const [portRef3, portRef4] = this.kernel.ports.createChannel() | |
444 | - | |
445 | - const message1 = this.kernel.createMessage({ | |
446 | - ports: [portRef2] | |
447 | - }) | |
448 | - const message2 = this.kernel.createMessage({ | |
449 | - ports: [portRef4] | |
450 | - }) | |
451 | - | |
452 | - this.kernel.send(portRef1, this.kernel.createMessage()) | |
453 | - this.kernel.send(portRef3, this.kernel.createMessage()) | |
454 | - | |
455 | - this.kernel.incrementTicks(6) | |
456 | - | |
457 | - return Promise.all([ | |
458 | - this.kernel.createInstance(First.typeId, message1), | |
459 | - this.kernel.createInstance(Second.typeId, message2), | |
460 | - this.kernel.ports.bind('one', portRef1), | |
461 | - this.kernel.ports.bind('two', portRef3) | |
462 | - ]) | |
463 | - } else if (runs === 1) { | |
464 | - runs++ | |
465 | - t.equals(m.data, 'first', 'should recive the first message') | |
466 | - } else if (runs === 2) { | |
467 | - t.equals(m.data, 'second', 'should recived the second message') | |
468 | - } | |
469 | - } | |
470 | - static get typeId () { | |
471 | - return 299 | |
472 | - } | |
473 | - } | |
474 | - | |
475 | - class First extends BaseContainer { | |
476 | - onMessage (m) { | |
477 | - this.kernel.incrementTicks(1) | |
478 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
479 | - 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] | |
480 | 299 … | })) |
481 | - } | |
482 | - static get typeId () { | |
483 | - return 2 | |
484 | - } | |
300 … | + ]) | |
301 … | + } catch (e) { | |
302 … | + console.log(e) | |
485 | 303 … | } |
486 | - | |
487 | - class Second extends BaseContainer { | |
488 | - onMessage (m) { | |
489 | - this.kernel.incrementTicks(2) | |
490 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
491 | - data: 'second' | |
492 | - })) | |
493 | - } | |
494 | - } | |
495 | - | |
496 | - const hypervisor = new Hypervisor(node.dag) | |
497 | - | |
498 | - hypervisor.registerContainer(Root) | |
499 | - hypervisor.registerContainer(First) | |
500 | - hypervisor.registerContainer(Second) | |
501 | - | |
502 | - const root = await hypervisor.createInstance(Root.typeId) | |
503 | - const [portRef1, portRef2] = root.ports.createChannel() | |
504 | - await root.createInstance(Root.typeId, root.createMessage({ | |
505 | - ports: [portRef2] | |
506 | - })) | |
507 | - | |
508 | - await root.ports.bind('first', portRef1) | |
509 | - const message = root.createMessage() | |
510 | - root.send(portRef1, message) | |
511 | 304 … | }) |
512 | 305 … | |
513 | 306 … | tape('saturation', async t => { |
514 | - t.plan(2) | |
307 … | + t.plan(3) | |
515 | 308 … | let runs = 0 |
516 | 309 … | |
517 | 310 … | class Root extends BaseContainer { |
518 | 311 … | async onMessage (m) { |
@@ -527,25 +320,26 @@ | ||
527 | 320 … | const message2 = this.kernel.createMessage({ |
528 | 321 … | ports: [portRef4] |
529 | 322 … | }) |
530 | 323 … | |
531 | - await this.kernel.createInstance(First.typeId, message1) | |
532 | - await this.kernel.createInstance(Second.typeId, message2) | |
533 | - | |
534 | - this.kernel.send(portRef1, this.kernel.createMessage()) | |
535 | - this.kernel.send(portRef3, this.kernel.createMessage()) | |
536 | - | |
537 | 324 … | this.kernel.incrementTicks(6) |
538 | 325 … | return Promise.all([ |
326 … | + this.kernel.createInstance(First.typeId, message1), | |
327 … | + this.kernel.createInstance(Second.typeId, message2), | |
328 … | + this.kernel.send(portRef1, this.kernel.createMessage()), | |
329 … | + this.kernel.send(portRef3, this.kernel.createMessage()), | |
539 | 330 … | this.kernel.ports.bind('one', portRef1), |
540 | 331 … | this.kernel.ports.bind('two', portRef3) |
541 | 332 … | ]) |
542 | 333 … | } else if (runs === 1) { |
543 | 334 … | runs++ |
544 | 335 … | t.equals(m.data, 'first', 'should recive the first message') |
545 | 336 … | } else if (runs === 2) { |
546 | 337 … | runs++ |
547 | - t.equals(m.data, 'second', 'should recived the second message') | |
338 … | + t.equals(m.data, 'second', 'should recive the first message') | |
339 … | + } else if (runs === 3) { | |
340 … | + runs++ | |
341 … | + t.equals(m.data, 'third', 'should recived the second message') | |
548 | 342 … | } |
549 | 343 … | } |
550 | 344 … | static get typeId () { |
551 | 345 … | return 299 |
@@ -554,10 +348,10 @@ | ||
554 | 348 … | |
555 | 349 … | class First extends BaseContainer { |
556 | 350 … | onMessage (m) { |
557 | 351 … | this.kernel.incrementTicks(2) |
558 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
559 | - data: 'first' | |
352 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
353 … | + data: 'second' | |
560 | 354 … | })) |
561 | 355 … | } |
562 | 356 … | static get typeId () { |
563 | 357 … | return 29 |
@@ -566,22 +360,24 @@ | ||
566 | 360 … | |
567 | 361 … | class Second extends BaseContainer { |
568 | 362 … | onMessage (m) { |
569 | 363 … | this.kernel.incrementTicks(3) |
570 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
571 | - data: 'second' | |
364 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
365 … | + data: 'third' | |
572 | 366 … | })) |
573 | 367 … | } |
574 | 368 … | static get typeId () { |
575 | 369 … | return 2 |
576 | 370 … | } |
577 | 371 … | } |
578 | 372 … | |
579 | 373 … | class Waiter extends BaseContainer { |
580 | - onCreation () { | |
374 … | + onCreation (m) { | |
581 | 375 … | return new Promise((resolve, reject) => { |
582 | 376 … | setTimeout(() => { |
583 | - resolve() | |
377 … | + this.kernel.send(m.ports[0], this.kernel.createMessage({ | |
378 … | + data: 'first' | |
379 … | + })).then(resolve) | |
584 | 380 … | }, 200) |
585 | 381 … | }) |
586 | 382 … | } |
587 | 383 … | } |
@@ -595,192 +391,31 @@ | ||
595 | 391 … | hypervisor.registerContainer(Waiter) |
596 | 392 … | |
597 | 393 … | const root = await hypervisor.createInstance(Root.typeId) |
598 | 394 … | const [portRef1, portRef2] = root.ports.createChannel() |
395 … | + const [portRef3, portRef4] = root.ports.createChannel() | |
599 | 396 … | |
600 | 397 … | const message = root.createMessage() |
601 | - root.send(portRef1, message) | |
602 | - await root.ports.bind('first', portRef1) | |
603 | - await root.createInstance(Root.typeId, root.createMessage({ | |
604 | - ports: [portRef2] | |
605 | - })) | |
398 … | + await Promise.all([ | |
399 … | + root.send(portRef1, message), | |
400 … | + root.ports.bind('first', portRef1), | |
401 … | + root.createInstance(Root.typeId, root.createMessage({ | |
402 … | + ports: [portRef2] | |
403 … | + })), | |
404 … | + root.ports.bind('sencond', portRef3), | |
405 … | + root.createInstance(Waiter.typeId, root.createMessage({ | |
406 … | + ports: [portRef4] | |
407 … | + })) | |
408 … | + ]) | |
606 | 409 … | |
607 | - const [portRef3, portRef4] = root.ports.createChannel() | |
608 | - await root.ports.bind('sencond', portRef3) | |
609 | - await root.createInstance(Waiter.typeId, root.createMessage({ | |
610 | - ports: [portRef4] | |
611 | - })) | |
612 | - | |
613 | 410 … | root.incrementTicks(100) |
614 | - root.send(portRef1, root.createMessage({data: 'testss'})) | |
615 | - // hypervisor.scheduler.done(root.id) | |
411 … | + await root.send(portRef1, root.createMessage({data: 'testss'})) | |
412 … | + hypervisor.scheduler.done(root.id) | |
616 | 413 … | } catch (e) { |
617 | 414 … | console.log(e) |
618 | 415 … | } |
619 | 416 … | }) |
620 | 417 … | |
621 | - tape('message should arrive in the correct order, even in a tie of ticks', async t => { | |
622 | - t.plan(2) | |
623 | - | |
624 | - let runs = 0 | |
625 | - | |
626 | - class Root extends BaseContainer { | |
627 | - async onMessage (m) { | |
628 | - if (!runs) { | |
629 | - runs++ | |
630 | - const [portRef1, portRef2] = this.kernel.ports.createChannel() | |
631 | - const [portRef3, portRef4] = this.kernel.ports.createChannel() | |
632 | - | |
633 | - const message1 = this.kernel.createMessage({ | |
634 | - ports: [portRef2] | |
635 | - }) | |
636 | - const message2 = this.kernel.createMessage({ | |
637 | - ports: [portRef4] | |
638 | - }) | |
639 | - | |
640 | - await this.kernel.createInstance(First.typeId, message1) | |
641 | - await this.kernel.createInstance(Second.typeId, message2) | |
642 | - | |
643 | - this.kernel.send(portRef1, this.kernel.createMessage()) | |
644 | - this.kernel.send(portRef3, this.kernel.createMessage()) | |
645 | - | |
646 | - this.kernel.incrementTicks(6) | |
647 | - return Promise.all([ | |
648 | - this.kernel.ports.bind('two', portRef3), | |
649 | - this.kernel.ports.bind('one', portRef1) | |
650 | - ]) | |
651 | - } else if (runs === 1) { | |
652 | - runs++ | |
653 | - t.equals(m.data, 'second', 'should recived the second message') | |
654 | - } else if (runs === 2) { | |
655 | - t.equals(m.data, 'first', 'should recive the first message') | |
656 | - } | |
657 | - } | |
658 | - static get typeId () { | |
659 | - return 299 | |
660 | - } | |
661 | - } | |
662 | - | |
663 | - class First extends BaseContainer { | |
664 | - onMessage (m) { | |
665 | - this.kernel.incrementTicks(2) | |
666 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
667 | - data: 'first' | |
668 | - })) | |
669 | - } | |
670 | - static get typeId () { | |
671 | - return 29 | |
672 | - } | |
673 | - } | |
674 | - | |
675 | - class Second extends BaseContainer { | |
676 | - onMessage (m) { | |
677 | - this.kernel.incrementTicks(2) | |
678 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
679 | - data: 'second' | |
680 | - })) | |
681 | - } | |
682 | - static get typeId () { | |
683 | - return 2 | |
684 | - } | |
685 | - } | |
686 | - | |
687 | - const hypervisor = new Hypervisor(node.dag) | |
688 | - | |
689 | - hypervisor.registerContainer(Root) | |
690 | - hypervisor.registerContainer(First) | |
691 | - hypervisor.registerContainer(Second) | |
692 | - | |
693 | - const root = await hypervisor.createInstance(Root.typeId) | |
694 | - const [portRef1, portRef2] = root.ports.createChannel() | |
695 | - const message = root.createMessage() | |
696 | - | |
697 | - root.send(portRef1, message) | |
698 | - await root.ports.bind('first', portRef1) | |
699 | - await root.createInstance(Root.typeId, root.createMessage({ | |
700 | - ports: [portRef2] | |
701 | - })) | |
702 | - }) | |
703 | - | |
704 | - tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { | |
705 | - t.plan(2) | |
706 | - | |
707 | - let runs = 0 | |
708 | - | |
709 | - class Root extends BaseContainer { | |
710 | - async onMessage (m) { | |
711 | - if (!runs) { | |
712 | - runs++ | |
713 | - const [portRef1, portRef2] = this.kernel.ports.createChannel() | |
714 | - const [portRef3, portRef4] = this.kernel.ports.createChannel() | |
715 | - | |
716 | - await this.kernel.ports.bind('one', portRef1) | |
717 | - await this.kernel.ports.bind('two', portRef3) | |
718 | - | |
719 | - const message1 = this.kernel.createMessage({ | |
720 | - ports: [portRef2] | |
721 | - }) | |
722 | - const message2 = this.kernel.createMessage({ | |
723 | - ports: [portRef4] | |
724 | - }) | |
725 | - | |
726 | - await this.kernel.createInstance(First.typeId, message1) | |
727 | - await this.kernel.createInstance(Second.typeId, message2) | |
728 | - | |
729 | - this.kernel.send(portRef1, this.kernel.createMessage()) | |
730 | - this.kernel.send(portRef3, this.kernel.createMessage()) | |
731 | - | |
732 | - this.kernel.incrementTicks(6) | |
733 | - } else if (runs === 1) { | |
734 | - runs++ | |
735 | - t.equals(m.data, 'first', 'should recive the first message') | |
736 | - } else if (runs === 2) { | |
737 | - t.equals(m.data, 'second', 'should recived the second message') | |
738 | - } | |
739 | - } | |
740 | - static get typeId () { | |
741 | - return 299 | |
742 | - } | |
743 | - } | |
744 | - | |
745 | - class First extends BaseContainer { | |
746 | - onMessage (m) { | |
747 | - this.kernel.incrementTicks(2) | |
748 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
749 | - data: 'first' | |
750 | - })) | |
751 | - } | |
752 | - static get typeId () { | |
753 | - return 29 | |
754 | - } | |
755 | - } | |
756 | - | |
757 | - class Second extends BaseContainer { | |
758 | - onMessage (m) { | |
759 | - this.kernel.incrementTicks(2) | |
760 | - this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
761 | - data: 'second' | |
762 | - })) | |
763 | - } | |
764 | - } | |
765 | - | |
766 | - const hypervisor = new Hypervisor(node.dag) | |
767 | - | |
768 | - hypervisor.registerContainer(Root) | |
769 | - hypervisor.registerContainer(First) | |
770 | - hypervisor.registerContainer(Second) | |
771 | - | |
772 | - const root = await hypervisor.createInstance(Root.typeId) | |
773 | - const [portRef1, portRef2] = root.ports.createChannel() | |
774 | - const message = root.createMessage() | |
775 | - | |
776 | - root.send(portRef1, message) | |
777 | - await root.ports.bind('first', portRef1) | |
778 | - await root.createInstance(Root.typeId, root.createMessage({ | |
779 | - ports: [portRef2] | |
780 | - })) | |
781 | - }) | |
782 | - | |
783 | 418 … | tape('send to the same container at the same time', async t => { |
784 | 419 … | t.plan(2) |
785 | 420 … | |
786 | 421 … | let runs = 0 |
@@ -1083,29 +718,32 @@ | ||
1083 | 718 … | const expectedSr = { |
1084 | 719 … | '/': 'zdpuArkZ5yNowNnU4qJ8vayAUncgibQP9goDP1CwFxdmPJF9D' |
1085 | 720 … | } |
1086 | 721 … | class Root extends BaseContainer { |
1087 | - async onMessage (m) { | |
722 … | + onMessage (m) { | |
1088 | 723 … | if (m.ports.length) { |
1089 | 724 … | const port = this.kernel.ports.get('test1') |
1090 | - await this.kernel.ports.unbind('test1') | |
1091 | - await this.kernel.ports.unbind('test2') | |
1092 | - await this.kernel.send(port, m) | |
725 … | + return Promise.all([ | |
726 … | + this.kernel.send(port, m), | |
727 … | + this.kernel.ports.unbind('test1'), | |
728 … | + this.kernel.ports.unbind('test2') | |
729 … | + ]) | |
1093 | 730 … | } else { |
1094 | 731 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1095 | - await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ | |
1096 | - ports: [portRef2] | |
1097 | - })) | |
1098 | - await this.kernel.ports.bind('test1', portRef1) | |
1099 | - | |
1100 | 732 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1101 | - await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ | |
1102 | - ports: [portRef4] | |
1103 | - })) | |
1104 | - await this.kernel.ports.bind('test2', portRef3) | |
1105 | - await this.kernel.send(portRef3, this.kernel.createMessage({ | |
1106 | - data: 'getChannel' | |
1107 | - })) | |
733 … | + return Promise.all([ | |
734 … | + this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ | |
735 … | + ports: [portRef2] | |
736 … | + })), | |
737 … | + this.kernel.ports.bind('test1', portRef1), | |
738 … | + this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ | |
739 … | + ports: [portRef4] | |
740 … | + })), | |
741 … | + this.kernel.ports.bind('test2', portRef3), | |
742 … | + this.kernel.send(portRef3, this.kernel.createMessage({ | |
743 … | + data: 'getChannel' | |
744 … | + })) | |
745 … | + ]) | |
1108 | 746 … | } |
1109 | 747 … | } |
1110 | 748 … | } |
1111 | 749 … |
Built with git-ssb-web