tests/index.jsView |
---|
38 | 38 | const hypervisor = new Hypervisor({dag: node.dag}) |
39 | 39 | hypervisor.registerContainer('test', testVMContainer) |
40 | 40 | |
41 | 41 | const rootContainer = await hypervisor.createInstance('test') |
42 | | - const port = await rootContainer.createPort('test', 'first') |
| 42 | + const port = await rootContainer.ports.create('test', 'first') |
43 | 43 | |
44 | 44 | await rootContainer.send(port, message) |
45 | 45 | |
46 | 46 | const stateRoot = await hypervisor.createStateRoot(rootContainer, Infinity) |
69 | 69 | } |
70 | 70 | |
71 | 71 | class testVMContainer extends BaseContainer { |
72 | 72 | async run (m) { |
73 | | - const port = await this.kernel.createPort('test2', 'child') |
| 73 | + const port = await this.kernel.ports.create('test2', 'child') |
74 | 74 | await this.kernel.send(port, m) |
75 | 75 | this.kernel.incrementTicks(1) |
76 | 76 | } |
77 | 77 | } |
80 | 80 | hypervisor.registerContainer('test', testVMContainer) |
81 | 81 | hypervisor.registerContainer('test2', testVMContainer2) |
82 | 82 | |
83 | 83 | let root = await hypervisor.createInstance('test') |
84 | | - let port = await root.createPort('test', 'first') |
| 84 | + let port = await root.ports.create('test', 'first') |
85 | 85 | |
86 | 86 | await root.send(port, message) |
87 | 87 | const stateRoot = await hypervisor.createStateRoot(root, Infinity) |
88 | 88 | t.true(hasResolved, 'should resolve before generating the state root') |
111 | 111 | class Ping extends BaseContainer { |
112 | 112 | async run (m) { |
113 | 113 | let port = this.kernel.ports.get('child') |
114 | 114 | if (!port) { |
115 | | - port = await this.kernel.createPort('pong', 'child') |
| 115 | + port = await this.kernel.ports.create('pong', 'child') |
116 | 116 | } |
117 | 117 | |
118 | 118 | if (this.kernel.ticks < 100) { |
119 | 119 | this.kernel.incrementTicks(1) |
136 | 136 | |
137 | 137 | hypervisor.registerContainer('ping', Ping) |
138 | 138 | hypervisor.registerContainer('pong', Pong) |
139 | 139 | const root = await hypervisor.createInstance('pong') |
140 | | - const port = await root.createPort('ping', 'child') |
| 140 | + const port = await root.ports.create('ping', 'child') |
141 | 141 | |
142 | 142 | await root.send(port, new Message()) |
143 | 143 | await hypervisor.createStateRoot(root, Infinity) |
144 | 144 | |
149 | 149 | let runs = 0 |
150 | 150 | |
151 | 151 | class Root extends BaseContainer { |
152 | 152 | async run (m) { |
153 | | - const one = this.kernel.createPort('child', 'one') |
154 | | - const two = this.kernel.createPort('child', 'two') |
155 | | - const three = this.kernel.createPort('child', 'three') |
| 153 | + const one = this.kernel.ports.create('child', 'one') |
| 154 | + const two = this.kernel.ports.create('child', 'two') |
| 155 | + const three = this.kernel.ports.create('child', 'three') |
156 | 156 | |
157 | 157 | await Promise.all([ |
158 | 158 | this.kernel.send(one, new Message()), |
159 | 159 | this.kernel.send(two, new Message()), |
183 | 183 | hypervisor.registerContainer('root', Root) |
184 | 184 | hypervisor.registerContainer('child', Child) |
185 | 185 | |
186 | 186 | const root = await hypervisor.createInstance('root') |
187 | | - const port = await root.createPort('root', 'first') |
| 187 | + const port = await root.ports.create('root', 'first') |
188 | 188 | await root.send(port, new Message()) |
189 | 189 | await root.wait(Infinity) |
190 | 190 | |
191 | 191 | t.equals(runs, 3, 'the number of run should be 3') |
198 | 198 | tape('traps', async t => { |
199 | 199 | class Root extends BaseContainer { |
200 | 200 | async run (m) { |
201 | 201 | await Promise.all([ |
202 | | - this.kernel.createPort('root', 'one'), |
203 | | - this.kernel.createPort('root', 'two'), |
204 | | - this.kernel.createPort('root', 'three') |
| 202 | + this.kernel.ports.create('root', 'one'), |
| 203 | + this.kernel.ports.create('root', 'two'), |
| 204 | + this.kernel.ports.create('root', 'three') |
205 | 205 | ]) |
206 | 206 | |
207 | 207 | throw new Error('it is a trap!!!') |
208 | 208 | } |
232 | 232 | class Root extends BaseContainer { |
233 | 233 | async run (m) { |
234 | 234 | if (!this.runs) { |
235 | 235 | this.runs = 1 |
236 | | - const one = this.kernel.createPort('first', 'one') |
237 | | - const two = this.kernel.createPort('second', 'two') |
| 236 | + const one = this.kernel.ports.create('first', 'one') |
| 237 | + const two = this.kernel.ports.create('second', 'two') |
238 | 238 | |
239 | 239 | await Promise.all([ |
240 | 240 | this.kernel.send(one, new Message()), |
241 | 241 | this.kernel.send(two, new Message()) |
273 | 273 | hypervisor.registerContainer('first', First) |
274 | 274 | hypervisor.registerContainer('second', Second) |
275 | 275 | |
276 | 276 | const root = await hypervisor.createInstance('root') |
277 | | - const port = await root.createPort('root', 'first') |
| 277 | + const port = await root.ports.create('root', 'first') |
278 | 278 | await root.send(port, new Message()) |
279 | 279 | }) |
280 | 280 | |
281 | 281 | tape('message should arrive in the correct order, even if sent out of order', async t => { |
284 | 284 | class Root extends BaseContainer { |
285 | 285 | async run (m) { |
286 | 286 | if (!this.runs) { |
287 | 287 | this.runs = 1 |
288 | | - const one = this.kernel.createPort('first', 'one') |
289 | | - const two = this.kernel.createPort('second', 'two') |
| 288 | + const one = this.kernel.ports.create('first', 'one') |
| 289 | + const two = this.kernel.ports.create('second', 'two') |
290 | 290 | |
291 | 291 | await Promise.all([ |
292 | 292 | this.kernel.send(one, new Message()), |
293 | 293 | this.kernel.send(two, new Message()) |
325 | 325 | hypervisor.registerContainer('first', First) |
326 | 326 | hypervisor.registerContainer('second', Second) |
327 | 327 | |
328 | 328 | const root = await hypervisor.createInstance('root') |
329 | | - const port = await root.createPort('root', 'first') |
| 329 | + const port = await root.ports.create('root', 'first') |
330 | 330 | await root.send(port, new Message()) |
331 | 331 | }) |
332 | 332 | |
333 | 333 | tape('message should arrive in the correct order, even in a tie of ticks', async t => { |
336 | 336 | class Root extends BaseContainer { |
337 | 337 | async run (m) { |
338 | 338 | if (!this.runs) { |
339 | 339 | this.runs = 1 |
340 | | - const one = this.kernel.createPort('first', 'one') |
341 | | - const two = this.kernel.createPort('second', 'two') |
| 340 | + const one = this.kernel.ports.create('first', 'one') |
| 341 | + const two = this.kernel.ports.create('second', 'two') |
342 | 342 | |
343 | 343 | await Promise.all([ |
344 | 344 | this.kernel.send(one, new Message()), |
345 | 345 | this.kernel.send(two, new Message()) |
377 | 377 | hypervisor.registerContainer('first', First) |
378 | 378 | hypervisor.registerContainer('second', Second) |
379 | 379 | |
380 | 380 | const root = await hypervisor.createInstance('root') |
381 | | - const port = await root.createPort('root', 'first') |
| 381 | + const port = await root.ports.create('root', 'first') |
382 | 382 | await root.send(port, new Message()) |
383 | 383 | }) |
384 | 384 | |
385 | 385 | tape('message should arrive in the correct order, even in a tie of ticks', async t => { |
388 | 388 | class Root extends BaseContainer { |
389 | 389 | async run (m) { |
390 | 390 | if (!this.runs) { |
391 | 391 | this.runs = 1 |
392 | | - const two = this.kernel.createPort('second', 'two') |
393 | | - const one = this.kernel.createPort('first', 'one') |
| 392 | + const two = this.kernel.ports.create('second', 'two') |
| 393 | + const one = this.kernel.ports.create('first', 'one') |
394 | 394 | |
395 | 395 | await Promise.all([ |
396 | 396 | this.kernel.send(two, new Message()), |
397 | 397 | this.kernel.send(one, new Message()) |
429 | 429 | hypervisor.registerContainer('first', First) |
430 | 430 | hypervisor.registerContainer('second', Second) |
431 | 431 | |
432 | 432 | const root = await hypervisor.createInstance('root') |
433 | | - const port = await root.createPort('root', 'first') |
| 433 | + const port = await root.ports.create('root', 'first') |
434 | 434 | await root.send(port, new Message()) |
435 | 435 | }) |
436 | 436 | |
437 | 437 | tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
440 | 440 | class Root extends BaseContainer { |
441 | 441 | async run (m) { |
442 | 442 | if (!this.runs) { |
443 | 443 | this.runs = 1 |
444 | | - const one = this.kernel.createPort('first', 'one') |
445 | | - const two = this.kernel.createPort('second', 'two') |
| 444 | + const one = this.kernel.ports.create('first', 'one') |
| 445 | + const two = this.kernel.ports.create('second', 'two') |
446 | 446 | |
447 | 447 | await Promise.all([ |
448 | 448 | this.kernel.send(two, new Message()), |
449 | 449 | this.kernel.send(one, new Message()) |
486 | 486 | hypervisor.registerContainer('first', First) |
487 | 487 | hypervisor.registerContainer('second', Second) |
488 | 488 | |
489 | 489 | const root = await hypervisor.createInstance('root') |
490 | | - const port = await root.createPort('root', 'first') |
| 490 | + const port = await root.ports.create('root', 'first') |
491 | 491 | await root.send(port, new Message()) |
492 | 492 | }) |
493 | 493 | |
494 | 494 | tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
497 | 497 | class Root extends BaseContainer { |
498 | 498 | async run (m) { |
499 | 499 | if (!this.runs) { |
500 | 500 | this.runs = 1 |
501 | | - const one = this.kernel.createPort('first', 'one') |
502 | | - const two = this.kernel.createPort('second', 'two') |
| 501 | + const one = this.kernel.ports.create('first', 'one') |
| 502 | + const two = this.kernel.ports.create('second', 'two') |
503 | 503 | |
504 | 504 | await Promise.all([ |
505 | 505 | this.kernel.send(two, new Message()), |
506 | 506 | this.kernel.send(one, new Message()) |
545 | 545 | hypervisor.registerContainer('first', First) |
546 | 546 | hypervisor.registerContainer('second', Second) |
547 | 547 | |
548 | 548 | const root = await hypervisor.createInstance('root') |
549 | | - const port = await root.createPort('root', 'first') |
| 549 | + const port = await root.ports.create('root', 'first') |
550 | 550 | await root.send(port, new Message()) |
551 | 551 | }) |
552 | 552 | |
553 | 553 | tape('should order parent messages correctly', async t => { |
555 | 555 | async run (m) { |
556 | 556 | if (!this.runs) { |
557 | 557 | this.runs = 1 |
558 | 558 | this.kernel.incrementTicks(1) |
559 | | - const leaf = this.kernel.createPort('leaf', 'leaf') |
| 559 | + const leaf = this.kernel.ports.create('leaf', 'leaf') |
560 | 560 | await this.kernel.send(leaf, new Message()) |
561 | 561 | } else { |
562 | 562 | ++this.runs |
563 | 563 | if (this.runs === 3) { |
585 | 585 | hypervisor.registerContainer('leaf', Leaf) |
586 | 586 | |
587 | 587 | const root = await hypervisor.createInstance('root') |
588 | 588 | root.incrementTicks(2) |
589 | | - const port = await root.createPort('middle', 'first') |
590 | 589 | |
| 590 | + const port = await root.ports.create('middle', 'first') |
| 591 | + |
591 | 592 | await root.send(port, new Message()) |
592 | 593 | await root.send(port, new Message()) |
593 | | - |
594 | 594 | await root.wait(Infinity) |
595 | 595 | |
596 | 596 | t.end() |
597 | 597 | node.stop(() => { |