Commit eacc6aefd1d880bdcfc1c451260d67651c742adb
fixred reloading ports
wanderer committed on 4/28/2017, 5:55:19 PMParent: ca80f013bf0ad297f4a0e0ab0c5a57b5c3b84034
Files changed
kernel.js | changed |
portManager.js | changed |
tests/index.js | changed |
kernel.js | ||
---|---|---|
@@ -106,25 +106,25 @@ | ||
106 | 106 | const nonce = new BN(this.state.nonce) |
107 | 107 | nonce.iaddn(1) |
108 | 108 | this.state.nonce = nonce.toArray() |
109 | 109 | |
110 | - let port = this._opts.hypervisor.createPort(type, { | |
110 | + let portRef = this._opts.hypervisor.createPort(type, { | |
111 | 111 | nonce: this.state.nonce, |
112 | 112 | parent: this._opts.parentPort.id |
113 | 113 | }) |
114 | - await manager.set(name, port) | |
115 | - return port | |
114 | + await manager.set(name, portRef) | |
115 | + return portRef | |
116 | 116 | } |
117 | 117 | |
118 | 118 | getPort (manager, name) { |
119 | - return manager.get(name) | |
119 | + return manager.getRef(name) | |
120 | 120 | } |
121 | 121 | |
122 | - async send (port, message) { | |
122 | + async send (portRef, message) { | |
123 | 123 | message._ticks = this.ticks |
124 | - const portObject = await this.ports.get(port) | |
125 | - portObject.hasSent = true | |
126 | - return this._opts.hypervisor.send(port, message) | |
124 | + const portInstance = await this.ports.get(portRef) | |
125 | + portInstance.hasSent = true | |
126 | + return this._opts.hypervisor.send(portRef, message) | |
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
130 | 130 | function clearObject (myObject) { |
portManager.js | ||
---|---|---|
@@ -64,8 +64,12 @@ | ||
64 | 64 | const id = await this.hypervisor.generateID(port) |
65 | 65 | return this._portMap.get(id) |
66 | 66 | } |
67 | 67 | |
68 | + getRef (key) { | |
69 | + return this.ports[key] | |
70 | + } | |
71 | + | |
68 | 72 | // waits till all ports have reached a threshold tick count |
69 | 73 | async wait (threshold) { |
70 | 74 | // find the ports that have a smaller tick count then the threshold tick count |
71 | 75 | const unkownPorts = [...this._portMap].filter(([id, port]) => { |
tests/index.js | ||
---|---|---|
@@ -81,28 +81,24 @@ | ||
81 | 81 | await hypervisor.createStateRoot(port, Infinity) |
82 | 82 | t.true(hasResolved, 'should resolve before generating the state root') |
83 | 83 | t.deepEquals(port, expectedState, 'expected state') |
84 | 84 | |
85 | + // test reviving the state | |
85 | 86 | class testVMContainer3 extends BaseContainer { |
86 | 87 | async run (m) { |
87 | - console.log('here!!') | |
88 | - const port = await this.kernel.getPort(this.kernel.ports, 'child') | |
88 | + const port = this.kernel.getPort(this.kernel.ports, 'child') | |
89 | 89 | await this.kernel.send(port, m) |
90 | 90 | this.kernel.incrementTicks(1) |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | hypervisor.addVM('test', testVMContainer3) |
95 | 95 | |
96 | 96 | // revive ports |
97 | - try { | |
98 | - message = new Message() | |
99 | - await hypervisor.graph.tree(expectedState, 1) | |
100 | - console.log(expectedState) | |
101 | - await hypervisor.send(expectedState['/'], message) | |
102 | - } catch (e) { | |
103 | - console.log(e) | |
104 | - } | |
97 | + message = new Message() | |
98 | + await hypervisor.graph.tree(expectedState, 1) | |
99 | + await hypervisor.send(expectedState['/'], message) | |
100 | + await hypervisor.createStateRoot(expectedState['/'], Infinity) | |
105 | 101 | |
106 | 102 | t.end() |
107 | 103 | node.stop(() => { |
108 | 104 | process.exit() |
Built with git-ssb-web