OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // VMOptions=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'package:observatory/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; |
7 import 'test_helper.dart'; | 8 import 'test_helper.dart'; |
8 import 'dart:async'; | 9 import 'dart:async'; |
9 | 10 |
10 void testMain() { | 11 void testMain() { |
11 print('Hello'); | 12 print('Hello'); |
12 } | 13 } |
13 | 14 |
14 var tests = [ | 15 var tests = [ |
15 | 16 |
16 (Isolate isolate) async { | 17 (Isolate isolate) async { |
17 Completer completer = new Completer(); | 18 Completer completer = new Completer(); |
18 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 19 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
19 var subscription; | 20 var subscription; |
20 subscription = stream.listen((ServiceEvent event) { | 21 subscription = stream.listen((ServiceEvent event) { |
21 if (event.kind == ServiceEvent.kPauseStart) { | 22 if (event.kind == ServiceEvent.kPauseStart) { |
22 print('Received PauseStart'); | 23 print('Received PauseStart'); |
23 subscription.cancel(); | 24 subscription.cancel(); |
24 completer.complete(); | 25 completer.complete(); |
25 } | 26 } |
26 }); | 27 }); |
27 | 28 |
28 if (isolate.pauseEvent != null && | 29 if (isolate.pauseEvent != null && |
29 isolate.pauseEvent.kind == ServiceEvent.kPauseStart) { | 30 isolate.pauseEvent.kind == ServiceEvent.kPauseStart) { |
30 // Wait for the isolate to hit PauseStart. | 31 // Wait for the isolate to hit PauseStart. |
31 subscription.cancel(); | 32 subscription.cancel(); |
32 } else { | 33 } else { |
33 await completer.future; | 34 await completer.future; |
34 } | 35 } |
35 | 36 |
| 37 // Grab the timestamp. |
| 38 var pausetime1 = isolate.pauseEvent.timestamp; |
| 39 expect(pausetime1, isNotNull); |
| 40 // Reload the isolate. |
| 41 await isolate.reload(); |
| 42 // Verify that it is the same. |
| 43 expect(pausetime1.millisecondsSinceEpoch, |
| 44 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); |
| 45 |
36 completer = new Completer(); | 46 completer = new Completer(); |
37 stream = await isolate.vm.getEventStream(VM.kDebugStream); | 47 stream = await isolate.vm.getEventStream(VM.kDebugStream); |
38 subscription = stream.listen((ServiceEvent event) { | 48 subscription = stream.listen((ServiceEvent event) { |
39 if (event.kind == ServiceEvent.kPauseExit) { | 49 if (event.kind == ServiceEvent.kPauseExit) { |
40 print('Received PauseExit'); | 50 print('Received PauseExit'); |
41 subscription.cancel(); | 51 subscription.cancel(); |
42 completer.complete(); | 52 completer.complete(); |
43 } | 53 } |
44 }); | 54 }); |
45 | 55 |
46 print('Resuming...'); | 56 print('Resuming...'); |
47 isolate.resume(); | 57 isolate.resume(); |
48 | 58 |
49 // Wait for the isolate to hit PauseExit. | 59 // Wait for the isolate to hit PauseExit. |
50 await completer.future; | 60 await completer.future; |
| 61 |
| 62 // Grab the timestamp. |
| 63 var pausetime2 = isolate.pauseEvent.timestamp; |
| 64 expect(pausetime2, isNotNull); |
| 65 // Reload the isolate. |
| 66 await isolate.reload(); |
| 67 // Verify that it is the same. |
| 68 expect(pausetime2.millisecondsSinceEpoch, |
| 69 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); |
| 70 expect(pausetime2.millisecondsSinceEpoch, |
| 71 greaterThan(pausetime1.millisecondsSinceEpoch)); |
51 }, | 72 }, |
52 | 73 |
53 ]; | 74 ]; |
54 | 75 |
55 main(args) => runIsolateTests(args, tests, | 76 main(args) => runIsolateTests(args, tests, |
56 testeeConcurrent: testMain, | 77 testeeConcurrent: testMain, |
57 pause_on_start: true, pause_on_exit: true); | 78 pause_on_start: true, pause_on_exit: true); |
OLD | NEW |