tests/index.jsView |
---|
108 | 108 | port = root.ports.get('first') |
109 | 109 | root.send(port, message) |
110 | 110 | }) |
111 | 111 | |
112 | | - tape.skip('ping pong', async t => { |
113 | | - class Ping extends BaseContainer { |
114 | | - async run (m) { |
115 | | - let port = this.exInterface.ports.get('child') |
116 | | - if (!port) { |
117 | | - port = this.exInterface.ports.create('pong') |
118 | | - this.exInterface.ports.bind(port, 'child') |
119 | | - } |
120 | | - |
121 | | - if (this.exInterface.ticks < 100) { |
122 | | - this.exInterface.incrementTicks(1) |
123 | | - return this.exInterface.send(port, this.exInterface.createMessage()) |
124 | | - } |
125 | | - } |
126 | | - } |
127 | | - |
128 | | - class Pong extends BaseContainer { |
129 | | - run (m) { |
130 | | - const port = m.fromPort |
131 | | - this.exInterface.incrementTicks(2) |
132 | | - return this.exInterface.send(port, this.exInterface.createMessage()) |
133 | | - } |
134 | | - } |
135 | | - |
136 | | - const hypervisor = new Hypervisor(node.dag) |
137 | | - |
138 | | - hypervisor.registerContainer('ping', Ping) |
139 | | - hypervisor.registerContainer('pong', Pong) |
140 | | - const root = await hypervisor.createInstance('pong') |
141 | | - const port = root.ports.create('ping') |
142 | | - root.ports.bind(port, 'child') |
143 | | - |
144 | | - await root.send(port, root.createMessage()) |
145 | | - await hypervisor.createStateRoot(root, Infinity) |
146 | | - |
147 | | - t.end() |
148 | | - }) |
149 | | - |
150 | 112 | tape('traps', async t => { |
151 | 113 | t.plan(1) |
152 | 114 | class Root extends BaseContainer { |
153 | 115 | async run (m) { |
374 | 336 | class First extends BaseContainer { |
375 | 337 | run (m) { |
376 | 338 | this.exInterface.incrementTicks(2) |
377 | 339 | return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
378 | | - resources: { |
379 | | - priority: 100 |
380 | | - }, |
381 | 340 | data: 'first' |
382 | 341 | })) |
383 | 342 | } |
384 | 343 | } |
437 | 396 | await root.ports.unbind('test') |
438 | 397 | const message = root.createMessage({ports: [port]}) |
439 | 398 | t.equals(message.ports[0], port, 'should create a message if the port is unbound') |
440 | 399 | }) |
| 400 | + |
| 401 | + tape.only('port deletion', async t => { |
| 402 | + t.plan(2) |
| 403 | + |
| 404 | + class Root extends BaseContainer { |
| 405 | + run (m) { |
| 406 | + const one = this.exInterface.ports.create('first') |
| 407 | + this.exInterface.ports.bind('one', one) |
| 408 | + this.exInterface.send(one, this.exInterface.createMessage()) |
| 409 | + this.exInterface.incrementTicks(6) |
| 410 | + } |
| 411 | + } |
| 412 | + |
| 413 | + class First extends BaseContainer { |
| 414 | + run (m) { |
| 415 | + this.exInterface.incrementTicks(2) |
| 416 | + this.exInterface.ports.delete('root') |
| 417 | + } |
| 418 | + } |
| 419 | + |
| 420 | + const hypervisor = new Hypervisor(node.dag) |
| 421 | + |
| 422 | + hypervisor.registerContainer('root', Root) |
| 423 | + hypervisor.registerContainer('first', First) |
| 424 | + |
| 425 | + const root = await hypervisor.createInstance('root') |
| 426 | + const port = root.ports.create('root') |
| 427 | + root.ports.bind('first', port) |
| 428 | + root.send(port, root.createMessage()) |
| 429 | + }) |
441 | 430 | }) |