tests/index.jsView |
---|
12 | 12 | this.exInterface = exInterface |
13 | 13 | } |
14 | 14 | |
15 | 15 | initailize (message) { |
16 | | - |
17 | 16 | const port = message.ports[0] |
18 | 17 | if (port) { |
19 | 18 | this.exInterface.ports.bind('root', port) |
20 | 19 | } |
147 | 146 | |
148 | 147 | t.end() |
149 | 148 | }) |
150 | 149 | |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | | - |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | 150 | tape('traps', async t => { |
205 | 151 | t.plan(1) |
206 | 152 | class Root extends BaseContainer { |
207 | 153 | async run (m) { |
246 | 192 | |
247 | 193 | this.exInterface.send(one, this.exInterface.createMessage()) |
248 | 194 | this.exInterface.send(two, this.exInterface.createMessage()) |
249 | 195 | |
250 | | - this.exInterface.incrementTicks(6) |
251 | 196 | } else if (runs === 1) { |
252 | 197 | runs++ |
| 198 | + t.equals(m.data, 'second', 'should recived the second message') |
| 199 | + } else if (runs === 2) { |
253 | 200 | t.equals(m.data, 'first', 'should recive the first message') |
254 | | - } else if (runs === 2) { |
255 | | - t.equals(m.data, 'second', 'should recived the second message') |
256 | 201 | } |
257 | 202 | } |
258 | 203 | } |
259 | 204 | |
260 | 205 | class First extends BaseContainer { |
261 | 206 | run (m) { |
262 | | - this.exInterface.incrementTicks(1) |
| 207 | + this.exInterface.incrementTicks(2) |
263 | 208 | this.exInterface.send(m.fromPort, this.exInterface.createMessage({data: 'first'})) |
264 | 209 | } |
265 | 210 | } |
266 | 211 | |
267 | 212 | class Second extends BaseContainer { |
268 | 213 | run (m) { |
269 | | - this.exInterface.incrementTicks(2) |
| 214 | + this.exInterface.incrementTicks(1) |
270 | 215 | this.exInterface.send(m.fromPort, this.exInterface.createMessage({data: 'second'})) |
271 | 216 | } |
272 | 217 | } |
273 | 218 | |
283 | 228 | |
284 | 229 | root.send(port, root.createMessage()) |
285 | 230 | }) |
286 | 231 | |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
294 | | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | | - |
312 | | - |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | | - |
323 | | - |
324 | | - |
325 | | - |
326 | | - |
327 | | - |
328 | | - |
329 | | - |
330 | | - |
331 | | - |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | | - |
339 | | - |
340 | | - |
341 | | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | | - |
350 | | - |
351 | | - |
352 | | - |
353 | | - |
354 | | - |
355 | | - |
356 | | - |
357 | | - |
358 | | - |
359 | | - |
360 | | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | | - |
370 | | - |
371 | | - |
372 | | - |
373 | | - |
374 | | - |
375 | | - |
376 | | - |
377 | | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | | - |
385 | | - |
386 | | - |
387 | | - |
388 | | - |
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 => { |
| 232 | + tape('message should arrive in the correct oder if sent in order', async t => { |
400 | 233 | t.plan(2) |
401 | | - |
402 | 234 | let runs = 0 |
403 | 235 | |
404 | 236 | class Root extends BaseContainer { |
405 | 237 | run (m) { |
407 | 239 | runs++ |
408 | 240 | const one = this.exInterface.ports.create('first') |
409 | 241 | const two = this.exInterface.ports.create('second') |
410 | 242 | |
| 243 | + this.exInterface.ports.bind('one', one) |
411 | 244 | this.exInterface.ports.bind('two', two) |
412 | | - this.exInterface.ports.bind('one', one) |
413 | 245 | |
414 | 246 | this.exInterface.send(one, this.exInterface.createMessage()) |
415 | 247 | this.exInterface.send(two, this.exInterface.createMessage()) |
416 | 248 | |
417 | 249 | this.exInterface.incrementTicks(6) |
418 | 250 | } else if (runs === 1) { |
419 | 251 | runs++ |
| 252 | + t.equals(m.data, 'first', 'should recive the first message') |
| 253 | + } else if (runs === 2) { |
420 | 254 | 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') |
423 | 255 | } |
424 | 256 | } |
425 | 257 | } |
426 | 258 | |
427 | 259 | class First extends BaseContainer { |
428 | 260 | run (m) { |
429 | | - this.exInterface.incrementTicks(2) |
430 | | - return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
431 | | - data: 'first' |
432 | | - })) |
| 261 | + this.exInterface.incrementTicks(1) |
| 262 | + this.exInterface.send(m.fromPort, this.exInterface.createMessage({data: 'first'})) |
433 | 263 | } |
434 | 264 | } |
435 | 265 | |
436 | 266 | class Second extends BaseContainer { |
437 | 267 | run (m) { |
438 | 268 | this.exInterface.incrementTicks(2) |
439 | | - return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
440 | | - data: 'second' |
441 | | - })) |
| 269 | + this.exInterface.send(m.fromPort, this.exInterface.createMessage({data: 'second'})) |
442 | 270 | } |
443 | 271 | } |
444 | 272 | |
445 | 273 | const hypervisor = new Hypervisor(node.dag) |
448 | 276 | hypervisor.registerContainer('first', First) |
449 | 277 | hypervisor.registerContainer('second', Second) |
450 | 278 | |
451 | 279 | const root = await hypervisor.createInstance('root') |
452 | | - |
453 | 280 | const port = root.ports.create('root') |
454 | 281 | root.ports.bind('first', port) |
455 | 282 | |
456 | 283 | root.send(port, root.createMessage()) |
457 | 284 | }) |
458 | 285 | |
459 | | - tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
| 286 | + tape('message should arrive in the correct order, even in a tie of ticks', async t => { |
460 | 287 | t.plan(2) |
461 | 288 | |
462 | 289 | let runs = 0 |
463 | 290 | |
467 | 294 | runs++ |
468 | 295 | const one = this.exInterface.ports.create('first') |
469 | 296 | const two = this.exInterface.ports.create('second') |
470 | 297 | |
| 298 | + this.exInterface.ports.bind('two', two) |
471 | 299 | this.exInterface.ports.bind('one', one) |
472 | | - this.exInterface.ports.bind('two', two) |
473 | 300 | |
| 301 | + this.exInterface.send(one, this.exInterface.createMessage()) |
474 | 302 | this.exInterface.send(two, this.exInterface.createMessage()) |
475 | | - this.exInterface.send(one, this.exInterface.createMessage()) |
476 | 303 | |
477 | 304 | this.exInterface.incrementTicks(6) |
478 | 305 | } else if (runs === 1) { |
479 | 306 | runs++ |
| 307 | + t.equals(m.data, 'second', 'should recived the second message') |
| 308 | + } else if (runs === 2) { |
480 | 309 | t.equals(m.data, 'first', 'should recive the first message') |
481 | | - } else if (runs === 2) { |
482 | | - t.equals(m.data, 'second', 'should recived the second message') |
483 | 310 | } |
484 | 311 | } |
485 | 312 | } |
486 | 313 | |
487 | 314 | class First extends BaseContainer { |
488 | 315 | run (m) { |
489 | 316 | this.exInterface.incrementTicks(2) |
490 | 317 | return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
491 | | - resources: { |
492 | | - priority: 100 |
493 | | - }, |
494 | 318 | data: 'first' |
495 | 319 | })) |
496 | 320 | } |
497 | 321 | } |
511 | 335 | hypervisor.registerContainer('first', First) |
512 | 336 | hypervisor.registerContainer('second', Second) |
513 | 337 | |
514 | 338 | const root = await hypervisor.createInstance('root') |
| 339 | + |
515 | 340 | const port = root.ports.create('root') |
516 | 341 | root.ports.bind('first', port) |
| 342 | + |
517 | 343 | root.send(port, root.createMessage()) |
518 | 344 | }) |
519 | 345 | |
520 | | - tape.skip('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
| 346 | + tape('message should arrive in the correct order, with a tie in ticks but with differnt proity', async t => { |
521 | 347 | t.plan(2) |
522 | 348 | |
| 349 | + let runs = 0 |
| 350 | + |
523 | 351 | class Root extends BaseContainer { |
524 | 352 | run (m) { |
525 | | - if (!this.runs) { |
526 | | - this.runs = 1 |
527 | | - |
| 353 | + if (!runs) { |
| 354 | + runs++ |
528 | 355 | const one = this.exInterface.ports.create('first') |
529 | 356 | const two = this.exInterface.ports.create('second') |
530 | 357 | |
531 | | - this.exInterface.ports.bind(one, 'one') |
532 | | - this.exInterface.ports.bind(two, 'two') |
| 358 | + this.exInterface.ports.bind('one', one) |
| 359 | + this.exInterface.ports.bind('two', two) |
533 | 360 | |
534 | | - return Promise.all([ |
535 | | - this.exInterface.send(two, this.exInterface.createMessage()), |
536 | | - this.exInterface.send(one, this.exInterface.createMessage()) |
537 | | - ]) |
538 | | - } else if (this.runs === 1) { |
539 | | - this.runs++ |
540 | | - t.equals(m.data, 'second', 'should recive the first message') |
541 | | - } else if (this.runs === 2) { |
542 | | - t.equals(m.data, 'first', 'should recived the second message') |
| 361 | + this.exInterface.send(two, this.exInterface.createMessage()) |
| 362 | + this.exInterface.send(one, this.exInterface.createMessage()) |
| 363 | + |
| 364 | + this.exInterface.incrementTicks(6) |
| 365 | + } else if (runs === 1) { |
| 366 | + runs++ |
| 367 | + t.equals(m.data, 'first', 'should recive the first message') |
| 368 | + } else if (runs === 2) { |
| 369 | + t.equals(m.data, 'second', 'should recived the second message') |
543 | 370 | } |
544 | 371 | } |
545 | 372 | } |
546 | 373 | |
547 | 374 | class First extends BaseContainer { |
548 | 375 | run (m) { |
549 | 376 | this.exInterface.incrementTicks(2) |
550 | 377 | return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
| 378 | + resources: { |
| 379 | + priority: 100 |
| 380 | + }, |
551 | 381 | data: 'first' |
552 | 382 | })) |
553 | 383 | } |
554 | 384 | } |
556 | 386 | class Second extends BaseContainer { |
557 | 387 | run (m) { |
558 | 388 | this.exInterface.incrementTicks(2) |
559 | 389 | return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
560 | | - resources: { |
561 | | - priority: 100 |
562 | | - }, |
563 | 390 | data: 'second' |
564 | 391 | })) |
565 | 392 | } |
566 | 393 | } |
572 | 399 | hypervisor.registerContainer('second', Second) |
573 | 400 | |
574 | 401 | const root = await hypervisor.createInstance('root') |
575 | 402 | const port = root.ports.create('root') |
576 | | - root.ports.bind(port, 'first') |
| 403 | + root.ports.bind('first', port) |
577 | 404 | root.send(port, root.createMessage()) |
578 | 405 | }) |
579 | 406 | |
580 | | - tape.skip('should order parent messages correctly', async t => { |
581 | | - t.plan(1) |
582 | | - class Middle extends BaseContainer { |
583 | | - run (m) { |
584 | | - if (!this.runs) { |
585 | | - this.runs = 1 |
586 | | - this.exInterface.incrementTicks(1) |
587 | | - |
588 | | - const leaf = this.exInterface.ports.create('leaf') |
589 | | - this.exInterface.ports.bind(leaf, 'leaf') |
590 | | - |
591 | | - return this.exInterface.send(leaf, this.exInterface.createMessage()) |
592 | | - } else { |
593 | | - ++this.runs |
594 | | - if (this.runs === 3) { |
595 | | - t.equals(m.data, 'first') |
596 | | - } |
597 | | - } |
598 | | - } |
599 | | - } |
600 | | - |
601 | | - class Leaf extends BaseContainer { |
602 | | - run (m) { |
603 | | - this.exInterface.incrementTicks(2) |
604 | | - return this.exInterface.send(m.fromPort, this.exInterface.createMessage({ |
605 | | - data: 'first' |
606 | | - })) |
607 | | - } |
608 | | - } |
609 | | - |
610 | | - const hypervisor = new Hypervisor(node.dag) |
611 | | - |
612 | | - hypervisor.registerContainer('root', BaseContainer) |
613 | | - hypervisor.registerContainer('middle', Middle) |
614 | | - hypervisor.registerContainer('leaf', Leaf) |
615 | | - |
616 | | - const root = await hypervisor.createInstance('root') |
617 | | - root.incrementTicks(2) |
618 | | - |
619 | | - const port = root.ports.create('middle') |
620 | | - root.ports.bind(port, 'first') |
621 | | - |
622 | | - await root.send(port, root.createMessage()) |
623 | | - root.send(port, root.createMessage()) |
624 | | - }) |
625 | | - |
626 | | - tape.skip('get container instance by path', async t => { |
627 | | - t.plan(1) |
628 | | - const hypervisor = new Hypervisor(node.dag) |
629 | | - hypervisor.registerContainer('base', BaseContainer) |
630 | | - |
631 | | - const root = await hypervisor.createInstance('base') |
632 | | - let port = root.ports.create('base') |
633 | | - root.ports.bind(port, 'first') |
634 | | - |
635 | | - const first = await root.getInstance(port) |
636 | | - port = first.ports.create('base') |
637 | | - first.ports.bind(port, 'second') |
638 | | - |
639 | | - const second = await first.getInstance(port) |
640 | | - port = second.ports.create('base') |
641 | | - second.ports.bind(port, 'third') |
642 | | - |
643 | | - const third = await second.getInstance(port) |
644 | | - const foundThird = await hypervisor.getInstanceByPath(root, 'first/second/third') |
645 | | - t.equals(third, foundThird, 'should find by path') |
646 | | - }) |
647 | | - |
648 | 407 | tape('checking ports', async t => { |
649 | 408 | t.plan(4) |
650 | 409 | const hypervisor = new Hypervisor(node.dag) |
651 | 410 | hypervisor.registerContainer('base', BaseContainer) |