| OLD | NEW |
| 1 library async_test; | 1 library async_test; |
| 2 | 2 |
| 3 import '../../pkg/unittest/lib/unittest.dart'; | 3 import '../../pkg/unittest/lib/unittest.dart'; |
| 4 import '../../pkg/unittest/lib/html_config.dart'; | 4 import '../../pkg/unittest/lib/html_config.dart'; |
| 5 | 5 |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 oneshotTimerIsolate() { | 10 oneshotTimerIsolate() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 assert(counter < 3); | 34 assert(counter < 3); |
| 35 counter++; | 35 counter++; |
| 36 }); | 36 }); |
| 37 }); | 37 }); |
| 38 } | 38 } |
| 39 | 39 |
| 40 cancellingIsolate() { | 40 cancellingIsolate() { |
| 41 port.receive((msg, replyTo) { | 41 port.receive((msg, replyTo) { |
| 42 expect(msg, 'START'); | 42 expect(msg, 'START'); |
| 43 final oneshot = new Timer(const Duration(milliseconds: 30), () { | |
| 44 fail('Should never be invoked'); | |
| 45 }); | |
| 46 bool shot = false; | 43 bool shot = false; |
| 44 var oneshot; |
| 47 var periodic; | 45 var periodic; |
| 48 periodic = new Timer.periodic(const Duration(milliseconds: 10), (timer) { | 46 periodic = new Timer.periodic(const Duration(milliseconds: 10), (timer) { |
| 49 expect(shot, isFalse); | 47 expect(shot, isFalse); |
| 50 shot = true; | 48 shot = true; |
| 51 expect(timer, same(periodic)); | 49 expect(timer, same(periodic)); |
| 52 periodic.cancel(); | 50 periodic.cancel(); |
| 53 oneshot.cancel(); | 51 oneshot.cancel(); |
| 54 // Wait some more time to be sure callbacks won't be invoked any | 52 // Wait some more time to be sure callbacks won't be invoked any |
| 55 // more. | 53 // more. |
| 56 new Timer(const Duration(milliseconds: 50), () { | 54 new Timer(const Duration(milliseconds: 50), () { |
| 57 replyTo.send('DONE'); | 55 replyTo.send('DONE'); |
| 58 }); | 56 }); |
| 59 }); | 57 }); |
| 58 // We launch the oneshot timer after the periodic timer. Otherwise a |
| 59 // (very long) context switch could make this test flaky: assume the |
| 60 // oneshot timer is created first and then there is a 30ms context switch. |
| 61 // when the periodic timer is scheduled it would execute after the oneshot. |
| 62 oneshot = new Timer(const Duration(milliseconds: 30), () { |
| 63 fail('Should never be invoked'); |
| 64 }); |
| 60 }); | 65 }); |
| 61 } | 66 } |
| 62 | 67 |
| 63 main() { | 68 main() { |
| 64 useHtmlConfiguration(); | 69 useHtmlConfiguration(); |
| 65 | 70 |
| 66 test('one shot timer in pure isolate', () { | 71 test('one shot timer in pure isolate', () { |
| 67 expect(spawnFunction(oneshotTimerIsolate).call('START'), | 72 expect(spawnFunction(oneshotTimerIsolate).call('START'), |
| 68 completion('DONE')); | 73 completion('DONE')); |
| 69 }); | 74 }); |
| 70 test('periodic timer in pure isolate', () { | 75 test('periodic timer in pure isolate', () { |
| 71 expect(spawnFunction(periodicTimerIsolate).call('START'), | 76 expect(spawnFunction(periodicTimerIsolate).call('START'), |
| 72 completion('DONE')); | 77 completion('DONE')); |
| 73 }); | 78 }); |
| 74 test('cancellation in pure isolate', () { | 79 test('cancellation in pure isolate', () { |
| 75 expect(spawnFunction(cancellingIsolate).call('START'), | 80 expect(spawnFunction(cancellingIsolate).call('START'), |
| 76 completion('DONE')); | 81 completion('DONE')); |
| 77 }); | 82 }); |
| 78 } | 83 } |
| OLD | NEW |