git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 67f17984adbe450a9a06aa0987f1b232af5f3120

removed creation methods

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 9/7/2017, 7:11:37 PM
Parent: e10327188504fa350697ac7abbb620cb1df69554

Files changed

creationService.jschanged
index.jschanged
kernel.jschanged
portManager.jschanged
tests/index.jschanged
creationService.jsView
@@ -9,10 +9,13 @@
99 }
1010
1111 queue (port, message) {
1212 if (message.data.type) {
13- const creator = this.scheduler.getInstance(message.fromId)
14- const id = creator.generateNextId()
13+ let id
14+ if (message.fromId) {
15+ const creator = this.scheduler.getInstance(message.fromId)
16+ id = creator.generateNextId()
17+ }
1518 return this.createInstance(message, id)
1619 }
1720 }
1821
index.jsView
@@ -120,12 +120,8 @@
120120 return instance
121121 }
122122 }
123123
124- createInstance (message, id) {
125- return this.creationService.createInstance(message, id)
126- }
127-
128124 createChannel () {
129125 const port1 = {
130126 messages: []
131127 }
kernel.jsView
@@ -142,20 +142,8 @@
142142 this.ports.checkSendingPorts(message)
143143 return message
144144 }
145145
146- /**
147- * creates a new container. Returning a port to it.
148- * @param {String} type
149- * @param {*} data - the data to populate the initail state with
150- * @returns {Object}
151- */
152- createInstance (message) {
153- this.ports.removeSentPorts(message)
154- const id = this.generateNextId()
155- return this.hypervisor.createInstance(message, id)
156- }
157-
158146 generateNextId () {
159147 let nonce = this.state.nonce
160148
161149 const id = {
portManager.jsView
@@ -57,9 +57,8 @@
5757
5858 // save the port instance
5959 this.ports[name] = port
6060
61- // console.log(name, port)
6261 // update the dest port
6362 const destPort = await this.hypervisor.getDestPort(port)
6463 port.messages.forEach(message => {
6564 message._fromPort = port
@@ -116,8 +115,9 @@
116115 const waits = []
117116 this._unboundPorts.forEach(port => {
118117 waits.push(this.kernel.send(port, new DeleteMessage()))
119118 })
119+
120120 this._unboundPorts.clear()
121121 return Promise.all(waits)
122122 }
123123
tests/index.jsView
@@ -38,14 +38,18 @@
3838 try {
3939 const hypervisor = new Hypervisor(node.dag)
4040 hypervisor.registerContainer(testVMContainer)
4141
42- const rootContainer = await hypervisor.createInstance(new Message({
42+ const port = hypervisor.creationService.getPort()
43+
44+ let rootContainer = await hypervisor.send(port, new Message({
4345 data: {
4446 type: testVMContainer.typeId
4547 }
4648 }))
4749
50+ rootContainer = await hypervisor.getInstance(rootContainer.id)
51+
4852 hypervisor.pin(rootContainer)
4953
5054 const [portRef1, portRef2] = rootContainer.ports.createChannel()
5155 const initMessage = rootContainer.createMessage({
@@ -55,13 +59,14 @@
5559 },
5660 ports: [portRef2]
5761 })
5862
59- await rootContainer.createInstance(initMessage)
63+ await rootContainer.send(port, initMessage)
64+ await rootContainer.ports.bind('first', portRef1)
6065
61- await rootContainer.ports.bind('first', portRef1)
6266 message = rootContainer.createMessage()
6367 await rootContainer.send(portRef1, message)
68+ rootContainer.shutdown()
6469
6570 // console.log(JSON.stringify(hypervisor.state, null, 2))
6671 const stateRoot = await hypervisor.createStateRoot(Infinity)
6772 t.deepEquals(stateRoot, expectedState, 'expected root!')
@@ -85,25 +90,33 @@
8590 try {
8691 const hypervisor = new Hypervisor(node.dag)
8792 hypervisor.registerContainer(testVMContainer)
8893
89- const root = await hypervisor.createInstance(new Message({
94+ const creationPort = hypervisor.creationService.getPort()
95+ let root = await hypervisor.send(creationPort, new Message({
9096 data: {
9197 type: testVMContainer.typeId
9298 }
9399 }))
94100
95101 hypervisor.pin(root)
102+
103+ root = await hypervisor.getInstance(root.id)
104+
96105 const [portRef1, portRef2] = root.ports.createChannel()
97106
98- await root.ports.bind('one', portRef1)
99- await root.createInstance(root.createMessage({
100- data: {
101- type: testVMContainer.typeId
102- },
103- ports: [portRef2]
104- }))
107+ await Promise.all([
108+ root.ports.bind('one', portRef1),
109+ root.send(creationPort, root.createMessage({
110+ data: {
111+ type: testVMContainer.typeId
112+ },
113+ ports: [portRef2]
114+ }))
115+ ])
105116
117+ root.shutdown()
118+
106119 const stateRoot = await hypervisor.createStateRoot(Infinity)
107120
108121 // await hypervisor.graph.tree(stateRoot, Infinity, true)
109122 // console.log(JSON.stringify(stateRoot, null, 2))
@@ -118,8 +131,9 @@
118131 let message
119132 const expectedState = {
120133 '/': 'zdpuB2Huo3ro3Fv9mpMhnUcL3jjd37T6MJ6jEd8GvA2cpvaYR'
121134 }
135+
122136 let hasResolved = false
123137
124138 class testVMContainer2 extends BaseContainer {
125139 onMessage (m) {
@@ -140,15 +154,20 @@
140154
141155 class testVMContainer extends BaseContainer {
142156 async onMessage (m) {
143157 const [portRef1, portRef2] = this.kernel.ports.createChannel()
144- await this.kernel.createInstance(this.kernel.createMessage({
145- data: {
146- type: testVMContainer2.typeId
147- },
148- ports: [portRef2]
149- }))
150- await this.kernel.send(portRef1, m)
158+ const port = this.kernel.hypervisor.creationService.getPort()
159+
160+ await Promise.all([
161+ this.kernel.send(port, this.kernel.createMessage({
162+ data: {
163+ type: testVMContainer2.typeId
164+ },
165+ ports: [portRef2]
166+ })),
167+ this.kernel.send(portRef1, m)
168+ ])
169+
151170 this.kernel.incrementTicks(1)
152171 return this.kernel.ports.bind('child', portRef1)
153172 }
154173 }
@@ -156,34 +175,38 @@
156175 const hypervisor = new Hypervisor(node.dag)
157176 hypervisor.registerContainer(testVMContainer)
158177 hypervisor.registerContainer(testVMContainer2)
159178
160- let root = await hypervisor.createInstance(new Message({
179+ let creationPort = hypervisor.creationService.getPort()
180+ let root = await hypervisor.send(creationPort, new Message({
161181 data: {
162182 type: testVMContainer.typeId
163183 }
164184 }))
165185
166186 hypervisor.pin(root)
167187
168188 const rootId = root.id
189+ root = await hypervisor.getInstance(rootId)
169190 const [portRef1, portRef2] = root.ports.createChannel()
170- await root.createInstance(root.createMessage({
171- data: {
172- type: testVMContainer.typeId
173- },
174- ports: [portRef2]
175- }))
176191
177- await root.ports.bind('first', portRef1)
178192 message = root.createMessage()
193+ await Promise.all([
194+ root.send(creationPort, root.createMessage({
195+ data: {
196+ type: testVMContainer.typeId
197+ },
198+ ports: [portRef2]
199+ })),
200+ root.ports.bind('first', portRef1),
201+ root.send(portRef1, message)
202+ ])
179203
180- await root.send(portRef1, message)
204+ root.shutdown()
205+
181206 const stateRoot = await hypervisor.createStateRoot(Infinity)
182207 t.true(hasResolved, 'should resolve before generating the state root')
183208
184- // await hypervisor.graph.tree(stateRoot, Infinity, true)
185- // console.log(JSON.stringify(stateRoot, null, 2))
186209 t.deepEquals(stateRoot, expectedState, 'expected state')
187210
188211 // test reviving the state
189212 class testVMContainer3 extends BaseContainer {
@@ -203,51 +226,27 @@
203226 tape('traps', async t => {
204227 t.plan(1)
205228 class Root extends BaseContainer {
206229 async onMessage (m) {
207- const [portRef1, portRef2] = this.kernel.ports.createChannel()
208- const [portRef3, portRef4] = this.kernel.ports.createChannel()
209- const [portRef5, portRef6] = this.kernel.ports.createChannel()
230+ const [portRef1] = this.kernel.ports.createChannel()
231+ const [portRef3] = this.kernel.ports.createChannel()
232+ const [portRef5] = this.kernel.ports.createChannel()
210233
211234 await Promise.all(
212235 this.kernel.ports.bind('one', portRef1),
213236 this.kernel.ports.bind('two', portRef3),
214237 this.kernel.ports.bind('three', portRef5)
215238 )
216239
217- const message1 = this.kernel.createMessage({
218- data: {
219- type: Root.typeId
220- },
221- ports: [portRef2]
222- })
223- const message2 = this.kernel.createMessage({
224- data: {
225- type: Root.typeId
226- },
227- ports: [portRef4]
228- })
229- const message3 = this.kernel.createMessage({
230- data: {
231- type: Root.typeId
232- },
233- ports: [portRef6]
234- })
235-
236- await Promise.all([
237- this.kernel.createInstance(message1),
238- this.kernel.createInstance(message2),
239- this.kernel.createInstance(message3)
240- ])
241-
242240 throw new Error('it is a trap!!!')
243241 }
244242 }
245243
246244 const hypervisor = new Hypervisor(node.dag)
247245
248246 hypervisor.registerContainer(Root)
249- const root = await hypervisor.createInstance(new Message({
247+ const creationPort = hypervisor.creationService.getPort()
248+ const root = await hypervisor.send(creationPort, new Message({
250249 data: {
251250 type: Root.typeId
252251 }
253252 }))
@@ -264,8 +263,10 @@
264263
265264 tape('recieving older messages', async t => {
266265 t.plan(2)
267266 let runs = 0
267+ const hypervisor = new Hypervisor(node.dag)
268+ const creationPort = hypervisor.creationService.getPort()
268269
269270 class Root extends BaseContainer {
270271 async onMessage (m) {
271272 if (!runs) {
@@ -285,16 +286,16 @@
285286 },
286287 ports: [portRef4]
287288 })
288289
289- await Promise.all([
290- this.kernel.createInstance(message1),
290+ return Promise.all([
291+ this.kernel.send(creationPort, message1),
291292 this.kernel.send(portRef1, this.kernel.createMessage()),
292293 this.kernel.send(portRef3, this.kernel.createMessage()),
293294 this.kernel.ports.bind('one', portRef1),
294- this.kernel.ports.bind('two', portRef3)
295+ this.kernel.ports.bind('two', portRef3),
296+ this.kernel.send(creationPort, message2)
295297 ])
296- return this.kernel.createInstance(message2)
297298 } else if (runs === 1) {
298299 runs++
299300 t.equals(m.data, 'first', 'should recive the first message')
300301 } else if (runs === 2) {
@@ -334,34 +335,35 @@
334335 }
335336 }
336337
337338 try {
338- const hypervisor = new Hypervisor(node.dag)
339-
340339 hypervisor.registerContainer(Root)
341340 hypervisor.registerContainer(First)
342341 hypervisor.registerContainer(Waiter)
343342
344- const root = await hypervisor.createInstance(new Message({
343+ let root = await hypervisor.send(creationPort, new Message({
345344 data: {
346345 type: Root.typeId
347346 }
348347 }))
349348
350349 hypervisor.pin(root)
350+
351+ root = await hypervisor.getInstance(root.id)
351352 const [portRef1, portRef2] = root.ports.createChannel()
352353
353354 const message = root.createMessage()
354355 await Promise.all([
355356 root.send(portRef1, message),
356357 root.ports.bind('first', portRef1),
357- root.createInstance(root.createMessage({
358+ root.send(creationPort, root.createMessage({
358359 data: {
359360 type: Root.typeId
360361 },
361362 ports: [portRef2]
362363 }))
363364 ])
365+ root.shutdown()
364366 } catch (e) {
365367 console.log(e)
366368 }
367369 })
@@ -369,8 +371,11 @@
369371 tape('saturation', async t => {
370372 t.plan(3)
371373 let runs = 0
372374
375+ const hypervisor = new Hypervisor(node.dag)
376+ const creationPort = hypervisor.creationService.getPort()
377+
373378 class Root extends BaseContainer {
374379 onIdle () {}
375380 async onMessage (m) {
376381 if (!runs) {
@@ -383,8 +388,9 @@
383388 type: First.typeId
384389 },
385390 ports: [portRef2]
386391 })
392+
387393 const message2 = this.kernel.createMessage({
388394 data: {
389395 type: Second.typeId
390396 },
@@ -392,10 +398,10 @@
392398 })
393399
394400 this.kernel.incrementTicks(6)
395401 return Promise.all([
396- this.kernel.createInstance(message1),
397- this.kernel.createInstance(message2),
402+ this.kernel.send(creationPort, message1),
403+ this.kernel.send(creationPort, message2),
398404 this.kernel.send(portRef1, this.kernel.createMessage()),
399405 this.kernel.send(portRef3, this.kernel.createMessage()),
400406 this.kernel.ports.bind('one', portRef1),
401407 this.kernel.ports.bind('two', portRef3)
@@ -452,16 +458,14 @@
452458 }
453459 }
454460
455461 try {
456- const hypervisor = new Hypervisor(node.dag)
457-
458462 hypervisor.registerContainer(Root)
459463 hypervisor.registerContainer(First)
460464 hypervisor.registerContainer(Second)
461465 hypervisor.registerContainer(Waiter)
462466
463- let root = await hypervisor.createInstance(new Message({
467+ let root = await hypervisor.send(creationPort, new Message({
464468 data: {
465469 type: Root.typeId
466470 }
467471 }))
@@ -474,24 +478,23 @@
474478 const message = root.createMessage()
475479 await Promise.all([
476480 root.send(portRef1, message),
477481 root.ports.bind('first', portRef1),
478- root.createInstance(root.createMessage({
482+ root.send(creationPort, root.createMessage({
479483 data: {
480484 type: Root.typeId
481485 },
482486 ports: [portRef2]
483487 })),
484488 root.ports.bind('sencond', portRef3),
485- root.createInstance(root.createMessage({
489+ root.send(creationPort, root.createMessage({
486490 data: {
487491 type: Waiter.typeId
488492 },
489493 ports: [portRef4]
490494 }))
491495 ])
492496
493- // root = await hypervisor.getInstance(root.id)
494497 root.incrementTicks(100)
495498 await root.send(portRef1, root.createMessage({
496499 data: 'testss'
497500 }))
@@ -506,8 +509,11 @@
506509
507510 let runs = 0
508511 let instance
509512
513+ const hypervisor = new Hypervisor(node.dag)
514+ const creationPort = hypervisor.creationService.getPort()
515+
510516 class Root extends BaseContainer {
511517 async onMessage (m) {
512518 let one = this.kernel.ports.get('one')
513519 if (!one) {
@@ -517,9 +523,9 @@
517523 type: First.typeId
518524 },
519525 ports: [portRef2]
520526 })
521- await this.kernel.createInstance(message1)
527+ await this.kernel.send(creationPort, message1)
522528 return this.kernel.ports.bind('one', portRef1)
523529 } else {
524530 return Promise.all([
525531 this.kernel.send(one, this.kernel.createMessage()),
@@ -543,34 +549,35 @@
543549 }
544550 }
545551
546552 try {
547- const hypervisor = new Hypervisor(node.dag)
548-
549553 hypervisor.registerContainer(Root)
550554 hypervisor.registerContainer(First)
551555
552- const root = await hypervisor.createInstance(new Message({
556+ let root = await hypervisor.send(creationPort, new Message({
553557 data: {
554558 type: Root.typeId
555559 }
556560 }))
557561
558562 hypervisor.pin(root)
563+ root = await hypervisor.getInstance(root.id)
559564
560565 const [portRef1, portRef2] = root.ports.createChannel()
561566 await Promise.all([
562567 root.ports.bind('first', portRef1),
563- root.createInstance(root.createMessage({
568+ root.send(creationPort, root.createMessage({
564569 data: {
565570 type: Root.typeId
566571 },
567572 ports: [portRef2]
568573 }))
569574 ])
570575
571576 const message = root.createMessage()
577+
572578 await root.send(portRef1, message)
579+ root.shutdown()
573580 await hypervisor.createStateRoot()
574581 await root.send(portRef1, root.createMessage())
575582 await hypervisor.createStateRoot()
576583 t.equals(runs, 2)
@@ -581,20 +588,22 @@
581588
582589 tape('checking ports', async t => {
583590 t.plan(4)
584591 const hypervisor = new Hypervisor(node.dag)
592+ const creationPort = hypervisor.creationService.getPort()
585593 hypervisor.registerContainer(BaseContainer)
586594
587- const root = await hypervisor.createInstance(new Message({
595+ let root = await hypervisor.send(creationPort, new Message({
588596 data: {
589597 type: BaseContainer.typeId
590598 }
591599 }))
592600
593601 hypervisor.pin(root)
602+ root = await hypervisor.getInstance(root.id)
594603
595604 const [portRef1, portRef2] = root.ports.createChannel()
596- root.createInstance(root.createMessage({
605+ root.send(creationPort, root.createMessage({
597606 data: {
598607 type: BaseContainer.typeId
599608 },
600609 ports: [portRef2]
@@ -632,8 +641,12 @@
632641 tape('port deletion', async t => {
633642 const expectedSr = {
634643 '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
635644 }
645+
646+ const hypervisor = new Hypervisor(node.dag)
647+ const creationPort = hypervisor.creationService.getPort()
648+
636649 class Root extends BaseContainer {
637650 async onMessage (m) {
638651 const [portRef1, portRef2] = this.kernel.ports.createChannel()
639652 const message1 = this.kernel.createMessage({
@@ -642,10 +655,12 @@
642655 },
643656 ports: [portRef2]
644657 })
645658
646- await this.kernel.createInstance(message1)
647- await this.kernel.send(portRef1, this.kernel.createMessage())
659+ await Promise.all([
660+ this.kernel.send(creationPort, message1),
661+ this.kernel.send(portRef1, this.kernel.createMessage())
662+ ])
648663 this.kernel.incrementTicks(6)
649664 return this.kernel.ports.bind('one', portRef1)
650665 }
651666 }
@@ -659,24 +674,23 @@
659674 return 299
660675 }
661676 }
662677
663- const hypervisor = new Hypervisor(node.dag)
664-
665678 hypervisor.registerContainer(Root)
666679 hypervisor.registerContainer(First)
667680
668- const root = await hypervisor.createInstance(new Message({
681+ let root = await hypervisor.send(creationPort, new Message({
669682 data: {
670683 type: Root.typeId
671684 }
672685 }))
673686
674687 hypervisor.pin(root)
688+ root = await hypervisor.getInstance(root.id)
675689
676690 const [portRef1, portRef2] = root.ports.createChannel()
677691 await root.ports.bind('first', portRef1)
678- await root.createInstance(root.createMessage({
692+ await root.send(creationPort, root.createMessage({
679693 data: {
680694 type: Root.typeId
681695 },
682696 ports: [portRef2]
@@ -684,8 +698,10 @@
684698
685699 const message = root.createMessage()
686700 await root.send(portRef1, message)
687701
702+ root.shutdown()
703+
688704 const sr = await hypervisor.createStateRoot()
689705 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
690706 await hypervisor.graph.tree(sr, Infinity, true)
691707
@@ -696,40 +712,44 @@
696712 const expectedSr = {
697713 '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
698714 }
699715
716+ const hypervisor = new Hypervisor(node.dag)
717+ const creationPort = hypervisor.creationService.getPort()
718+
700719 class Root extends BaseContainer {
701720 onMessage (m) {
702- return this.kernel.createInstance(new Message({
721+ return this.kernel.send(creationPort, new Message({
703722 data: {
704723 type: Root.typeId
705724 }
706725 }))
707726 }
708727 }
709728
710- const hypervisor = new Hypervisor(node.dag)
711729 hypervisor.registerContainer(Root)
712730
713- const root = await hypervisor.createInstance(new Message({
731+ let root = await hypervisor.send(creationPort, new Message({
714732 data: {
715733 type: Root.typeId
716734 }
717735 }))
718736
737+ root = await hypervisor.getInstance(root.id)
719738 hypervisor.pin(root)
720739
721740 const [portRef1, portRef2] = root.ports.createChannel()
722741 await root.ports.bind('first', portRef1)
723- await root.createInstance(root.createMessage({
742+ await root.send(creationPort, root.createMessage({
724743 data: {
725744 type: Root.typeId
726745 },
727746 ports: [portRef2]
728747 }))
729748
730749 const message = root.createMessage()
731750 await root.send(portRef1, message)
751+ root.shutdown()
732752 const sr = await hypervisor.createStateRoot()
733753 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
734754
735755 t.end()
@@ -738,12 +758,16 @@
738758 tape('should remove subgraphs', async t => {
739759 const expectedSr = {
740760 '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
741761 }
762+
763+ const hypervisor = new Hypervisor(node.dag)
764+ const creationPort = hypervisor.creationService.getPort()
765+
742766 class Root extends BaseContainer {
743767 onMessage (m) {
744768 const [, portRef2] = this.kernel.ports.createChannel()
745- return this.kernel.createInstance(this.kernel.createMessage({
769+ return this.kernel.send(creationPort, this.kernel.createMessage({
746770 data: {
747771 type: Sub.typeId
748772 },
749773 ports: [portRef2]
@@ -755,9 +779,9 @@
755779 async onInitailize (message) {
756780 await this.kernel.ports.bind('root', message.ports[0])
757781 const [portRef1, portRef2] = this.kernel.ports.createChannel()
758782 await this.kernel.ports.bind('child', portRef1)
759- await this.kernel.createInstance(this.kernel.createMessage({
783+ await this.kernel.send(creationPort, this.kernel.createMessage({
760784 data: {
761785 type: Root.typeId
762786 },
763787 ports: [portRef2]
@@ -768,31 +792,32 @@
768792 }
769793 }
770794
771795 try {
772- const hypervisor = new Hypervisor(node.dag)
773-
774796 hypervisor.registerContainer(Root)
775797 hypervisor.registerContainer(Sub)
776798
777- const root = await hypervisor.createInstance(new Message({
799+ let root = await hypervisor.send(creationPort, new Message({
778800 data: {
779801 type: Root.typeId
780802 }
781803 }))
782804
805+ root = await hypervisor.getInstance(root.id)
806+
783807 hypervisor.pin(root)
784808
785809 const [portRef1, portRef2] = root.ports.createChannel()
786810 await root.ports.bind('first', portRef1)
787- await root.createInstance(root.createMessage({
811+ await root.send(creationPort, root.createMessage({
788812 data: {
789813 type: Root.typeId
790814 },
791815 ports: [portRef2]
792816 }))
793817
794818 await root.send(portRef1, root.createMessage())
819+ root.shutdown()
795820 const sr = await hypervisor.createStateRoot()
796821
797822 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
798823 t.end()
@@ -804,26 +829,30 @@
804829 tape('should not remove connected nodes', async t => {
805830 const expectedSr = {
806831 '/': 'zdpuAr4A3i1t6B7BkLT9C7DoxwvFnNg74gEzyqhpFj7nqVBy6'
807832 }
833+
834+ const hypervisor = new Hypervisor(node.dag)
835+ const creationPort = hypervisor.creationService.getPort()
836+
808837 class Root extends BaseContainer {
809838 async onMessage (m) {
810839 if (m.ports.length) {
811840 const port = this.kernel.ports.get('test1')
812841 await this.kernel.send(port, m)
813842 return this.kernel.ports.unbind('test1')
814843 } else {
815844 const [portRef1, portRef2] = this.kernel.ports.createChannel()
816- await this.kernel.createInstance(this.kernel.createMessage({
845+ await this.kernel.send(creationPort, this.kernel.createMessage({
817846 data: {
818847 type: Sub.typeId
819848 },
820849 ports: [portRef2]
821850 }))
822851 await this.kernel.ports.bind('test1', portRef1)
823852
824853 const [portRef3, portRef4] = this.kernel.ports.createChannel()
825- await this.kernel.createInstance(this.kernel.createMessage({
854+ await this.kernel.send(creationPort, this.kernel.createMessage({
826855 data: {
827856 type: Sub.typeId
828857 },
829858 ports: [portRef4]
@@ -853,42 +882,45 @@
853882 return 299
854883 }
855884 }
856885
857- const hypervisor = new Hypervisor(node.dag)
858-
859886 hypervisor.registerContainer(Root)
860887 hypervisor.registerContainer(Sub)
861888
862- const root = await hypervisor.createInstance(new Message({
889+ let root = await hypervisor.send(creationPort, new Message({
863890 data: {
864891 type: Root.typeId
865892 }
866893 }))
867894
895+ root = await hypervisor.getInstance(root.id)
868896 hypervisor.pin(root)
869897
870898 const [portRef1, portRef2] = root.ports.createChannel()
871899 await root.ports.bind('first', portRef1)
872- await root.createInstance(root.createMessage({
900+ await root.send(creationPort, root.createMessage({
873901 data: {
874902 type: Root.typeId
875903 },
876904 ports: [portRef2]
877905 }))
878906
879907 await root.send(portRef1, root.createMessage())
908+ root.shutdown()
880909 const sr = await hypervisor.createStateRoot()
910+
881911 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
882- // await hypervisor.graph.tree(sr, Infinity)
883-
884912 t.end()
885913 })
886914
887915 tape('should remove multiple subgraphs', async t => {
888916 const expectedSr = {
889917 '/': 'zdpuAzYGmZeZsi5Zer7LXCTm1AsmqpUMJAXZnEeFW2UVDZj2P'
890918 }
919+
920+ const hypervisor = new Hypervisor(node.dag)
921+ const creationPort = hypervisor.creationService.getPort()
922+
891923 class Root extends BaseContainer {
892924 onMessage (m) {
893925 if (m.ports.length) {
894926 const port = this.kernel.ports.get('test1')
@@ -900,16 +932,16 @@
900932 } else {
901933 const [portRef1, portRef2] = this.kernel.ports.createChannel()
902934 const [portRef3, portRef4] = this.kernel.ports.createChannel()
903935 return Promise.all([
904- this.kernel.createInstance(this.kernel.createMessage({
936+ this.kernel.send(creationPort, this.kernel.createMessage({
905937 data: {
906938 type: Sub.typeId
907939 },
908940 ports: [portRef2]
909941 })),
910942 this.kernel.ports.bind('test1', portRef1),
911- this.kernel.createInstance(this.kernel.createMessage({
943+ this.kernel.send(creationPort, this.kernel.createMessage({
912944 data: {
913945 type: Sub.typeId
914946 },
915947 ports: [portRef4]
@@ -941,33 +973,34 @@
941973 }
942974 }
943975
944976 try {
945- const hypervisor = new Hypervisor(node.dag)
946-
947977 hypervisor.registerContainer(Root)
948978 hypervisor.registerContainer(Sub)
949979
950- const root = await hypervisor.createInstance(new Message({
980+ let root = await hypervisor.send(creationPort, new Message({
951981 data: {
952982 type: Root.typeId
953983 }
954984 }))
955985
986+ root = await hypervisor.getInstance(root.id)
956987 hypervisor.pin(root)
957988
958989 const [portRef1, portRef2] = root.ports.createChannel()
959990 await Promise.all([
960991 root.ports.bind('first', portRef1),
961- root.createInstance(root.createMessage({
992+ root.send(creationPort, root.createMessage({
962993 data: {
963994 type: Root.typeId
964995 },
965996 ports: [portRef2]
966997 })),
967998 root.send(portRef1, root.createMessage())
968999 ])
9691000
1001+ root.shutdown()
1002+
9701003 const sr = await hypervisor.createStateRoot()
9711004 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
9721005
9731006 t.end()
@@ -979,8 +1012,10 @@
9791012 tape('response ports', async t => {
9801013 t.plan(2)
9811014 let runs = 0
9821015 const returnValue = 'this is a test'
1016+ const hypervisor = new Hypervisor(node.dag)
1017+ const creationPort = hypervisor.creationService.getPort()
9831018
9841019 class testVMContainer extends BaseContainer {
9851020 onMessage (m) {
9861021 runs++
@@ -991,17 +1026,18 @@
9911026 }
9921027 }
9931028 }
9941029
995- const hypervisor = new Hypervisor(node.dag)
9961030 hypervisor.registerContainer(testVMContainer)
9971031
998- const rootContainer = await hypervisor.createInstance(new Message({
1032+ let rootContainer = await hypervisor.send(creationPort, new Message({
9991033 data: {
10001034 type: testVMContainer.typeId
10011035 }
10021036 }))
10031037
1038+ rootContainer = await hypervisor.getInstance(rootContainer.id)
1039+
10041040 hypervisor.pin(rootContainer)
10051041
10061042 const [portRef1, portRef2] = rootContainer.ports.createChannel()
10071043 const initMessage = rootContainer.createMessage({
@@ -1010,9 +1046,9 @@
10101046 },
10111047 ports: [portRef2]
10121048 })
10131049
1014- rootContainer.createInstance(initMessage)
1050+ rootContainer.send(creationPort, initMessage)
10151051
10161052 await rootContainer.ports.bind('first', portRef1)
10171053 const message = rootContainer.createMessage()
10181054 const rPort = rootContainer.getResponsePort(message)
@@ -1033,10 +1069,11 @@
10331069 }
10341070 }
10351071
10361072 const hypervisor = new Hypervisor(node.dag)
1073+ const creationPort = hypervisor.creationService.getPort()
10371074 hypervisor.registerContainer(testVMContainer)
1038- const instance = await hypervisor.createInstance(new Message({
1075+ const instance = await hypervisor.send(creationPort, new Message({
10391076 data: {
10401077 type: testVMContainer.typeId
10411078 }
10421079 }))
@@ -1050,10 +1087,11 @@
10501087 onMessage () {}
10511088 }
10521089
10531090 const hypervisor = new Hypervisor(node.dag)
1091+ const creationPort = hypervisor.creationService.getPort()
10541092 hypervisor.registerContainer(testVMContainer)
1055- const oldInst = await hypervisor.createInstance(new Message({
1093+ const oldInst = await hypervisor.send(creationPort, new Message({
10561094 data: {
10571095 type: testVMContainer.typeId,
10581096 code: content
10591097 }
@@ -1077,18 +1115,11 @@
10771115 ports: [port2]
10781116 })
10791117 return this.kernel.send(creationPort, message)
10801118 }
1081- onMessage () {
1082-
1083- }
10841119 }
10851120
10861121 class TestVMContainer2 extends BaseContainer {
1087- onMessage () {
1088-
1089- }
1090-
10911122 static get typeId () {
10921123 return 66
10931124 }
10941125 }
@@ -1097,10 +1128,11 @@
10971128 hypervisor.registerContainer(TestVMContainer)
10981129 hypervisor.registerContainer(TestVMContainer2)
10991130
11001131 const port = hypervisor.creationService.getPort()
1132+ const port2 = hypervisor.creationService.getPort()
11011133
1102- const root = await hypervisor.createInstance(new Message({
1134+ const root = await hypervisor.send(port2, new Message({
11031135 data: {
11041136 type: TestVMContainer.typeId
11051137 },
11061138 ports: [port]

Built with git-ssb-web