tests/index.jsView |
---|
10 | 10 | class BaseContainer { |
11 | 11 | constructor (exInterface) { |
12 | 12 | this.exInterface = exInterface |
13 | 13 | } |
| 14 | + |
| 15 | + initailize (message) { |
| 16 | + |
| 17 | + const port = message.ports[0] |
| 18 | + if (port) { |
| 19 | + this.exInterface.ports.bind('root', port) |
| 20 | + } |
| 21 | + } |
14 | 22 | } |
15 | 23 | |
16 | 24 | node.on('ready', () => { |
17 | 25 | tape('basic', async t => { |
21 | 29 | '/': 'zdpuAyGKaZ3nbBQdgESbEgVYr81TcAFB6LE2MQQPWLZaYxuF3' |
22 | 30 | } |
23 | 31 | |
24 | 32 | class testVMContainer extends BaseContainer { |
25 | | - initailize (message) { |
26 | | - const port = message.ports[0] |
27 | | - if (port) { |
28 | | - this.exInterface.ports.bind('root', port) |
29 | | - } |
30 | | - } |
31 | 33 | run (m) { |
32 | 34 | t.true(m === message, 'should recive a message') |
33 | 35 | } |
34 | 36 | } |
49 | 51 | tape('one child contract', async t => { |
50 | 52 | t.plan(4) |
51 | 53 | let message |
52 | 54 | const expectedState = { |
53 | | - '/': 'zdpuAofSzrBqwYs6z1r28fMeb8z5oSKF6CcWA6m22RqazgoTB' |
| 55 | + '/': 'zdpuAtVcH6MUnvt2RXnLsDXyLB3CBSQ7aydfh2ogSKGCejJCQ' |
54 | 56 | } |
55 | 57 | let hasResolved = false |
56 | 58 | |
57 | 59 | class testVMContainer2 extends BaseContainer { |
58 | | - async initailize (m) { |
59 | | - console.log('init') |
60 | | - await this.exInterface.ports.bind('root', m.ports[0]) |
61 | | - } |
62 | 60 | run (m) { |
63 | | - console.log('here') |
64 | 61 | t.true(m === message, 'should recive a message') |
65 | 62 | return new Promise((resolve, reject) => { |
66 | 63 | setTimeout(() => { |
67 | 64 | this.exInterface.incrementTicks(1) |
72 | 69 | } |
73 | 70 | } |
74 | 71 | |
75 | 72 | class testVMContainer extends BaseContainer { |
76 | | - async initailize (m) { |
77 | | - const port = m.ports[0] |
78 | | - if (port) { |
79 | | - await this.exInterface.ports.bind('root', port) |
80 | | - } |
81 | | - } |
82 | | - async run (m) { |
83 | | - const port = await this.exInterface.ports.create('test2') |
84 | | - await this.exInterface.ports.bind('child', port) |
85 | | - await this.exInterface.send(port, m) |
| 73 | + run (m) { |
| 74 | + const port = this.exInterface.ports.create('test2') |
| 75 | + this.exInterface.ports.bind('child', port) |
| 76 | + this.exInterface.send(port, m) |
86 | 77 | this.exInterface.incrementTicks(1) |
87 | | - console.log('run') |
88 | 78 | } |
89 | 79 | } |
90 | 80 | |
91 | | - try { |
92 | | - const hypervisor = new Hypervisor(node.dag) |
93 | | - hypervisor.registerContainer('test', testVMContainer) |
94 | | - hypervisor.registerContainer('test2', testVMContainer2) |
| 81 | + const hypervisor = new Hypervisor(node.dag) |
| 82 | + hypervisor.registerContainer('test', testVMContainer) |
| 83 | + hypervisor.registerContainer('test2', testVMContainer2) |
95 | 84 | |
96 | | - let root = await hypervisor.createInstance('test') |
97 | | - let port = root.ports.create('test') |
| 85 | + let root = await hypervisor.createInstance('test') |
| 86 | + const rootId = root.id |
| 87 | + let port = root.ports.create('test') |
98 | 88 | |
99 | | - await root.ports.bind('first', port) |
100 | | - message = root.createMessage() |
| 89 | + root.ports.bind('first', port) |
| 90 | + message = root.createMessage() |
101 | 91 | |
102 | | - await root.send(port, message) |
103 | | - console.log('state', hypervisor._state) |
104 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
105 | | - |
106 | | - |
107 | | - } catch (e) { |
108 | | - console.log(e) |
| 92 | + root.send(port, message) |
| 93 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 94 | + t.true(hasResolved, 'should resolve before generating the state root') |
| 95 | + t.deepEquals(stateRoot, expectedState, 'expected state') |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + class testVMContainer3 extends BaseContainer { |
| 100 | + run (m) { |
| 101 | + const port = this.exInterface.ports.get('child') |
| 102 | + this.exInterface.send(port, m) |
| 103 | + this.exInterface.incrementTicks(1) |
| 104 | + } |
109 | 105 | } |
110 | 106 | |
111 | | - |
112 | | - |
113 | | - |
114 | | - |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
| 107 | + hypervisor.registerContainer('test', testVMContainer3) |
| 108 | + root = await hypervisor.getInstance(rootId) |
| 109 | + port = root.ports.get('first') |
| 110 | + root.send(port, message) |
125 | 111 | }) |
126 | 112 | |
127 | 113 | tape.skip('ping pong', async t => { |
128 | 114 | class Ping extends BaseContainer { |
129 | 115 | async run (m) { |
130 | | - let port = this.kernel.ports.get('child') |
| 116 | + let port = this.exInterface.ports.get('child') |
131 | 117 | if (!port) { |
132 | | - port = this.kernel.ports.create('pong') |
133 | | - this.kernel.ports.bind(port, 'child') |
| 118 | + port = this.exInterface.ports.create('pong') |
| 119 | + this.exInterface.ports.bind(port, 'child') |
134 | 120 | } |
135 | 121 | |
136 | | - if (this.kernel.ticks < 100) { |
137 | | - this.kernel.incrementTicks(1) |
138 | | - return this.kernel.send(port, this.kernel.createMessage()) |
| 122 | + if (this.exInterface.ticks < 100) { |
| 123 | + this.exInterface.incrementTicks(1) |
| 124 | + return this.exInterface.send(port, this.exInterface.createMessage()) |
139 | 125 | } |
140 | 126 | } |
141 | 127 | } |
142 | 128 | |
143 | 129 | class Pong extends BaseContainer { |
144 | 130 | run (m) { |
145 | 131 | const port = m.fromPort |
146 | | - this.kernel.incrementTicks(2) |
147 | | - return this.kernel.send(port, this.kernel.createMessage()) |
| 132 | + this.exInterface.incrementTicks(2) |
| 133 | + return this.exInterface.send(port, this.exInterface.createMessage()) |
148 | 134 | } |
149 | 135 | } |
150 | 136 | |
151 | 137 | const hypervisor = new Hypervisor(node.dag) |
161 | 147 | |
162 | 148 | t.end() |
163 | 149 | }) |
164 | 150 | |
165 | | - tape.skip('queing multiple messages', async t => { |
166 | | - t.plan(2) |
167 | | - let runs = 0 |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
168 | 157 | |
169 | | - class Root extends BaseContainer { |
170 | | - async run (m) { |
171 | | - const one = this.kernel.ports.create('child') |
172 | | - const two = this.kernel.ports.create('child') |
173 | | - const three = this.kernel.ports.create('child') |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
174 | 163 | |
175 | | - this.kernel.ports.bind(one, 'one') |
176 | | - this.kernel.ports.bind(two, 'two') |
177 | | - this.kernel.ports.bind(three, 'three') |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
178 | 170 | |
179 | | - await Promise.all([ |
180 | | - this.kernel.send(one, this.kernel.createMessage()), |
181 | | - this.kernel.send(two, this.kernel.createMessage()), |
182 | | - this.kernel.send(three, this.kernel.createMessage()) |
183 | | - ]) |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
184 | 179 | |
185 | | - return new Promise((resolve, reject) => { |
186 | | - setTimeout(() => { |
187 | | - this.kernel.incrementTicks(6) |
188 | | - resolve() |
189 | | - }, 200) |
190 | | - }) |
191 | | - } |
192 | | - } |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
193 | 186 | |
194 | | - class Child extends BaseContainer { |
195 | | - run (m) { |
196 | | - runs++ |
197 | | - this.kernel.incrementTicks(2) |
198 | | - } |
199 | | - } |
| 187 | + |
200 | 188 | |
201 | | - const hypervisor = new Hypervisor(node.dag) |
| 189 | + |
| 190 | + |
202 | 191 | |
203 | | - hypervisor.registerContainer('root', Root) |
204 | | - hypervisor.registerContainer('child', Child) |
| 192 | + |
| 193 | + |
| 194 | + |
205 | 195 | |
206 | | - const root = await hypervisor.createInstance('root') |
207 | | - const port = root.ports.create('root') |
208 | | - root.ports.bind(port, 'first') |
| 196 | + |
| 197 | + |
209 | 198 | |
210 | | - await root.send(port, root.createMessage()) |
211 | | - await root.wait(Infinity) |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
212 | 203 | |
213 | | - t.equals(runs, 3, 'the number of run should be 3') |
214 | | - const nonce = await hypervisor.graph.get(root.state, 'ports/first/link/nonce/0') |
215 | | - t.equals(nonce, 3, 'should have the correct nonce') |
216 | | - |
217 | | - await hypervisor.graph.tree(root.state, Infinity) |
218 | | - }) |
219 | | - |
220 | | - tape.skip('traps', async t => { |
| 204 | + tape('traps', async t => { |
221 | 205 | t.plan(1) |
222 | 206 | class Root extends BaseContainer { |
223 | 207 | async run (m) { |
224 | | - const one = this.kernel.ports.create('child') |
225 | | - const two = this.kernel.ports.create('child') |
226 | | - const three = this.kernel.ports.create('child') |
| 208 | + const one = this.exInterface.ports.create('root') |
| 209 | + const two = this.exInterface.ports.create('root') |
| 210 | + const three = this.exInterface.ports.create('root') |
227 | 211 | |
228 | | - this.kernel.ports.bind(one, 'one') |
229 | | - this.kernel.ports.bind(two, 'two') |
230 | | - this.kernel.ports.bind(three, 'three') |
| 212 | + this.exInterface.ports.bind('one', one) |
| 213 | + this.exInterface.ports.bind('two', two) |
| 214 | + this.exInterface.ports.bind('three', three) |
231 | 215 | |
232 | 216 | throw new Error('it is a trap!!!') |
233 | 217 | } |
234 | 218 | } |
236 | 220 | const hypervisor = new Hypervisor(node.dag) |
237 | 221 | |
238 | 222 | hypervisor.registerContainer('root', Root) |
239 | 223 | const root = await hypervisor.createInstance('root') |
240 | | - await root.run() |
| 224 | + await root.run(root.createMessage()) |
| 225 | + |
| 226 | + const stateRoot = await hypervisor.createStateRoot() |
241 | 227 | |
242 | | - t.deepEquals(root.state, { |
243 | | - '/': { |
244 | | - nonce: [0], |
245 | | - ports: {} |
246 | | - } |
| 228 | + t.deepEquals(stateRoot, { |
| 229 | + '/': 'zdpuAwrMmQXqFusve7zcRYxVUuji4NVzZR5GyjwyStsjteCoW' |
247 | 230 | }, 'should revert the state') |
248 | 231 | }) |
249 | 232 | |
250 | | - tape.skip('message should arrive in the correct oder if sent in order', async t => { |
| 233 | + tape('message should arrive in the correct oder if sent in order', async t => { |
251 | 234 | t.plan(2) |
| 235 | + let runs = 0 |
252 | 236 | |
253 | 237 | class Root extends BaseContainer { |
254 | | - async run (m) { |
255 | | - if (!this.runs) { |
256 | | - this.runs = 1 |
257 | | - const one = this.kernel.ports.create('first') |
258 | | - const two = this.kernel.ports.create('second') |
| 238 | + run (m) { |
| 239 | + if (!runs) { |
| 240 | + runs++ |
| 241 | + const one = this.exInterface.ports.create('first') |
| 242 | + const two = this.exInterface.ports.create('second') |
259 | 243 | |
260 | | - this.kernel.ports.bind(one, 'one') |
261 | | - this.kernel.ports.bind(two, 'two') |
| 244 | + this.exInterface.ports.bind('one', one) |
| 245 | + this.exInterface.ports.bind('two', two) |
262 | 246 | |
263 | | - await Promise.all([ |
264 | | - this.kernel.send(one, this.kernel.createMessage()), |
265 | | - this.kernel.send(two, this.kernel.createMessage()) |
266 | | - ]) |
| 247 | + this.exInterface.send(one, this.exInterface.createMessage()) |
| 248 | + this.exInterface.send(two, this.exInterface.createMessage()) |
267 | 249 | |
268 | | - this.kernel.incrementTicks(6) |
269 | | - } else if (this.runs === 1) { |
270 | | - this.runs++ |
| 250 | + this.exInterface.incrementTicks(6) |
| 251 | + } else if (runs === 1) { |
| 252 | + runs++ |
271 | 253 | t.equals(m.data, 'first', 'should recive the first message') |
272 | | - } else if (this.runs === 2) { |
| 254 | + } else if (runs === 2) { |
273 | 255 | t.equals(m.data, 'second', 'should recived the second message') |
274 | 256 | } |
275 | 257 | } |
276 | 258 | } |
277 | 259 | |
278 | 260 | class First extends BaseContainer { |
279 | | - async run (m) { |
280 | | - this.kernel.incrementTicks(1) |
281 | | - await this.kernel.send(m.fromPort, this.kernel.createMessage({data: 'first'})) |
| 261 | + run (m) { |
| 262 | + this.exInterface.incrementTicks(1) |
| 263 | + this.exInterface.send(m.fromPort, this.exInterface.createMessage({data: 'first'})) |
282 | 264 | } |
283 | 265 | } |
284 | 266 | |
285 | 267 | class Second extends BaseContainer { |
286 | | - async run (m) { |
287 | | - this.kernel.incrementTicks(2) |
288 | | - await this.kernel.send(m.fromPort, this.kernel.createMessage({data: 'second'})) |
| 268 | + run (m) { |
| 269 | + this.exInterface.incrementTicks(2) |
| 270 | + this.exInterface.send(m.fromPort, this.exInterface.createMessage({data: 'second'})) |
289 | 271 | } |
290 | 272 | } |
291 | 273 | |
292 | 274 | const hypervisor = new Hypervisor(node.dag) |
296 | 278 | hypervisor.registerContainer('second', Second) |
297 | 279 | |
298 | 280 | const root = await hypervisor.createInstance('root') |
299 | 281 | const port = root.ports.create('root') |
300 | | - root.ports.bind(port, 'first') |
| 282 | + root.ports.bind('first', port) |
301 | 283 | |
302 | 284 | root.send(port, root.createMessage()) |
303 | 285 | }) |
304 | 286 | |
305 | | - tape.skip('message should arrive in the correct order, even if sent out of order', async t => { |
306 | | - t.plan(2) |
| 287 | + |
| 288 | + |
307 | 289 | |
308 | | - class Root extends BaseContainer { |
309 | | - run (m) { |
310 | | - if (!this.runs) { |
311 | | - this.runs = 1 |
312 | | - const one = this.kernel.ports.create('first') |
313 | | - const two = this.kernel.ports.create('second') |
| 290 | + |
314 | 291 | |
315 | | - this.kernel.ports.bind(one, 'one') |
316 | | - this.kernel.ports.bind(two, 'two') |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
317 | 298 | |
318 | | - return Promise.all([ |
319 | | - this.kernel.send(one, this.kernel.createMessage()), |
320 | | - this.kernel.send(two, this.kernel.createMessage()) |
321 | | - ]) |
322 | | - } else if (this.runs === 1) { |
323 | | - this.runs++ |
324 | | - t.equals(m.data, 'second', 'should recive the first message') |
325 | | - } else if (this.runs === 2) { |
326 | | - t.equals(m.data, 'first', 'should recived the second message') |
327 | | - } |
328 | | - } |
329 | | - } |
| 299 | + |
| 300 | + |
330 | 301 | |
331 | | - class First extends BaseContainer { |
332 | | - run (m) { |
333 | | - this.kernel.incrementTicks(2) |
334 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({data: 'first'})) |
335 | | - } |
336 | | - } |
| 302 | + |
| 303 | + |
337 | 304 | |
338 | | - class Second extends BaseContainer { |
339 | | - run (m) { |
340 | | - this.kernel.incrementTicks(1) |
341 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({data: 'second'})) |
342 | | - } |
343 | | - } |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + |
| 312 | + |
| 313 | + |
344 | 314 | |
345 | | - const hypervisor = new Hypervisor(node.dag) |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | + |
346 | 321 | |
347 | | - hypervisor.registerContainer('root', Root) |
348 | | - hypervisor.registerContainer('first', First) |
349 | | - hypervisor.registerContainer('second', Second) |
| 322 | + |
| 323 | + |
| 324 | + |
| 325 | + |
| 326 | + |
| 327 | + |
350 | 328 | |
351 | | - const root = await hypervisor.createInstance('root') |
352 | | - const port = root.ports.create('root') |
353 | | - root.ports.bind(port, 'first') |
| 329 | + |
354 | 330 | |
355 | | - root.send(port, root.createMessage()) |
356 | | - }) |
| 331 | + |
| 332 | + |
| 333 | + |
357 | 334 | |
358 | | - tape.skip('message should arrive in the correct order, even in a tie of ticks', async t => { |
359 | | - t.plan(2) |
| 335 | + |
| 336 | + |
| 337 | + |
360 | 338 | |
361 | | - class Root extends BaseContainer { |
362 | | - async run (m) { |
363 | | - if (!this.runs) { |
364 | | - this.runs = 1 |
365 | | - const one = this.kernel.ports.create('first') |
366 | | - const two = this.kernel.ports.create('second') |
| 339 | + |
| 340 | + |
367 | 341 | |
368 | | - this.kernel.ports.bind(one, 'one') |
369 | | - this.kernel.ports.bind(two, 'two') |
| 342 | + |
| 343 | + |
| 344 | + |
370 | 345 | |
371 | | - await Promise.all([ |
372 | | - this.kernel.send(one, this.kernel.createMessage()), |
373 | | - this.kernel.send(two, this.kernel.createMessage()) |
374 | | - ]) |
| 346 | + |
| 347 | + |
| 348 | + |
| 349 | + |
| 350 | + |
| 351 | + |
375 | 352 | |
376 | | - this.kernel.incrementTicks(6) |
377 | | - } else if (this.runs === 1) { |
378 | | - this.runs++ |
379 | | - t.equals(m.data, 'first', 'should recived the second message') |
380 | | - } else if (this.runs === 2) { |
381 | | - t.equals(m.data, 'second', 'should recive the first message') |
382 | | - } |
383 | | - } |
384 | | - } |
| 353 | + |
| 354 | + |
385 | 355 | |
386 | | - class First extends BaseContainer { |
387 | | - run (m) { |
388 | | - this.kernel.incrementTicks(2) |
389 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
390 | | - data: 'first' |
391 | | - })) |
392 | | - } |
393 | | - } |
| 356 | + |
| 357 | + |
394 | 358 | |
395 | | - class Second extends BaseContainer { |
396 | | - run (m) { |
397 | | - this.kernel.incrementTicks(2) |
398 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
399 | | - data: 'second' |
400 | | - })) |
401 | | - } |
402 | | - } |
| 359 | + |
| 360 | + |
| 361 | + |
| 362 | + |
| 363 | + |
| 364 | + |
| 365 | + |
| 366 | + |
| 367 | + |
403 | 368 | |
404 | | - const hypervisor = new Hypervisor(node.dag) |
| 369 | + |
| 370 | + |
| 371 | + |
| 372 | + |
| 373 | + |
| 374 | + |
| 375 | + |
| 376 | + |
405 | 377 | |
406 | | - hypervisor.registerContainer('root', Root) |
407 | | - hypervisor.registerContainer('first', First) |
408 | | - hypervisor.registerContainer('second', Second) |
| 378 | + |
| 379 | + |
| 380 | + |
| 381 | + |
| 382 | + |
| 383 | + |
| 384 | + |
| 385 | + |
409 | 386 | |
410 | | - const root = await hypervisor.createInstance('root') |
411 | | - const port = await root.ports.create('root') |
412 | | - root.ports.bind(port, 'first') |
413 | | - root.send(port, root.createMessage()) |
414 | | - }) |
| 387 | + |
415 | 388 | |
416 | | - tape.skip('message should arrive in the correct order, even in a tie of ticks', async t => { |
| 389 | + |
| 390 | + |
| 391 | + |
| 392 | + |
| 393 | + |
| 394 | + |
| 395 | + |
| 396 | + |
| 397 | + |
| 398 | + |
| 399 | + tape('message should arrive in the correct order, even in a tie of ticks', async t => { |
417 | 400 | t.plan(2) |
418 | 401 | |
| 402 | + let runs = 0 |
| 403 | + |
419 | 404 | class Root extends BaseContainer { |
420 | 405 | run (m) { |
421 | | - if (!this.runs) { |
422 | | - this.runs = 1 |
423 | | - const two = this.kernel.ports.create('second') |
424 | | - const one = this.kernel.ports.create('first') |
| 406 | + if (!runs) { |
| 407 | + runs++ |
| 408 | + const one = this.exInterface.ports.create('first') |
| 409 | + const two = this.exInterface.ports.create('second') |
425 | 410 | |
426 | | - this.kernel.ports.bind(two, 'two') |
427 | | - this.kernel.ports.bind(one, 'one') |
| 411 | + this.exInterface.ports.bind('two', two) |
| 412 | + this.exInterface.ports.bind('one', one) |
428 | 413 | |
429 | | - return Promise.all([ |
430 | | - this.kernel.send(two, this.kernel.createMessage()), |
431 | | - this.kernel.send(one, this.kernel.createMessage()) |
432 | | - ]) |
433 | | - } else if (this.runs === 1) { |
434 | | - this.runs++ |
435 | | - t.equals(m.data, 'second', 'should recive the first message') |
436 | | - } else if (this.runs === 2) { |
437 | | - t.equals(m.data, 'first', 'should recived the second message') |
| 414 | + this.exInterface.send(one, this.exInterface.createMessage()) |
| 415 | + this.exInterface.send(two, this.exInterface.createMessage()) |
| 416 | + |
| 417 | + this.exInterface.incrementTicks(6) |
| 418 | + } else if (runs === 1) { |
| 419 | + runs++ |
| 420 | + t.equals(m.data, 'second', 'should recived the second message') |
| 421 | + } else if (runs === 2) { |
| 422 | + t.equals(m.data, 'first', 'should recive the first message') |
438 | 423 | } |
439 | 424 | } |
440 | 425 | } |
441 | 426 | |
442 | 427 | class First extends BaseContainer { |
443 | 428 | run (m) { |
444 | | - this.kernel.incrementTicks(2) |
445 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 429 | + this.exInterface.incrementTicks(2) |
| 430 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
446 | 431 | data: 'first' |
447 | 432 | })) |
448 | 433 | } |
449 | 434 | } |
450 | 435 | |
451 | 436 | class Second extends BaseContainer { |
452 | 437 | run (m) { |
453 | | - this.kernel.incrementTicks(2) |
454 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 438 | + this.exInterface.incrementTicks(2) |
| 439 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
455 | 440 | data: 'second' |
456 | 441 | })) |
457 | 442 | } |
458 | 443 | } |
465 | 450 | |
466 | 451 | const root = await hypervisor.createInstance('root') |
467 | 452 | |
468 | 453 | const port = root.ports.create('root') |
469 | | - root.ports.bind(port, 'first') |
| 454 | + root.ports.bind('first', port) |
470 | 455 | |
471 | 456 | root.send(port, root.createMessage()) |
472 | 457 | }) |
473 | 458 | |
474 | | - tape.skip('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
| 459 | + tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
475 | 460 | t.plan(2) |
476 | 461 | |
| 462 | + let runs = 0 |
| 463 | + |
477 | 464 | class Root extends BaseContainer { |
478 | 465 | run (m) { |
479 | | - if (!this.runs) { |
480 | | - this.runs = 1 |
481 | | - const one = this.kernel.ports.create('first') |
482 | | - const two = this.kernel.ports.create('second') |
| 466 | + if (!runs) { |
| 467 | + runs++ |
| 468 | + const one = this.exInterface.ports.create('first') |
| 469 | + const two = this.exInterface.ports.create('second') |
483 | 470 | |
484 | | - this.kernel.ports.bind(one, 'one') |
485 | | - this.kernel.ports.bind(two, 'two') |
| 471 | + this.exInterface.ports.bind('one', one) |
| 472 | + this.exInterface.ports.bind('two', two) |
486 | 473 | |
487 | | - return Promise.all([ |
488 | | - this.kernel.send(two, this.kernel.createMessage()), |
489 | | - this.kernel.send(one, this.kernel.createMessage()) |
490 | | - ]) |
491 | | - } else if (this.runs === 1) { |
492 | | - this.runs++ |
| 474 | + this.exInterface.send(two, this.exInterface.createMessage()) |
| 475 | + this.exInterface.send(one, this.exInterface.createMessage()) |
| 476 | + |
| 477 | + this.exInterface.incrementTicks(6) |
| 478 | + } else if (runs === 1) { |
| 479 | + runs++ |
493 | 480 | t.equals(m.data, 'first', 'should recive the first message') |
494 | | - } else if (this.runs === 2) { |
| 481 | + } else if (runs === 2) { |
495 | 482 | t.equals(m.data, 'second', 'should recived the second message') |
496 | 483 | } |
497 | 484 | } |
498 | 485 | } |
499 | 486 | |
500 | 487 | class First extends BaseContainer { |
501 | 488 | run (m) { |
502 | | - this.kernel.incrementTicks(2) |
503 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 489 | + this.exInterface.incrementTicks(2) |
| 490 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
504 | 491 | resources: { |
505 | 492 | priority: 100 |
506 | 493 | }, |
507 | 494 | data: 'first' |
510 | 497 | } |
511 | 498 | |
512 | 499 | class Second extends BaseContainer { |
513 | 500 | run (m) { |
514 | | - this.kernel.incrementTicks(2) |
515 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 501 | + this.exInterface.incrementTicks(2) |
| 502 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
516 | 503 | data: 'second' |
517 | 504 | })) |
518 | 505 | } |
519 | 506 | } |
525 | 512 | hypervisor.registerContainer('second', Second) |
526 | 513 | |
527 | 514 | const root = await hypervisor.createInstance('root') |
528 | 515 | const port = root.ports.create('root') |
529 | | - root.ports.bind(port, 'first') |
| 516 | + root.ports.bind('first', port) |
530 | 517 | root.send(port, root.createMessage()) |
531 | 518 | }) |
532 | 519 | |
533 | 520 | tape.skip('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
537 | 524 | run (m) { |
538 | 525 | if (!this.runs) { |
539 | 526 | this.runs = 1 |
540 | 527 | |
541 | | - const one = this.kernel.ports.create('first') |
542 | | - const two = this.kernel.ports.create('second') |
| 528 | + const one = this.exInterface.ports.create('first') |
| 529 | + const two = this.exInterface.ports.create('second') |
543 | 530 | |
544 | | - this.kernel.ports.bind(one, 'one') |
545 | | - this.kernel.ports.bind(two, 'two') |
| 531 | + this.exInterface.ports.bind(one, 'one') |
| 532 | + this.exInterface.ports.bind(two, 'two') |
546 | 533 | |
547 | 534 | return Promise.all([ |
548 | | - this.kernel.send(two, this.kernel.createMessage()), |
549 | | - this.kernel.send(one, this.kernel.createMessage()) |
| 535 | + this.exInterface.send(two, this.exInterface.createMessage()), |
| 536 | + this.exInterface.send(one, this.exInterface.createMessage()) |
550 | 537 | ]) |
551 | 538 | } else if (this.runs === 1) { |
552 | 539 | this.runs++ |
553 | 540 | t.equals(m.data, 'second', 'should recive the first message') |
558 | 545 | } |
559 | 546 | |
560 | 547 | class First extends BaseContainer { |
561 | 548 | run (m) { |
562 | | - this.kernel.incrementTicks(2) |
563 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 549 | + this.exInterface.incrementTicks(2) |
| 550 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
564 | 551 | data: 'first' |
565 | 552 | })) |
566 | 553 | } |
567 | 554 | } |
568 | 555 | |
569 | 556 | class Second extends BaseContainer { |
570 | 557 | run (m) { |
571 | | - this.kernel.incrementTicks(2) |
572 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 558 | + this.exInterface.incrementTicks(2) |
| 559 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
573 | 560 | resources: { |
574 | 561 | priority: 100 |
575 | 562 | }, |
576 | 563 | data: 'second' |
595 | 582 | class Middle extends BaseContainer { |
596 | 583 | run (m) { |
597 | 584 | if (!this.runs) { |
598 | 585 | this.runs = 1 |
599 | | - this.kernel.incrementTicks(1) |
| 586 | + this.exInterface.incrementTicks(1) |
600 | 587 | |
601 | | - const leaf = this.kernel.ports.create('leaf') |
602 | | - this.kernel.ports.bind(leaf, 'leaf') |
| 588 | + const leaf = this.exInterface.ports.create('leaf') |
| 589 | + this.exInterface.ports.bind(leaf, 'leaf') |
603 | 590 | |
604 | | - return this.kernel.send(leaf, this.kernel.createMessage()) |
| 591 | + return this.exInterface.send(leaf, this.exInterface.createMessage()) |
605 | 592 | } else { |
606 | 593 | ++this.runs |
607 | 594 | if (this.runs === 3) { |
608 | 595 | t.equals(m.data, 'first') |
612 | 599 | } |
613 | 600 | |
614 | 601 | class Leaf extends BaseContainer { |
615 | 602 | run (m) { |
616 | | - this.kernel.incrementTicks(2) |
617 | | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 603 | + this.exInterface.incrementTicks(2) |
| 604 | + return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
618 | 605 | data: 'first' |
619 | 606 | })) |
620 | 607 | } |
621 | 608 | } |
657 | 644 | const foundThird = await hypervisor.getInstanceByPath(root, 'first/second/third') |
658 | 645 | t.equals(third, foundThird, 'should find by path') |
659 | 646 | }) |
660 | 647 | |
661 | | - tape.skip('checking ports', async t => { |
662 | | - t.plan(5) |
| 648 | + tape('checking ports', async t => { |
| 649 | + t.plan(4) |
663 | 650 | const hypervisor = new Hypervisor(node.dag) |
664 | 651 | hypervisor.registerContainer('base', BaseContainer) |
665 | 652 | |
666 | 653 | const root = await hypervisor.createInstance('base') |
667 | 654 | let port = root.ports.create('base') |
668 | | - root.ports.bind(port, 'test') |
| 655 | + await root.ports.bind('test', port) |
669 | 656 | |
670 | | - t.equals(root.ports.getBoundName(port), 'test', 'should get the ports name') |
671 | | - |
672 | 657 | try { |
673 | 658 | root.createMessage({ |
674 | 659 | ports: [port] |
675 | 660 | }) |
677 | 662 | t.pass('should thow if sending a port that is bound') |
678 | 663 | } |
679 | 664 | |
680 | 665 | try { |
681 | | - root.ports.bind(port, 'test') |
| 666 | + await root.ports.bind('test', port) |
682 | 667 | } catch (e) { |
683 | 668 | t.pass('should thow if binding an already bound port') |
684 | 669 | } |
685 | 670 | |
686 | 671 | try { |
687 | 672 | let port2 = root.ports.create('base') |
688 | | - root.ports.bind(port2, 'test') |
| 673 | + await root.ports.bind('test', port2) |
689 | 674 | } catch (e) { |
690 | 675 | t.pass('should thow if binding an already bound name') |
691 | 676 | } |
692 | 677 | |
693 | | - root.ports.unbind('test') |
| 678 | + await root.ports.unbind('test') |
694 | 679 | const message = root.createMessage({ports: [port]}) |
695 | 680 | t.equals(message.ports[0], port, 'should create a message if the port is unbound') |
696 | 681 | }) |
697 | 682 | }) |