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) |
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) |
110 | 110 … | } |
111 | 111 … | } |
112 | 112 … | |
113 | 113 … | class testVMContainer extends BaseContainer { |
114 | | - onMessage (m) { |
| 114 … | + async onMessage (m) { |
115 | 115 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
116 | | - this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
| 116 … | + await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
117 | 117 … | ports: [portRef2] |
118 | 118 … | })) |
119 | 119 … | this.kernel.incrementTicks(2) |
120 | 120 … | this.kernel.send(portRef1, m) |
127 | 127 … | hypervisor.registerContainer(testVMContainer2) |
128 | 128 … | |
129 | 129 … | const root = await hypervisor.createInstance(testVMContainer.typeId) |
130 | 130 … | const [portRef1, portRef2] = root.ports.createChannel() |
131 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
| 131 … | + await root.createInstance(testVMContainer.typeId, root.createMessage({ |
132 | 132 … | ports: [portRef2] |
133 | 133 … | })) |
134 | 134 … | |
135 | 135 … | await root.ports.bind('first', portRef1) |
170 | 170 … | } |
171 | 171 … | } |
172 | 172 … | |
173 | 173 … | class testVMContainer extends BaseContainer { |
174 | | - onMessage (m) { |
| 174 … | + async onMessage (m) { |
175 | 175 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
176 | | - this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
| 176 … | + await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
177 | 177 … | ports: [portRef2] |
178 | 178 … | })) |
179 | 179 … | this.kernel.send(portRef1, m) |
180 | 180 … | this.kernel.incrementTicks(1) |
188 | 188 … | |
189 | 189 … | let root = await hypervisor.createInstance(testVMContainer.typeId) |
190 | 190 … | const rootId = root.id |
191 | 191 … | const [portRef1, portRef2] = root.ports.createChannel() |
192 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
| 192 … | + await root.createInstance(testVMContainer.typeId, root.createMessage({ |
193 | 193 … | ports: [portRef2] |
194 | 194 … | })) |
195 | 195 … | |
196 | 196 … | await root.ports.bind('first', portRef1) |
242 | 242 … | const message3 = this.kernel.createMessage({ |
243 | 243 … | ports: [portRef6] |
244 | 244 … | }) |
245 | 245 … | |
246 | | - this.kernel.createInstance(Root.typeId, message1) |
247 | | - this.kernel.createInstance(Root.typeId, message2) |
248 | | - this.kernel.createInstance(Root.typeId, message3) |
| 246 … | + await Promise.all([ |
| 247 … | + this.kernel.createInstance(Root.typeId, message1), |
| 248 … | + this.kernel.createInstance(Root.typeId, message2), |
| 249 … | + this.kernel.createInstance(Root.typeId, message3) |
| 250 … | + ]) |
249 | 251 … | |
250 | 252 … | throw new Error('it is a trap!!!') |
251 | 253 … | } |
252 | 254 … | } |
267 | 269 … | t.plan(2) |
268 | 270 … | let runs = 0 |
269 | 271 … | |
270 | 272 … | class Root extends BaseContainer { |
271 | | - onMessage (m) { |
| 273 … | + async onMessage (m) { |
272 | 274 … | if (!runs) { |
273 | 275 … | runs++ |
274 | 276 … | |
275 | 277 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
281 | 283 … | const message2 = this.kernel.createMessage({ |
282 | 284 … | ports: [portRef4] |
283 | 285 … | }) |
284 | 286 … | |
285 | | - this.kernel.createInstance(First.typeId, message1) |
286 | | - this.kernel.createInstance(Second.typeId, message2) |
| 287 … | + await this.kernel.createInstance(First.typeId, message1) |
| 288 … | + await this.kernel.createInstance(Second.typeId, message2) |
287 | 289 … | |
288 | 290 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
289 | 291 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
290 | 292 … | return Promise.all( |
334 | 336 … | |
335 | 337 … | const root = await hypervisor.createInstance(Root.typeId) |
336 | 338 … | |
337 | 339 … | const [portRef1, portRef2] = root.ports.createChannel() |
338 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 340 … | + await root.createInstance(Root.typeId, root.createMessage({ |
339 | 341 … | ports: [portRef2] |
340 | 342 … | })) |
341 | 343 … | |
342 | 344 … | await root.ports.bind('first', portRef1) |
348 | 350 … | t.plan(2) |
349 | 351 … | let runs = 0 |
350 | 352 … | |
351 | 353 … | class Root extends BaseContainer { |
352 | | - onMessage (m) { |
| 354 … | + async onMessage (m) { |
353 | 355 … | if (!runs) { |
354 | 356 … | runs++ |
355 | 357 … | |
356 | 358 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
362 | 364 … | const message2 = this.kernel.createMessage({ |
363 | 365 … | ports: [portRef4] |
364 | 366 … | }) |
365 | 367 … | |
366 | | - this.kernel.createInstance(First.typeId, message1) |
367 | | - this.kernel.createInstance(Second.typeId, message2) |
| 368 … | + await this.kernel.createInstance(First.typeId, message1) |
| 369 … | + await this.kernel.createInstance(Second.typeId, message2) |
368 | 370 … | |
369 | 371 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
370 | 372 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
371 | 373 … | |
416 | 418 … | |
417 | 419 … | const root = await hypervisor.createInstance(Root.typeId) |
418 | 420 … | |
419 | 421 … | const [portRef1, portRef2] = root.ports.createChannel() |
420 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 422 … | + await root.createInstance(Root.typeId, root.createMessage({ |
421 | 423 … | ports: [portRef2] |
422 | 424 … | })) |
423 | 425 … | |
424 | 426 … | await root.ports.bind('first', portRef1) |
443 | 445 … | const message2 = this.kernel.createMessage({ |
444 | 446 … | ports: [portRef4] |
445 | 447 … | }) |
446 | 448 … | |
447 | | - this.kernel.createInstance(First.typeId, message1) |
448 | | - this.kernel.createInstance(Second.typeId, message2) |
449 | | - |
450 | 449 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
451 | 450 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
452 | 451 … | |
453 | 452 … | this.kernel.incrementTicks(6) |
454 | 453 … | |
455 | 454 … | return Promise.all([ |
| 455 … | + this.kernel.createInstance(First.typeId, message1), |
| 456 … | + this.kernel.createInstance(Second.typeId, message2), |
456 | 457 … | this.kernel.ports.bind('one', portRef1), |
457 | 458 … | this.kernel.ports.bind('two', portRef3) |
458 | 459 … | ]) |
459 | 460 … | } else if (runs === 1) { |
496 | 497 … | hypervisor.registerContainer(Second) |
497 | 498 … | |
498 | 499 … | const root = await hypervisor.createInstance(Root.typeId) |
499 | 500 … | const [portRef1, portRef2] = root.ports.createChannel() |
500 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 501 … | + await root.createInstance(Root.typeId, root.createMessage({ |
501 | 502 … | ports: [portRef2] |
502 | 503 … | })) |
503 | 504 … | |
504 | 505 … | await root.ports.bind('first', portRef1) |
510 | 511 … | t.plan(2) |
511 | 512 … | let runs = 0 |
512 | 513 … | |
513 | 514 … | class Root extends BaseContainer { |
514 | | - onMessage (m) { |
| 515 … | + async onMessage (m) { |
515 | 516 … | if (!runs) { |
516 | 517 … | runs++ |
517 | 518 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
518 | 519 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
523 | 524 … | const message2 = this.kernel.createMessage({ |
524 | 525 … | ports: [portRef4] |
525 | 526 … | }) |
526 | 527 … | |
527 | | - this.kernel.createInstance(First.typeId, message1) |
528 | | - this.kernel.createInstance(Second.typeId, message2) |
| 528 … | + await this.kernel.createInstance(First.typeId, message1) |
| 529 … | + await this.kernel.createInstance(Second.typeId, message2) |
529 | 530 … | |
530 | 531 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
531 | 532 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
532 | 533 … | |
581 | 582 … | }) |
582 | 583 … | } |
583 | 584 … | } |
584 | 585 … | |
585 | | - const hypervisor = new Hypervisor(node.dag) |
| 586 … | + try { |
| 587 … | + const hypervisor = new Hypervisor(node.dag) |
586 | 588 … | |
587 | | - hypervisor.registerContainer(Root) |
588 | | - hypervisor.registerContainer(First) |
589 | | - hypervisor.registerContainer(Second) |
590 | | - hypervisor.registerContainer(Waiter) |
| 589 … | + hypervisor.registerContainer(Root) |
| 590 … | + hypervisor.registerContainer(First) |
| 591 … | + hypervisor.registerContainer(Second) |
| 592 … | + hypervisor.registerContainer(Waiter) |
591 | 593 … | |
592 | | - const root = await hypervisor.createInstance(Root.typeId) |
593 | | - const [portRef1, portRef2] = root.ports.createChannel() |
| 594 … | + const root = await hypervisor.createInstance(Root.typeId) |
| 595 … | + const [portRef1, portRef2] = root.ports.createChannel() |
594 | 596 … | |
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 | | - })) |
| 597 … | + const message = root.createMessage() |
| 598 … | + root.send(portRef1, message) |
| 599 … | + await root.ports.bind('first', portRef1) |
| 600 … | + await root.createInstance(Root.typeId, root.createMessage({ |
| 601 … | + ports: [portRef2] |
| 602 … | + })) |
601 | 603 … | |
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 | | - })) |
| 604 … | + const [portRef3, portRef4] = root.ports.createChannel() |
| 605 … | + await root.ports.bind('sencond', portRef3) |
| 606 … | + await root.createInstance(Waiter.typeId, root.createMessage({ |
| 607 … | + ports: [portRef4] |
| 608 … | + })) |
607 | 609 … | |
608 | | - root.incrementTicks(100) |
609 | | - root.send(portRef1, root.createMessage({data: 'testss'})) |
610 | | - hypervisor.scheduler.done(root.id) |
| 610 … | + root.incrementTicks(100) |
| 611 … | + root.send(portRef1, root.createMessage({data: 'testss'})) |
| 612 … | + |
| 613 … | + } catch (e) { |
| 614 … | + console.log(e) |
| 615 … | + } |
611 | 616 … | }) |
612 | 617 … | |
613 | 618 … | tape('message should arrive in the correct order, even in a tie of ticks', async t => { |
614 | 619 … | t.plan(2) |
615 | 620 … | |
616 | 621 … | let runs = 0 |
617 | 622 … | |
618 | 623 … | class Root extends BaseContainer { |
619 | | - onMessage (m) { |
| 624 … | + async onMessage (m) { |
620 | 625 … | if (!runs) { |
621 | 626 … | runs++ |
622 | 627 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
623 | 628 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
628 | 633 … | const message2 = this.kernel.createMessage({ |
629 | 634 … | ports: [portRef4] |
630 | 635 … | }) |
631 | 636 … | |
632 | | - this.kernel.createInstance(First.typeId, message1) |
633 | | - this.kernel.createInstance(Second.typeId, message2) |
| 637 … | + await this.kernel.createInstance(First.typeId, message1) |
| 638 … | + await this.kernel.createInstance(Second.typeId, message2) |
634 | 639 … | |
635 | 640 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
636 | 641 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
637 | 642 … | |
687 | 692 … | const message = root.createMessage() |
688 | 693 … | |
689 | 694 … | root.send(portRef1, message) |
690 | 695 … | await root.ports.bind('first', portRef1) |
691 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 696 … | + await root.createInstance(Root.typeId, root.createMessage({ |
692 | 697 … | ports: [portRef2] |
693 | 698 … | })) |
694 | 699 … | }) |
695 | 700 … | |
714 | 719 … | const message2 = this.kernel.createMessage({ |
715 | 720 … | ports: [portRef4] |
716 | 721 … | }) |
717 | 722 … | |
718 | | - this.kernel.createInstance(First.typeId, message1) |
719 | | - this.kernel.createInstance(Second.typeId, message2) |
| 723 … | + await this.kernel.createInstance(First.typeId, message1) |
| 724 … | + await this.kernel.createInstance(Second.typeId, message2) |
720 | 725 … | |
721 | 726 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
722 | 727 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
723 | 728 … | |
766 | 771 … | const message = root.createMessage() |
767 | 772 … | |
768 | 773 … | root.send(portRef1, message) |
769 | 774 … | await root.ports.bind('first', portRef1) |
770 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 775 … | + await root.createInstance(Root.typeId, root.createMessage({ |
771 | 776 … | ports: [portRef2] |
772 | 777 … | })) |
773 | 778 … | }) |
774 | 779 … | |
778 | 783 … | let runs = 0 |
779 | 784 … | let instance |
780 | 785 … | |
781 | 786 … | class Root extends BaseContainer { |
782 | | - onMessage (m) { |
| 787 … | + async onMessage (m) { |
783 | 788 … | let one = this.kernel.ports.get('one') |
784 | 789 … | if (!one) { |
785 | 790 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
786 | 791 … | const message1 = this.kernel.createMessage({ |
787 | 792 … | ports: [portRef2] |
788 | 793 … | }) |
789 | | - this.kernel.createInstance(First.typeId, message1) |
| 794 … | + await this.kernel.createInstance(First.typeId, message1) |
790 | 795 … | return this.kernel.ports.bind('one', portRef1) |
791 | 796 … | } else { |
792 | 797 … | this.kernel.send(one, this.kernel.createMessage()) |
793 | 798 … | this.kernel.send(one, this.kernel.createMessage()) |
808 | 813 … | } |
809 | 814 … | } |
810 | 815 … | } |
811 | 816 … | |
812 | | - const hypervisor = new Hypervisor(node.dag) |
| 817 … | + try { |
| 818 … | + const hypervisor = new Hypervisor(node.dag) |
813 | 819 … | |
814 | | - hypervisor.registerContainer(Root) |
815 | | - hypervisor.registerContainer(First) |
| 820 … | + hypervisor.registerContainer(Root) |
| 821 … | + hypervisor.registerContainer(First) |
816 | 822 … | |
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 | | - })) |
| 823 … | + const root = await hypervisor.createInstance(Root.typeId) |
| 824 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 825 … | + await root.ports.bind('first', portRef1) |
| 826 … | + await root.createInstance(Root.typeId, root.createMessage({ |
| 827 … | + ports: [portRef2] |
| 828 … | + })) |
823 | 829 … | |
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) |
| 830 … | + const message = root.createMessage() |
| 831 … | + root.send(portRef1, message) |
| 832 … | + await hypervisor.createStateRoot() |
| 833 … | + root.send(portRef1, root.createMessage()) |
| 834 … | + await hypervisor.createStateRoot() |
| 835 … | + t.equals(runs, 2) |
| 836 … | + } catch (e) { |
| 837 … | + console.log(e) |
| 838 … | + } |
830 | 839 … | }) |
831 | 840 … | |
832 | 841 … | tape('checking ports', async t => { |
833 | 842 … | t.plan(4) |
874 | 883 … | const expectedSr = { |
875 | 884 … | '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
876 | 885 … | } |
877 | 886 … | class Root extends BaseContainer { |
878 | | - onMessage (m) { |
| 887 … | + async onMessage (m) { |
879 | 888 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
880 | 889 … | const message1 = this.kernel.createMessage({ |
881 | 890 … | ports: [portRef2] |
882 | 891 … | }) |
883 | 892 … | |
884 | | - this.kernel.createInstance(First.typeId, message1) |
| 893 … | + await this.kernel.createInstance(First.typeId, message1) |
885 | 894 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
886 | 895 … | this.kernel.incrementTicks(6) |
887 | 896 … | return this.kernel.ports.bind('one', portRef1) |
888 | 897 … | } |
905 | 914 … | |
906 | 915 … | const root = await hypervisor.createInstance(Root.typeId) |
907 | 916 … | const [portRef1, portRef2] = root.ports.createChannel() |
908 | 917 … | await root.ports.bind('first', portRef1) |
909 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 918 … | + await root.createInstance(Root.typeId, root.createMessage({ |
910 | 919 … | ports: [portRef2] |
911 | 920 … | })) |
912 | 921 … | |
913 | 922 … | const message = root.createMessage() |
925 | 934 … | '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
926 | 935 … | } |
927 | 936 … | class Root extends BaseContainer { |
928 | 937 … | onMessage (m) { |
929 | | - this.kernel.createInstance(Root.typeId) |
| 938 … | + return this.kernel.createInstance(Root.typeId) |
930 | 939 … | } |
931 | 940 … | } |
932 | 941 … | |
933 | 942 … | const hypervisor = new Hypervisor(node.dag) |
934 | | - |
935 | 943 … | hypervisor.registerContainer(Root) |
936 | 944 … | |
937 | 945 … | const root = await hypervisor.createInstance(Root.typeId) |
938 | 946 … | const [portRef1, portRef2] = root.ports.createChannel() |
939 | 947 … | await root.ports.bind('first', portRef1) |
940 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 948 … | + await root.createInstance(Root.typeId, root.createMessage({ |
941 | 949 … | ports: [portRef2] |
942 | 950 … | })) |
943 | 951 … | |
944 | 952 … | const message = root.createMessage() |
955 | 963 … | } |
956 | 964 … | class Root extends BaseContainer { |
957 | 965 … | onMessage (m) { |
958 | 966 … | const [, portRef2] = this.kernel.ports.createChannel() |
959 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 967 … | + return this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
960 | 968 … | ports: [portRef2] |
961 | 969 … | })) |
962 | 970 … | } |
963 | 971 … | } |
966 | 974 … | async onInitailize (message) { |
967 | 975 … | await this.kernel.ports.bind('root', message.ports[0]) |
968 | 976 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
969 | 977 … | await this.kernel.ports.bind('child', portRef1) |
970 | | - this.kernel.createInstance(Root.typeId, this.kernel.createMessage({ |
| 978 … | + await this.kernel.createInstance(Root.typeId, this.kernel.createMessage({ |
971 | 979 … | ports: [portRef2] |
972 | 980 … | })) |
973 | 981 … | } |
974 | 982 … | static get typeId () { |
975 | 983 … | return 299 |
976 | 984 … | } |
977 | 985 … | } |
978 | 986 … | |
979 | | - const hypervisor = new Hypervisor(node.dag) |
| 987 … | + try { |
| 988 … | + const hypervisor = new Hypervisor(node.dag) |
980 | 989 … | |
981 | | - hypervisor.registerContainer(Root) |
982 | | - hypervisor.registerContainer(Sub) |
| 990 … | + hypervisor.registerContainer(Root) |
| 991 … | + hypervisor.registerContainer(Sub) |
983 | 992 … | |
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 | | - })) |
| 993 … | + const root = await hypervisor.createInstance(Root.typeId) |
| 994 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 995 … | + await root.ports.bind('first', portRef1) |
| 996 … | + await root.createInstance(Root.typeId, root.createMessage({ |
| 997 … | + ports: [portRef2] |
| 998 … | + })) |
990 | 999 … | |
991 | | - root.send(portRef1, root.createMessage()) |
992 | | - const sr = await hypervisor.createStateRoot() |
| 1000 … | + root.send(portRef1, root.createMessage()) |
| 1001 … | + const sr = await hypervisor.createStateRoot() |
993 | 1002 … | |
994 | | - t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
995 | | - t.end() |
| 1003 … | + t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
| 1004 … | + t.end() |
| 1005 … | + } catch (e) { |
| 1006 … | + console.log(e) |
| 1007 … | + } |
996 | 1008 … | }) |
997 | 1009 … | |
998 | 1010 … | tape('should not remove connected nodes', async t => { |
999 | 1011 … | const expectedSr = { |
1006 | 1018 … | this.kernel.send(port, m) |
1007 | 1019 … | return this.kernel.ports.unbind('test1') |
1008 | 1020 … | } else { |
1009 | 1021 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1010 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 1022 … | + await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1011 | 1023 … | ports: [portRef2] |
1012 | 1024 … | })) |
1013 | 1025 … | await this.kernel.ports.bind('test1', portRef1) |
1014 | 1026 … | |
1015 | 1027 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1016 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 1028 … | + await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1017 | 1029 … | ports: [portRef4] |
1018 | 1030 … | })) |
1019 | 1031 … | await this.kernel.ports.bind('test2', portRef3) |
1020 | 1032 … | this.kernel.send(portRef3, this.kernel.createMessage({ |
1049 | 1061 … | |
1050 | 1062 … | const root = await hypervisor.createInstance(Root.typeId) |
1051 | 1063 … | const [portRef1, portRef2] = root.ports.createChannel() |
1052 | 1064 … | await root.ports.bind('first', portRef1) |
1053 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 1065 … | + await root.createInstance(Root.typeId, root.createMessage({ |
1054 | 1066 … | ports: [portRef2] |
1055 | 1067 … | })) |
1056 | 1068 … | |
1057 | 1069 … | root.send(portRef1, root.createMessage()) |
1063 | 1075 … | }) |
1064 | 1076 … | |
1065 | 1077 … | tape('should remove multiple subgraphs', async t => { |
1066 | 1078 … | const expectedSr = { |
1067 | | - '/': 'zdpuAohccQTxM82d8N6Q82z234nQskeQoJGJu3eAVmxoQwWde' |
| 1079 … | + '/': 'zdpuArkZ5yNowNnU4qJ8vayAUncgibQP9goDP1CwFxdmPJF9D' |
1068 | 1080 … | } |
1069 | 1081 … | class Root extends BaseContainer { |
1070 | 1082 … | async onMessage (m) { |
1071 | 1083 … | if (m.ports.length) { |
1072 | 1084 … | const port = this.kernel.ports.get('test1') |
1073 | | - this.kernel.send(port, m) |
1074 | 1085 … | await this.kernel.ports.unbind('test1') |
1075 | 1086 … | await this.kernel.ports.unbind('test2') |
| 1087 … | + await this.kernel.send(port, m) |
1076 | 1088 … | } else { |
1077 | 1089 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1078 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 1090 … | + await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1079 | 1091 … | ports: [portRef2] |
1080 | 1092 … | })) |
1081 | 1093 … | await this.kernel.ports.bind('test1', portRef1) |
1082 | 1094 … | |
1083 | 1095 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1084 | | - this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
| 1096 … | + await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1085 | 1097 … | ports: [portRef4] |
1086 | 1098 … | })) |
1087 | 1099 … | await this.kernel.ports.bind('test2', portRef3) |
1088 | | - this.kernel.send(portRef3, this.kernel.createMessage({ |
| 1100 … | + await this.kernel.send(portRef3, this.kernel.createMessage({ |
1089 | 1101 … | data: 'getChannel' |
1090 | 1102 … | })) |
1091 | 1103 … | } |
1092 | 1104 … | } |
1093 | 1105 … | } |
1094 | 1106 … | |
1095 | 1107 … | class Sub extends BaseContainer { |
1096 | | - onMessage (message) { |
| 1108 … | + async onMessage (message) { |
1097 | 1109 … | if (message.data === 'getChannel') { |
1098 | 1110 … | const ports = this.kernel.ports.createChannel() |
1099 | | - this.kernel.send(message.fromPort, this.kernel.createMessage({ |
| 1111 … | + await this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1100 | 1112 … | data: 'bindPort', |
1101 | 1113 … | ports: [ports[1]] |
1102 | 1114 … | })) |
1103 | 1115 … | return this.kernel.ports.bind('channel', ports[0]) |
1109 | 1121 … | return 299 |
1110 | 1122 … | } |
1111 | 1123 … | } |
1112 | 1124 … | |
1113 | | - const hypervisor = new Hypervisor(node.dag) |
| 1125 … | + try { |
| 1126 … | + const hypervisor = new Hypervisor(node.dag) |
1114 | 1127 … | |
1115 | | - hypervisor.registerContainer(Root) |
1116 | | - hypervisor.registerContainer(Sub) |
| 1128 … | + hypervisor.registerContainer(Root) |
| 1129 … | + hypervisor.registerContainer(Sub) |
1117 | 1130 … | |
1118 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 1131 … | + const root = await hypervisor.createInstance(Root.typeId) |
1119 | 1132 … | |
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 | | - })) |
| 1133 … | + const [portRef1, portRef2] = root.ports.createChannel() |
| 1134 … | + await root.ports.bind('first', portRef1) |
| 1135 … | + await root.createInstance(Root.typeId, root.createMessage({ |
| 1136 … | + ports: [portRef2] |
| 1137 … | + })) |
1125 | 1138 … | |
1126 | | - root.send(portRef1, root.createMessage()) |
| 1139 … | + root.send(portRef1, root.createMessage()) |
1127 | 1140 … | |
1128 | | - const sr = await hypervisor.createStateRoot() |
1129 | | - t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
| 1141 … | + const sr = await hypervisor.createStateRoot() |
| 1142 … | + t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1130 | 1143 … | |
1131 | | - t.end() |
| 1144 … | + |
| 1145 … | + |
| 1146 … | + |
| 1147 … | + t.end() |
| 1148 … | + } catch (e) { |
| 1149 … | + console.log(e) |
| 1150 … | + } |
1132 | 1151 … | }) |
1133 | 1152 … | |
1134 | 1153 … | tape('response ports', async t => { |
1135 | 1154 … | t.plan(2) |