tests/index.jsView |
---|
15 | 15 | } |
16 | 16 | } |
17 | 17 | |
18 | 18 | tape('basic', async t => { |
19 | | - t.plan(3) |
| 19 | + t.plan(2) |
20 | 20 | let message |
21 | 21 | const expectedState = { |
22 | 22 | '/': Buffer.from('70a9676b7995b108057bd29955e3874401aa5ba7', 'hex') |
23 | 23 | } |
41 | 41 | hypervisor.send(rootCap, message) |
42 | 42 | |
43 | 43 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
44 | 44 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
45 | | - |
46 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
47 | 45 | }) |
48 | 46 | |
49 | 47 | tape('caps manager', async t => { |
50 | 48 | const capsManager = new CapsManager({}) |
58 | 56 | t.end() |
59 | 57 | }) |
60 | 58 | |
61 | 59 | tape('two communicating actors', async t => { |
62 | | - t.plan(3) |
| 60 | + t.plan(2) |
63 | 61 | let message |
64 | 62 | const expectedState = { |
65 | 63 | '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
66 | 64 | } |
97 | 95 | |
98 | 96 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
99 | 97 | |
100 | 98 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
101 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
102 | 99 | }) |
103 | 100 | |
104 | 101 | tape('three communicating actors', async t => { |
105 | | - t.plan(4) |
| 102 | + t.plan(3) |
106 | 103 | let message |
107 | 104 | const expectedState = { |
108 | 105 | '/': Buffer.from('24855a8efa9af536f0f9b319c05b10d6b7cae6c8', 'hex') |
109 | 106 | } |
144 | 141 | |
145 | 142 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
146 | 143 | |
147 | 144 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
148 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
149 | 145 | }) |
150 | 146 | |
151 | 147 | tape('three communicating actors, with tick counting', async t => { |
152 | | - t.plan(4) |
| 148 | + t.plan(3) |
153 | 149 | let message |
154 | 150 | const expectedState = { |
155 | 151 | '/': Buffer.from('24855a8efa9af536f0f9b319c05b10d6b7cae6c8', 'hex') |
156 | 152 | } |
198 | 194 | |
199 | 195 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
200 | 196 | |
201 | 197 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
202 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
203 | 198 | }) |
204 | 199 | |
205 | 200 | tape('response caps', async t => { |
206 | | - t.plan(4) |
| 201 | + t.plan(3) |
207 | 202 | let message |
208 | 203 | const expectedState = { |
209 | 204 | '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
210 | 205 | } |
246 | 241 | |
247 | 242 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
248 | 243 | |
249 | 244 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
250 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
251 | 245 | }) |
252 | 246 | |
253 | 247 | tape('response caps for errors', async t => { |
254 | | - t.plan(4) |
| 248 | + t.plan(3) |
255 | 249 | let message |
256 | 250 | const expectedState = { |
257 | 251 | '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
258 | 252 | } |
295 | 289 | |
296 | 290 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
297 | 291 | |
298 | 292 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
299 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
300 | 293 | }) |
301 | 294 | |
302 | 295 | tape('actor creation', async t => { |
303 | | - t.plan(3) |
| 296 | + t.plan(2) |
304 | 297 | let message |
305 | 298 | const expectedState = { |
306 | 299 | '/': Buffer.from('8e809b10d473ef4592dc5c1683e89bc7001e5e3e', 'hex') |
307 | 300 | } |
328 | 321 | const cap = m.caps[0] |
329 | 322 | return this.kernel.send(cap, new Message()) |
330 | 323 | } |
331 | 324 | |
332 | | - onMessage (m) { |
333 | | - } |
334 | | - |
335 | 325 | static get typeId () { |
336 | 326 | return 8 |
337 | 327 | } |
338 | 328 | } |
345 | 335 | |
346 | 336 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
347 | 337 | |
348 | 338 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
349 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
350 | 339 | }) |
351 | 340 | |
352 | 341 | tape('simple message arbiter test', async t => { |
353 | | - t.plan(5) |
| 342 | + t.plan(4) |
354 | 343 | const expectedState = { |
355 | 344 | '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
356 | 345 | } |
357 | 346 | |
385 | 374 | if (recMsg === 0) { |
386 | 375 | t.equal(m.data, 'first', 'should recive fist message') |
387 | 376 | } else if (recMsg === 1) { |
388 | 377 | t.equal(m.data, 'second', 'should recive second message') |
389 | | - } else if (recMsg === 2) { |
| 378 | + } else { |
390 | 379 | t.equal(m.data, 'third', 'should recive third message') |
391 | 380 | } |
392 | 381 | recMsg++ |
393 | 382 | } |
408 | 397 | |
409 | 398 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
410 | 399 | |
411 | 400 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
412 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
413 | 401 | }) |
414 | 402 | |
415 | 403 | tape('arbiter test for id comparision', async t => { |
416 | | - t.plan(5) |
| 404 | + t.plan(4) |
417 | 405 | let message |
418 | 406 | const expectedState = { |
419 | 407 | '/': Buffer.from('0866fe6a6adaf28c51ce99ddfddd49c492e9ce48', 'hex') |
420 | 408 | } |
439 | 427 | if (recMsg === 0) { |
440 | 428 | t.equal(m.data, 'first', 'should recive fist message') |
441 | 429 | } else if (recMsg === 1) { |
442 | 430 | t.equal(m.data, 'second', 'should recive second message') |
443 | | - } else if (recMsg === 2) { |
| 431 | + } else { |
444 | 432 | t.equal(m.data, 'third', 'should recive third message') |
445 | 433 | } |
446 | 434 | recMsg++ |
447 | 435 | |
475 | 463 | |
476 | 464 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
477 | 465 | |
478 | 466 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
479 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
480 | 467 | }) |
481 | 468 | |
482 | 469 | tape('basic tagged caps', async t => { |
483 | | - t.plan(5) |
| 470 | + t.plan(4) |
484 | 471 | const expectedState = { |
485 | 472 | '/': Buffer.from('ef403643f292108fe9edc1700d80a7bf2402e7a0', 'hex') |
486 | 473 | } |
487 | 474 | |
522 | 509 | |
523 | 510 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
524 | 511 | |
525 | 512 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
526 | | - t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
527 | 513 | }) |
| 514 | + |
| 515 | +tape('trying to listen for caps more then once', async t => { |
| 516 | + t.plan(4) |
| 517 | + const expectedState = { |
| 518 | + '/': Buffer.from('ef403643f292108fe9edc1700d80a7bf2402e7a0', 'hex') |
| 519 | + } |
| 520 | + |
| 521 | + const tree = new RadixTree({ |
| 522 | + db: db |
| 523 | + }) |
| 524 | + |
| 525 | + class testVMContainerA extends BaseContainer { |
| 526 | + async onMessage (m) { |
| 527 | + t.true(m, 'should recive first message') |
| 528 | + const rCap = this.kernel.mintCap(1) |
| 529 | + const message = new Message({data: 'first'}) |
| 530 | + message.responseCap = rCap |
| 531 | + await this.kernel.send(m.caps[0], message) |
| 532 | + const promise = this.kernel.inbox.waitOnTag([1], 44) |
| 533 | + try { |
| 534 | + await this.kernel.inbox.waitOnTag([1], 44) |
| 535 | + } catch (e) { |
| 536 | + t.true(e, 'should error if waiting twice') |
| 537 | + } |
| 538 | + return promise |
| 539 | + } |
| 540 | + } |
| 541 | + |
| 542 | + class testVMContainerB extends BaseContainer { |
| 543 | + onMessage (m) { |
| 544 | + t.true(m, 'should recive a message') |
| 545 | + } |
| 546 | + |
| 547 | + static get typeId () { |
| 548 | + return 8 |
| 549 | + } |
| 550 | + } |
| 551 | + |
| 552 | + const hypervisor = new Hypervisor(tree) |
| 553 | + hypervisor.registerContainer(testVMContainerA) |
| 554 | + hypervisor.registerContainer(testVMContainerB) |
| 555 | + |
| 556 | + let capA = await hypervisor.createInstance(testVMContainerA.typeId, new Message()) |
| 557 | + let capB = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 558 | + |
| 559 | + await hypervisor.send(capA, new Message({caps: [capB]})) |
| 560 | + |
| 561 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 562 | + |
| 563 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 564 | +}) |
| 565 | + |
| 566 | +tape('multple messages to restore on waiting for tags', async t => { |
| 567 | + t.plan(6) |
| 568 | + const expectedState = { |
| 569 | + '/': Buffer.from('c2bbd78ee38ecf417f857451bdb06cdba1345b22', 'hex') |
| 570 | + } |
| 571 | + |
| 572 | + const tree = new RadixTree({ |
| 573 | + db: db |
| 574 | + }) |
| 575 | + |
| 576 | + class testVMContainerA extends BaseContainer { |
| 577 | + async onMessage (m) { |
| 578 | + t.true(m, 'should recive first message') |
| 579 | + if (m.caps.length) { |
| 580 | + const cap1 = this.kernel.mintCap(1) |
| 581 | + const cap2 = this.kernel.mintCap(2) |
| 582 | + const message1 = new Message({ |
| 583 | + data: 'first' |
| 584 | + }) |
| 585 | + const message2 = new Message({ |
| 586 | + data: 'second' |
| 587 | + }) |
| 588 | + message1.caps.push(cap1) |
| 589 | + message2.caps.push(cap2) |
| 590 | + await Promise.all([ |
| 591 | + this.kernel.send(m.caps[0], message1), |
| 592 | + this.kernel.send(m.caps[1], message2) |
| 593 | + ]) |
| 594 | + const rMessage = await this.kernel.inbox.waitOnTag([1, 2], 44) |
| 595 | + t.true(rMessage, 'should recive a response message') |
| 596 | + } |
| 597 | + } |
| 598 | + } |
| 599 | + |
| 600 | + class testVMContainerB extends BaseContainer { |
| 601 | + async onMessage (m) { |
| 602 | + t.true(m, 'should recive a message') |
| 603 | + const cap = m.caps[0] |
| 604 | + this.kernel.incrementTicks(1) |
| 605 | + await this.kernel.send(cap, new Message({data: m.data})) |
| 606 | + |
| 607 | + return new Promise((resolve, reject) => { |
| 608 | + setTimeout(resolve, 200) |
| 609 | + }) |
| 610 | + } |
| 611 | + |
| 612 | + static get typeId () { |
| 613 | + return 8 |
| 614 | + } |
| 615 | + } |
| 616 | + |
| 617 | + const hypervisor = new Hypervisor(tree) |
| 618 | + hypervisor.registerContainer(testVMContainerA) |
| 619 | + hypervisor.registerContainer(testVMContainerB) |
| 620 | + |
| 621 | + let capA = await hypervisor.createInstance(testVMContainerA.typeId, new Message()) |
| 622 | + let capB1 = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 623 | + let capB2 = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 624 | + |
| 625 | + await hypervisor.send(capA, new Message({caps: [capB1, capB2]})) |
| 626 | + |
| 627 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 628 | + |
| 629 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 630 | +}) |
| 631 | + |
| 632 | +tape('multple messages to backup on waiting for tags', async t => { |
| 633 | + t.plan(6) |
| 634 | + const expectedState = { |
| 635 | + '/': Buffer.from('c2bbd78ee38ecf417f857451bdb06cdba1345b22', 'hex') |
| 636 | + } |
| 637 | + |
| 638 | + const tree = new RadixTree({ |
| 639 | + db: db |
| 640 | + }) |
| 641 | + |
| 642 | + class testVMContainerA extends BaseContainer { |
| 643 | + async onMessage (m) { |
| 644 | + t.true(m, 'should recive first message') |
| 645 | + if (m.caps.length) { |
| 646 | + const cap1 = this.kernel.mintCap(1) |
| 647 | + const cap2 = this.kernel.mintCap(2) |
| 648 | + const message1 = new Message({ |
| 649 | + data: 'first' |
| 650 | + }) |
| 651 | + const message2 = new Message({ |
| 652 | + data: 'second' |
| 653 | + }) |
| 654 | + message1.caps.push(cap1) |
| 655 | + message2.caps.push(cap2) |
| 656 | + await this.kernel.send(m.caps[0], message1) |
| 657 | + await this.kernel.send(m.caps[1], message2) |
| 658 | + const rMessage = await this.kernel.inbox.waitOnTag([1, 2], 44) |
| 659 | + t.true(rMessage, 'should recive a response message') |
| 660 | + } |
| 661 | + } |
| 662 | + } |
| 663 | + |
| 664 | + class testVMContainerB extends BaseContainer { |
| 665 | + async onMessage (m) { |
| 666 | + t.true(m, 'should recive a message') |
| 667 | + const cap = m.caps[0] |
| 668 | + this.kernel.incrementTicks(1) |
| 669 | + await this.kernel.send(cap, new Message({data: m.data})) |
| 670 | + |
| 671 | + return new Promise((resolve, reject) => { |
| 672 | + setTimeout(resolve, 200) |
| 673 | + }) |
| 674 | + } |
| 675 | + |
| 676 | + static get typeId () { |
| 677 | + return 8 |
| 678 | + } |
| 679 | + } |
| 680 | + |
| 681 | + const hypervisor = new Hypervisor(tree) |
| 682 | + hypervisor.registerContainer(testVMContainerA) |
| 683 | + hypervisor.registerContainer(testVMContainerB) |
| 684 | + |
| 685 | + let capA = await hypervisor.createInstance(testVMContainerA.typeId, new Message()) |
| 686 | + let capB1 = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 687 | + let capB2 = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 688 | + |
| 689 | + await hypervisor.send(capA, new Message({caps: [capB1, capB2]})) |
| 690 | + |
| 691 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 692 | + |
| 693 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 694 | +}) |
| 695 | + |
| 696 | +tape('multple messages, but single tag', async t => { |
| 697 | + t.plan(6) |
| 698 | + const expectedState = { |
| 699 | + '/': Buffer.from('c2bbd78ee38ecf417f857451bdb06cdba1345b22', 'hex') |
| 700 | + } |
| 701 | + |
| 702 | + const tree = new RadixTree({ |
| 703 | + db: db |
| 704 | + }) |
| 705 | + |
| 706 | + class testVMContainerA extends BaseContainer { |
| 707 | + async onMessage (m) { |
| 708 | + t.true(m, 'should recive first message') |
| 709 | + if (m.caps.length) { |
| 710 | + const cap1 = this.kernel.mintCap(1) |
| 711 | + const cap2 = this.kernel.mintCap(2) |
| 712 | + const message1 = new Message({ |
| 713 | + data: 'first' |
| 714 | + }) |
| 715 | + const message2 = new Message({ |
| 716 | + data: 'second' |
| 717 | + }) |
| 718 | + message1.caps.push(cap1) |
| 719 | + message2.caps.push(cap2) |
| 720 | + await this.kernel.send(m.caps[0], message1) |
| 721 | + await this.kernel.send(m.caps[1], message2) |
| 722 | + const rMessage = await this.kernel.inbox.waitOnTag([2], 44) |
| 723 | + t.true(rMessage, 'should recive a response message') |
| 724 | + } |
| 725 | + } |
| 726 | + } |
| 727 | + |
| 728 | + class testVMContainerB extends BaseContainer { |
| 729 | + async onMessage (m) { |
| 730 | + t.true(m, 'should recive a message') |
| 731 | + const cap = m.caps[0] |
| 732 | + this.kernel.incrementTicks(1) |
| 733 | + await this.kernel.send(cap, new Message({data: m.data})) |
| 734 | + |
| 735 | + return new Promise((resolve, reject) => { |
| 736 | + setTimeout(resolve, 200) |
| 737 | + }) |
| 738 | + } |
| 739 | + |
| 740 | + static get typeId () { |
| 741 | + return 8 |
| 742 | + } |
| 743 | + } |
| 744 | + |
| 745 | + const hypervisor = new Hypervisor(tree) |
| 746 | + hypervisor.registerContainer(testVMContainerA) |
| 747 | + hypervisor.registerContainer(testVMContainerB) |
| 748 | + |
| 749 | + let capA = await hypervisor.createInstance(testVMContainerA.typeId, new Message()) |
| 750 | + let capB1 = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 751 | + let capB2 = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 752 | + |
| 753 | + await hypervisor.send(capA, new Message({caps: [capB1, capB2]})) |
| 754 | + |
| 755 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 756 | + |
| 757 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 758 | +}) |
| 759 | + |
| 760 | +tape('deadlock test', async t => { |
| 761 | + t.plan(7) |
| 762 | + const expectedState = { |
| 763 | + '/': Buffer.from('2e8658dc2f616599b4fa622318b86ad6ed809db0', 'hex') |
| 764 | + } |
| 765 | + |
| 766 | + const tree = new RadixTree({ |
| 767 | + db: db |
| 768 | + }) |
| 769 | + |
| 770 | + class testVMContainerA extends BaseContainer { |
| 771 | + async onMessage (m) { |
| 772 | + t.true(m, 'should recive first message 1') |
| 773 | + const rMessage = await this.kernel.inbox.waitOnTag([1], 50) |
| 774 | + t.equals(rMessage, undefined, 'should recive a response message 1') |
| 775 | + } |
| 776 | + } |
| 777 | + |
| 778 | + class testVMContainerB extends BaseContainer { |
| 779 | + async onMessage (m) { |
| 780 | + t.true(m, 'should recive first message 2') |
| 781 | + this.kernel.incrementTicks(47) |
| 782 | + const rMessage = await this.kernel.inbox.waitOnTag([1], 1) |
| 783 | + t.equals(rMessage, undefined, 'should recive a response message 2') |
| 784 | + } |
| 785 | + |
| 786 | + static get typeId () { |
| 787 | + return 8 |
| 788 | + } |
| 789 | + } |
| 790 | + |
| 791 | + class testVMContainerC extends BaseContainer { |
| 792 | + async onMessage (m) { |
| 793 | + t.true(m, 'should recive first message 3') |
| 794 | + this.kernel.incrementTicks(45) |
| 795 | + const rMessage = await this.kernel.inbox.waitOnTag([1], 1) |
| 796 | + t.equals(rMessage, undefined, 'should recive a response message 3') |
| 797 | + } |
| 798 | + |
| 799 | + static get typeId () { |
| 800 | + return 7 |
| 801 | + } |
| 802 | + } |
| 803 | + |
| 804 | + const hypervisor = new Hypervisor(tree) |
| 805 | + hypervisor.registerContainer(testVMContainerA) |
| 806 | + hypervisor.registerContainer(testVMContainerB) |
| 807 | + hypervisor.registerContainer(testVMContainerC) |
| 808 | + |
| 809 | + let capA = await hypervisor.createInstance(testVMContainerA.typeId, new Message()) |
| 810 | + let capB = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 811 | + let capC = await hypervisor.createInstance(testVMContainerC.typeId, new Message()) |
| 812 | + |
| 813 | + await Promise.all([ |
| 814 | + hypervisor.send(capA, new Message()), |
| 815 | + hypervisor.send(capB, new Message()), |
| 816 | + hypervisor.send(capC, new Message()) |
| 817 | + ]) |
| 818 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 819 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 820 | +}) |