git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 4d55c78be4ffb7631d68b6f18e18e09d8bd4b510

fix port binding error

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 8/11/2017, 2:18:58 PM
Parent: d0da8197e290a0f7d27a4b08cbc89d00cf1ca258

Files changed

index.jschanged
portManager.jschanged
scheduler.jschanged
tests/index.jschanged
index.jsView
@@ -177,9 +177,8 @@
177177 for (const id of unlinked) {
178178 await this.tree.delete(id)
179179 }
180180
181- // console.log(JSON.stringify(this.state, null, 2))
182181 return this.graph.flush(this.state)
183182 }
184183
185184 /**
portManager.jsView
@@ -54,18 +54,17 @@
5454 throw new Error('cannot bind port to a name that is alread bound')
5555 } else {
5656 this._unboundPorts.delete(port)
5757
58- port.messages.forEach(message => {
59- message._fromPort = port
60- message.fromName = name
61- })
62-
6358 // save the port instance
6459 this.ports[name] = port
6560
6661 // update the dest port
6762 const destPort = await this.hypervisor.getDestPort(port)
63 + port.messages.forEach(message => {
64 + message._fromPort = port
65 + message.fromName = name
66 + })
6867 destPort.destName = name
6968 destPort.destId = this.id
7069 delete destPort.destPort
7170 }
@@ -93,12 +92,12 @@
9392 /**
9493 * delete an port given the name it is bound to
9594 * @param {string} name
9695 */
97- delete (name) {
96 + async delete (name) {
9897 const port = this.ports[name]
98 + await this.kernel.send(port, new DeleteMessage())
9999 this._delete(name)
100- return this.kernel.send(port, new DeleteMessage())
101100 }
102101
103102 _delete (name) {
104103 this.hypervisor.addNodeToCheck(this.id)
@@ -199,9 +198,9 @@
199198 */
200199 async getNextMessage () {
201200 let message = this._peekNextMessage()
202201 let saturated = this._isSaturated()
203- let oldestTime = this.hypervisor.scheduler.oldest()
202 + let oldestTime = this.hypervisor.scheduler.leastNumberOfTicks()
204203
205204 while (!saturated && // end if there are messages on all the ports
206205 // end if we have a message older then slowest containers
207206 !((message && oldestTime >= message._fromTicks) ||
@@ -221,9 +220,9 @@
221220 message = this._peekNextMessage()
222221 })
223222 ])
224223
225- oldestTime = this.hypervisor.scheduler.oldest()
224 + oldestTime = this.hypervisor.scheduler.leastNumberOfTicks()
226225 }
227226
228227 return message
229228 }
scheduler.jsView
@@ -96,9 +96,9 @@
9696 /**
9797 * returns the oldest container's ticks
9898 * @return {integer}
9999 */
100- oldest () {
100 + leastNumberOfTicks () {
101101 const nextValue = this.instances.values().next().value
102102 return nextValue ? nextValue.ticks : 0
103103 }
104104
@@ -110,12 +110,12 @@
110110 this._waits.forEach(wait => wait.resolve())
111111 this._waits = []
112112 } else {
113113 // find the old container and see if to can resolve any of the waits
114- const oldest = this.oldest()
114 + const least = this.leastNumberOfTicks()
115115 for (const index in this._waits) {
116116 const wait = this._waits[index]
117- if (wait.ticks <= oldest) {
117 + if (wait.ticks <= least) {
118118 wait.resolve()
119119 this._running.add(wait.id)
120120 } else {
121121 this._waits.splice(0, index)
tests/index.jsView
@@ -55,9 +55,9 @@
5555 rootContainer.send(portRef1, message)
5656
5757 const stateRoot = await hypervisor.createStateRoot(Infinity)
5858 t.deepEquals(stateRoot, expectedState, 'expected root!')
59- t.equals(hypervisor.scheduler.oldest(), 0)
59 + t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0)
6060 } catch (e) {
6161 console.log(e)
6262 }
6363 })
@@ -307,8 +307,9 @@
307307 t.plan(3)
308308 let runs = 0
309309
310310 class Root extends BaseContainer {
311 + onIdle () {}
311312 async onMessage (m) {
312313 if (!runs) {
313314 runs++
314315 const [portRef1, portRef2] = this.kernel.ports.createChannel()
@@ -334,12 +335,12 @@
334335 runs++
335336 t.equals(m.data, 'first', 'should recive the first message')
336337 } else if (runs === 2) {
337338 runs++
338- t.equals(m.data, 'second', 'should recive the first message')
339 + t.equals(m.data, 'second', 'should recive the second message')
339340 } else if (runs === 3) {
340341 runs++
341- t.equals(m.data, 'third', 'should recived the second message')
342 + t.equals(m.data, 'third', 'should recived the third message')
342343 }
343344 }
344345 static get typeId () {
345346 return 299
@@ -389,9 +390,9 @@
389390 hypervisor.registerContainer(First)
390391 hypervisor.registerContainer(Second)
391392 hypervisor.registerContainer(Waiter)
392393
393- const root = await hypervisor.createInstance(Root.typeId)
394 + let root = await hypervisor.createInstance(Root.typeId)
394395 const [portRef1, portRef2] = root.ports.createChannel()
395396 const [portRef3, portRef4] = root.ports.createChannel()
396397
397398 const message = root.createMessage()
@@ -406,11 +407,12 @@
406407 ports: [portRef4]
407408 }))
408409 ])
409410
411 + // root = await hypervisor.getInstance(root.id)
410412 root.incrementTicks(100)
411413 await root.send(portRef1, root.createMessage({data: 'testss'}))
412- hypervisor.scheduler.done(root.id)
414 + root.shutdown()
413415 } catch (e) {
414416 console.log(e)
415417 }
416418 })
@@ -461,12 +463,14 @@
461463 hypervisor.registerContainer(First)
462464
463465 const root = await hypervisor.createInstance(Root.typeId)
464466 const [portRef1, portRef2] = root.ports.createChannel()
465- await root.ports.bind('first', portRef1)
466- await root.createInstance(Root.typeId, root.createMessage({
467- ports: [portRef2]
468- }))
467 + await Promise.all([
468 + root.ports.bind('first', portRef1),
469 + root.createInstance(Root.typeId, root.createMessage({
470 + ports: [portRef2]
471 + }))
472 + ])
469473
470474 const message = root.createMessage()
471475 await root.send(portRef1, message)
472476 await hypervisor.createStateRoot()

Built with git-ssb-web