Commit 6da610e32ec129cd6b73621fbc7218782741896b
added tests for arbater on id
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 11/17/2017, 1:56:24 AM
Parent: 9a16576184581f6734875fc6fa632bb9bd5fdad8
Files changed
tests/index.js | changed |
tests/index.js | ||
---|---|---|
@@ -410,4 +410,71 @@ | ||
410 | 410 | |
411 | 411 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
412 | 412 | t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
413 | 413 | }) |
414 | + | |
415 | +tape('arbiter test for id comparision', async t => { | |
416 | + t.plan(5) | |
417 | + let message | |
418 | + const expectedState = { | |
419 | + '/': Buffer.from('0866fe6a6adaf28c51ce99ddfddd49c492e9ce48', 'hex') | |
420 | + } | |
421 | + | |
422 | + const tree = new RadixTree({ | |
423 | + db: db | |
424 | + }) | |
425 | + | |
426 | + class testVMContainerA extends BaseContainer { | |
427 | + onCreation (m) { | |
428 | + message = new Message({ | |
429 | + data: m.data | |
430 | + }) | |
431 | + this.kernel.send(m.caps[0], message) | |
432 | + } | |
433 | + } | |
434 | + | |
435 | + let recMsg = 0 | |
436 | + | |
437 | + class testVMContainerB extends BaseContainer { | |
438 | + onMessage (m) { | |
439 | + if (recMsg === 0) { | |
440 | + t.equal(m.data, 'first', 'should recive fist message') | |
441 | + } else if (recMsg === 1) { | |
442 | + t.equal(m.data, 'second', 'should recive second message') | |
443 | + } else if (recMsg === 2) { | |
444 | + t.equal(m.data, 'third', 'should recive third message') | |
445 | + } | |
446 | + recMsg++ | |
447 | + | |
448 | + return new Promise((resolve, reject) => { | |
449 | + setTimeout(resolve, 200) | |
450 | + }) | |
451 | + } | |
452 | + | |
453 | + static get typeId () { | |
454 | + return 8 | |
455 | + } | |
456 | + } | |
457 | + | |
458 | + const hypervisor = new Hypervisor(tree) | |
459 | + hypervisor.registerContainer(testVMContainerA) | |
460 | + hypervisor.registerContainer(testVMContainerB) | |
461 | + | |
462 | + let capB = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) | |
463 | + hypervisor.send(capB, new Message({ | |
464 | + data: 'first' | |
465 | + })) | |
466 | + await hypervisor.createInstance(testVMContainerA.typeId, new Message({ | |
467 | + caps: [capB], | |
468 | + data: 'second' | |
469 | + })) | |
470 | + | |
471 | + await hypervisor.createInstance(testVMContainerA.typeId, new Message({ | |
472 | + caps: [capB], | |
473 | + data: 'third' | |
474 | + })) | |
475 | + | |
476 | + const stateRoot = await hypervisor.createStateRoot(Infinity) | |
477 | + | |
478 | + t.deepEquals(stateRoot, expectedState, 'expected root!') | |
479 | + t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) | |
480 | +}) |
Built with git-ssb-web