tests/index.jsView |
---|
27 | 27 | '/': 'zdpuB1wc9Pb6jUzfNt4nAxAEUxB7kNhg4vbq7YLcEyBUb6iAB' |
28 | 28 | } |
29 | 29 | |
30 | 30 | class testVMContainer extends BaseContainer { |
31 | | - run (m) { |
| 31 | + onMessage (m) { |
32 | 32 | t.true(m === message, 'should recive a message') |
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
87 | 87 | '/': 'zdpuAtVcH6MUnvt2RXnLsDXyLB3CBSQ7aydfh2ogSKGCejJCQ' |
88 | 88 | } |
89 | 89 | |
90 | 90 | class testVMContainer2 extends BaseContainer { |
91 | | - run (m) { |
| 91 | + onMessage (m) { |
92 | 92 | t.true(m === message, 'should recive a message') |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | 96 | class testVMContainer extends BaseContainer { |
97 | | - run (m) { |
| 97 | + onMessage (m) { |
98 | 98 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
99 | 99 | this.kernel.createInstance('test2', this.kernel.createMessage({ |
100 | 100 | ports: [portRef2] |
101 | 101 | })) |
133 | 133 | } |
134 | 134 | let hasResolved = false |
135 | 135 | |
136 | 136 | class testVMContainer2 extends BaseContainer { |
137 | | - run (m) { |
| 137 | + onMessage (m) { |
138 | 138 | t.true(m === message, 'should recive a message') |
139 | 139 | return new Promise((resolve, reject) => { |
140 | 140 | setTimeout(() => { |
141 | 141 | this.kernel.incrementTicks(1) |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | class testVMContainer extends BaseContainer { |
150 | | - run (m) { |
| 150 | + onMessage (m) { |
151 | 151 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
152 | 152 | this.kernel.createInstance('test2', this.kernel.createMessage({ |
153 | 153 | ports: [portRef2] |
154 | 154 | })) |
178 | 178 | t.deepEquals(stateRoot, expectedState, 'expected state') |
179 | 179 | |
180 | 180 | |
181 | 181 | class testVMContainer3 extends BaseContainer { |
182 | | - run (m) { |
| 182 | + onMessage (m) { |
183 | 183 | const port = this.kernel.ports.get('child') |
184 | 184 | this.kernel.send(port, m) |
185 | 185 | this.kernel.incrementTicks(1) |
186 | 186 | } |
194 | 194 | |
195 | 195 | tape('traps', async t => { |
196 | 196 | t.plan(1) |
197 | 197 | class Root extends BaseContainer { |
198 | | - async run (m) { |
| 198 | + async onMessage (m) { |
199 | 199 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
200 | 200 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
201 | 201 | const [portRef5, portRef6] = this.kernel.ports.createChannel() |
202 | 202 | |
238 | 238 | t.plan(2) |
239 | 239 | let runs = 0 |
240 | 240 | |
241 | 241 | class Root extends BaseContainer { |
242 | | - run (m) { |
| 242 | + onMessage (m) { |
243 | 243 | if (!runs) { |
244 | 244 | runs++ |
245 | 245 | |
246 | 246 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | 273 | class First extends BaseContainer { |
274 | | - run (m) { |
| 274 | + onMessage (m) { |
275 | 275 | this.kernel.incrementTicks(2) |
276 | 276 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
277 | 277 | data: 'first' |
278 | 278 | })) |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | 282 | class Second extends BaseContainer { |
283 | | - run (m) { |
| 283 | + onMessage (m) { |
284 | 284 | this.kernel.incrementTicks(3) |
285 | 285 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
286 | 286 | data: 'second' |
287 | 287 | })) |
310 | 310 | t.plan(2) |
311 | 311 | let runs = 0 |
312 | 312 | |
313 | 313 | class Root extends BaseContainer { |
314 | | - run (m) { |
| 314 | + onMessage (m) { |
315 | 315 | if (!runs) { |
316 | 316 | runs++ |
317 | 317 | |
318 | 318 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | 345 | class First extends BaseContainer { |
346 | | - run (m) { |
| 346 | + onMessage (m) { |
347 | 347 | this.kernel.incrementTicks(2) |
348 | 348 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
349 | 349 | data: 'first' |
350 | 350 | })) |
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | class Second extends BaseContainer { |
355 | | - run (m) { |
| 355 | + onMessage (m) { |
356 | 356 | this.kernel.incrementTicks(1) |
357 | 357 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
358 | 358 | data: 'second' |
359 | 359 | })) |
382 | 382 | t.plan(2) |
383 | 383 | let runs = 0 |
384 | 384 | |
385 | 385 | class Root extends BaseContainer { |
386 | | - run (m) { |
| 386 | + onMessage (m) { |
387 | 387 | if (!runs) { |
388 | 388 | runs++ |
389 | 389 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
390 | 390 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | 418 | class First extends BaseContainer { |
419 | | - run (m) { |
| 419 | + onMessage (m) { |
420 | 420 | this.kernel.incrementTicks(1) |
421 | 421 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
422 | 422 | data: 'first' |
423 | 423 | })) |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | 427 | class Second extends BaseContainer { |
428 | | - run (m) { |
| 428 | + onMessage (m) { |
429 | 429 | this.kernel.incrementTicks(2) |
430 | 430 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
431 | 431 | data: 'second' |
432 | 432 | })) |
454 | 454 | t.plan(2) |
455 | 455 | let runs = 0 |
456 | 456 | |
457 | 457 | class Root extends BaseContainer { |
458 | | - run (m) { |
| 458 | + onMessage (m) { |
459 | 459 | if (!runs) { |
460 | 460 | runs++ |
461 | 461 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
462 | 462 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
488 | 488 | } |
489 | 489 | } |
490 | 490 | |
491 | 491 | class First extends BaseContainer { |
492 | | - run (m) { |
| 492 | + onMessage (m) { |
493 | 493 | this.kernel.incrementTicks(2) |
494 | 494 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
495 | 495 | data: 'first' |
496 | 496 | })) |
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
500 | 500 | class Second extends BaseContainer { |
501 | | - run (m) { |
| 501 | + onMessage (m) { |
502 | 502 | this.kernel.incrementTicks(3) |
503 | 503 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
504 | 504 | data: 'second' |
505 | 505 | })) |
549 | 549 | |
550 | 550 | let runs = 0 |
551 | 551 | |
552 | 552 | class Root extends BaseContainer { |
553 | | - run (m) { |
| 553 | + onMessage (m) { |
554 | 554 | if (!runs) { |
555 | 555 | runs++ |
556 | 556 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
557 | 557 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
582 | 582 | } |
583 | 583 | } |
584 | 584 | |
585 | 585 | class First extends BaseContainer { |
586 | | - run (m) { |
| 586 | + onMessage (m) { |
587 | 587 | this.kernel.incrementTicks(2) |
588 | 588 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
589 | 589 | data: 'first' |
590 | 590 | })) |
591 | 591 | } |
592 | 592 | } |
593 | 593 | |
594 | 594 | class Second extends BaseContainer { |
595 | | - run (m) { |
| 595 | + onMessage (m) { |
596 | 596 | this.kernel.incrementTicks(2) |
597 | 597 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
598 | 598 | data: 'second' |
599 | 599 | })) |
622 | 622 | |
623 | 623 | let runs = 0 |
624 | 624 | |
625 | 625 | class Root extends BaseContainer { |
626 | | - run (m) { |
| 626 | + onMessage (m) { |
627 | 627 | if (!runs) { |
628 | 628 | runs++ |
629 | 629 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
630 | 630 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
655 | 655 | } |
656 | 656 | } |
657 | 657 | |
658 | 658 | class First extends BaseContainer { |
659 | | - run (m) { |
| 659 | + onMessage (m) { |
660 | 660 | this.kernel.incrementTicks(2) |
661 | 661 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
662 | 662 | data: 'first' |
663 | 663 | })) |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | 667 | class Second extends BaseContainer { |
668 | | - run (m) { |
| 668 | + onMessage (m) { |
669 | 669 | this.kernel.incrementTicks(2) |
670 | 670 | this.kernel.send(m.fromPort, this.kernel.createMessage({ |
671 | 671 | data: 'second' |
672 | 672 | })) |
696 | 696 | let runs = 0 |
697 | 697 | let instance |
698 | 698 | |
699 | 699 | class Root extends BaseContainer { |
700 | | - run (m) { |
| 700 | + onMessage (m) { |
701 | 701 | let one = this.kernel.ports.get('one') |
702 | 702 | if (!one) { |
703 | 703 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
704 | 704 | this.kernel.ports.bind('one', portRef1) |
713 | 713 | } |
714 | 714 | } |
715 | 715 | |
716 | 716 | class First extends BaseContainer { |
717 | | - run (m) { |
| 717 | + onMessage (m) { |
718 | 718 | ++runs |
719 | 719 | if (runs === 2) { |
720 | 720 | t.equals(instance, this, 'should have same instances') |
721 | 721 | } else { |
789 | 789 | const expectedSr = { |
790 | 790 | '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z' |
791 | 791 | } |
792 | 792 | class Root extends BaseContainer { |
793 | | - run (m) { |
| 793 | + onMessage (m) { |
794 | 794 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
795 | 795 | this.kernel.ports.bind('one', portRef1) |
796 | 796 | const message1 = this.kernel.createMessage({ |
797 | 797 | ports: [portRef2] |
803 | 803 | } |
804 | 804 | } |
805 | 805 | |
806 | 806 | class First extends BaseContainer { |
807 | | - run (m) { |
| 807 | + onMessage (m) { |
808 | 808 | this.kernel.incrementTicks(2) |
809 | 809 | this.kernel.ports.delete('root') |
810 | 810 | } |
811 | 811 | } |
835 | 835 | const expectedSr = { |
836 | 836 | '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z' |
837 | 837 | } |
838 | 838 | class Root extends BaseContainer { |
839 | | - run (m) { |
| 839 | + onMessage (m) { |
840 | 840 | this.kernel.createInstance('root') |
841 | 841 | } |
842 | 842 | } |
843 | 843 | |
864 | 864 | const expectedSr = { |
865 | 865 | '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z' |
866 | 866 | } |
867 | 867 | class Root extends BaseContainer { |
868 | | - run (m) { |
| 868 | + onMessage (m) { |
869 | 869 | const [, portRef2] = this.kernel.ports.createChannel() |
870 | 870 | this.kernel.createInstance('sub', this.kernel.createMessage({ |
871 | 871 | ports: [portRef2] |
872 | 872 | })) |
907 | 907 | const expectedSr = { |
908 | 908 | '/': 'zdpuAwsZTd5mRZBCYA1FJSHrpYDPgSZSiaTQp9xkUeajaoMHM' |
909 | 909 | } |
910 | 910 | class Root extends BaseContainer { |
911 | | - run (m) { |
| 911 | + onMessage (m) { |
912 | 912 | if (m.ports.length) { |
913 | 913 | const port = this.kernel.ports.get('test1') |
914 | 914 | this.kernel.send(port, m) |
915 | 915 | this.kernel.ports.unbind('test1') |
932 | 932 | } |
933 | 933 | } |
934 | 934 | |
935 | 935 | class Sub extends BaseContainer { |
936 | | - run (message) { |
| 936 | + onMessage (message) { |
937 | 937 | if (message.data === 'getChannel') { |
938 | 938 | const ports = this.kernel.ports.createChannel() |
939 | 939 | this.kernel.ports.bind('channel', ports[0]) |
940 | 940 | this.kernel.send(message.fromPort, this.kernel.createMessage({ |
971 | 971 | const expectedSr = { |
972 | 972 | '/': 'zdpuAmi9tkYTpoVsZvqQgxpQFRhCgYFVv4W3fjjfVhf1j8swv' |
973 | 973 | } |
974 | 974 | class Root extends BaseContainer { |
975 | | - run (m) { |
| 975 | + onMessage (m) { |
976 | 976 | if (m.ports.length) { |
977 | 977 | const port = this.kernel.ports.get('test1') |
978 | 978 | this.kernel.send(port, m) |
979 | 979 | this.kernel.ports.unbind('test1') |
997 | 997 | } |
998 | 998 | } |
999 | 999 | |
1000 | 1000 | class Sub extends BaseContainer { |
1001 | | - run (message) { |
| 1001 | + onMessage (message) { |
1002 | 1002 | if (message.data === 'getChannel') { |
1003 | 1003 | const ports = this.kernel.ports.createChannel() |
1004 | 1004 | this.kernel.ports.bind('channel', ports[0]) |
1005 | 1005 | this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1038 | 1038 | let runs = 0 |
1039 | 1039 | const returnValue = 'this is a test' |
1040 | 1040 | |
1041 | 1041 | class testVMContainer extends BaseContainer { |
1042 | | - run (m) { |
| 1042 | + onMessage (m) { |
1043 | 1043 | runs++ |
1044 | 1044 | if (runs === 1) { |
1045 | 1045 | return returnValue |
1046 | 1046 | } else { |
1075 | 1075 | |
1076 | 1076 | tape('start up', async t => { |
1077 | 1077 | t.plan(1) |
1078 | 1078 | class testVMContainer extends BaseContainer { |
1079 | | - run () {} |
1080 | | - startup () { |
| 1079 | + onMessage () {} |
| 1080 | + onStartup () { |
1081 | 1081 | t.true(true, 'should start up') |
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | |
1091 | 1091 | tape('large code size', async t => { |
1092 | 1092 | t.plan(1) |
1093 | 1093 | const content = Buffer.from(new ArrayBuffer(1000000)) |
1094 | 1094 | class testVMContainer extends BaseContainer { |
1095 | | - run () {} |
| 1095 | + onMessage () {} |
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | const hypervisor = new Hypervisor(node.dag) |
1099 | 1099 | hypervisor.registerContainer('test', testVMContainer) |