Commit acc114f061e4e4c2cbede55a72d008b7e46c5cbc
first two test passing
wanderer committed on 5/7/2017, 2:31:49 PMParent: 5f6b460515d272f0c4dcfce10ff08f1efd953318
Files changed
index.js | changed |
kernel.js | changed |
portManager.js | changed |
tests/index.js | changed |
index.js | ||
---|---|---|
@@ -13,12 +13,12 @@ | ||
13 | 13 | let id = await this.generateID(port) |
14 | 14 | let kernel = this._vmInstances.get(id) |
15 | 15 | if (!kernel) { |
16 | 16 | // load the container from the state |
17 | - await this.graph.tree(port, 2) | |
18 | - const parentID = await this.generateID(port.id['/'].parent) | |
17 | + await this.graph.tree(port, 3) | |
18 | + const parentID = await this.generateID({id: port.id['/'].parent}) | |
19 | 19 | const parentKernel = await this._vmInstances.get(parentID) |
20 | - const parentPort = parentKernel.entryPort || null | |
20 | + const parentPort = parentKernel.entryPort | |
21 | 21 | |
22 | 22 | kernel = await this.createInstanceFromPort(port, parentPort) |
23 | 23 | // don't delete the root contracts |
24 | 24 | if (id) { |
@@ -36,9 +36,9 @@ | ||
36 | 36 | let kernel = await this.getInstance(port) |
37 | 37 | return kernel.wait(threshold, fromPort) |
38 | 38 | } |
39 | 39 | |
40 | - async createInstance (type, state, entryPort, parentPort) { | |
40 | + async createInstance (type, state, entryPort = null, parentPort) { | |
41 | 41 | const VM = this._VMs[type] |
42 | 42 | if (!state) { |
43 | 43 | state = VM.createState() |
44 | 44 | } |
kernel.js | ||
---|---|---|
@@ -53,9 +53,8 @@ | ||
53 | 53 | this.emit(vmState, message) |
54 | 54 | } |
55 | 55 | |
56 | 56 | async _runNextMessage () { |
57 | - // console.log('next message', this.ticks, this.entryPort) | |
58 | 57 | const message = await this.ports.getNextMessage() |
59 | 58 | // if the vm is paused and it gets a message; save that message for use when the VM is resumed |
60 | 59 | if (message && this.vmState === 'paused') { |
61 | 60 | this.ports._portMap(message._fromPort).unshfit(message) |
@@ -112,9 +111,8 @@ | ||
112 | 111 | |
113 | 112 | // returns a promise that resolves once the kernel hits the threshould tick |
114 | 113 | // count |
115 | 114 | async wait (threshold, fromPort) { |
116 | - console.log('wait', threshold, fromPort, this.ticks, this.vmState, this.entryPort) | |
117 | 115 | if (threshold <= this.ticks) { |
118 | 116 | return this.ticks |
119 | 117 | } else if (this.vmState === 'idle') { |
120 | 118 | return this.ports.wait(threshold, fromPort) |
@@ -129,9 +127,8 @@ | ||
129 | 127 | } |
130 | 128 | } |
131 | 129 | |
132 | 130 | incrementTicks (count) { |
133 | - console.log('update ticks') | |
134 | 131 | this.ticks += count |
135 | 132 | while (!this._waitingQueue.isEmpty()) { |
136 | 133 | const waiter = this._waitingQueue.peek() |
137 | 134 | if (waiter.threshold > this.ticks) { |
@@ -182,12 +179,8 @@ | ||
182 | 179 | |
183 | 180 | const receiverEntryPort = portRef === this.entryPort ? this.parentPort : portRef |
184 | 181 | const vm = await this.hypervisor.getInstance(receiverEntryPort) |
185 | 182 | vm.queue(message) |
186 | - if (this.vmState !== 'running') { | |
187 | - this._updateVmState('running') | |
188 | - this._runNextMessage() | |
189 | - } | |
190 | 183 | } |
191 | 184 | } |
192 | 185 | |
193 | 186 | function clearObject (myObject) { |
portManager.js | ||
---|---|---|
@@ -37,8 +37,9 @@ | ||
37 | 37 | }) |
38 | 38 | |
39 | 39 | // create the parent port |
40 | 40 | await Promise.all(ports) |
41 | + // skip the root, since it doesn't have a parent | |
41 | 42 | if (this.parentPort !== undefined) { |
42 | 43 | const id = await this.hypervisor.generateID(this.parentPort) |
43 | 44 | this._portMap.set(id, new Port(ENTRY)) |
44 | 45 | } |
@@ -71,14 +72,14 @@ | ||
71 | 72 | // waits till all ports have reached a threshold tick count |
72 | 73 | async wait (threshold, fromPort) { |
73 | 74 | // find the ports that have a smaller tick count then the threshold tick count |
74 | 75 | const unkownPorts = [...this._portMap].filter(([id, port]) => { |
76 | + const portRef = this.getRef(port.name) | |
75 | 77 | return (port.hasSent || port.name === ENTRY) && |
76 | 78 | port.ticks < threshold && |
77 | - fromPort !== port | |
79 | + fromPort !== portRef | |
78 | 80 | }) |
79 | 81 | |
80 | - // console.log(unkownPorts, this.entryPort) | |
81 | 82 | const promises = unkownPorts.map(async ([id, port]) => { |
82 | 83 | const portObj = port.name === ENTRY ? this.parentPort : this.ports[port.name] |
83 | 84 | // update the port's tick count |
84 | 85 | port.ticks = await this.hypervisor.wait(portObj, threshold, this.entryPort) |
tests/index.js | ||
---|---|---|
@@ -51,9 +51,9 @@ | ||
51 | 51 | } |
52 | 52 | t.end() |
53 | 53 | }) |
54 | 54 | |
55 | - tape.only('one child contract', async t => { | |
55 | + tape('one child contract', async t => { | |
56 | 56 | let message = new Message() |
57 | 57 | const expectedState = { '/': 'zdpuAqtY43BMaTCB5nTt7kooeKAWibqGs44Uwy9jJQHjTnHRK' } |
58 | 58 | let hasResolved = false |
59 | 59 | |
@@ -119,9 +119,9 @@ | ||
119 | 119 | |
120 | 120 | t.end() |
121 | 121 | }) |
122 | 122 | |
123 | - tape('should wait on parent', async t => { | |
123 | + tape.skip('should wait on parent', async t => { | |
124 | 124 | let r |
125 | 125 | const lock = new Promise((resolve, reject) => { |
126 | 126 | r = resolve |
127 | 127 | }) |
Built with git-ssb-web