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 'dart:async'; | 6 import 'dart:async'; |
7 import 'package:observatory/service_io.dart'; | 7 import 'package:observatory/service_io.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 | 9 |
10 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
11 | 11 |
12 Future sleep(int milliseconds) { | 12 Future sleep(int milliseconds) { |
13 Completer completer = new Completer(); | 13 Completer completer = new Completer(); |
14 Duration duration = new Duration(milliseconds: milliseconds); | 14 Duration duration = new Duration(milliseconds: milliseconds); |
15 new Timer(duration, () => completer.complete() ); | 15 new Timer(duration, () => completer.complete() ); |
16 return completer.future; | 16 return completer.future; |
kustermann
2016/09/28 18:26:24
Side note: This could be just:
new Future.delay
| |
17 } | 17 } |
18 | 18 |
19 var tests = [ | 19 var tests = [ |
20 (Isolate isolate) async { | 20 (Isolate isolate) async { |
21 var params = { | 21 var params = { |
22 }; | 22 }; |
23 var result = await isolate.invokeRpcNoUpgrade( | 23 var result = await isolate.invokeRpcNoUpgrade( |
24 '_getAllocationProfile', params); | 24 '_getAllocationProfile', params); |
25 expect(result['type'], equals('AllocationProfile')); | 25 expect(result['type'], equals('AllocationProfile')); |
26 expect(result.containsKey('dateLastAccumulatorReset'), isFalse); | 26 expect(result.containsKey('dateLastAccumulatorReset'), isFalse); |
(...skipping 12 matching lines...) Expand all Loading... | |
39 expect(result['type'], equals('AllocationProfile')); | 39 expect(result['type'], equals('AllocationProfile')); |
40 var firstReset = result['dateLastAccumulatorReset']; | 40 var firstReset = result['dateLastAccumulatorReset']; |
41 expect(firstReset, new isInstanceOf<String>()); | 41 expect(firstReset, new isInstanceOf<String>()); |
42 expect(result.containsKey('dateLastServiceGC'), isFalse); | 42 expect(result.containsKey('dateLastServiceGC'), isFalse); |
43 expect(result['heaps'].length, isPositive); | 43 expect(result['heaps'].length, isPositive); |
44 expect(result['heaps']['new']['type'], equals('HeapSpace')); | 44 expect(result['heaps']['new']['type'], equals('HeapSpace')); |
45 expect(result['heaps']['old']['type'], equals('HeapSpace')); | 45 expect(result['heaps']['old']['type'], equals('HeapSpace')); |
46 expect(result['members'].length, isPositive); | 46 expect(result['members'].length, isPositive); |
47 expect(result['members'][0]['type'], equals('ClassHeapStats')); | 47 expect(result['members'][0]['type'], equals('ClassHeapStats')); |
48 | 48 |
49 await sleep(10); | 49 await sleep(1000); |
50 | 50 |
51 result = await isolate.invokeRpcNoUpgrade('_getAllocationProfile', params); | 51 result = await isolate.invokeRpcNoUpgrade('_getAllocationProfile', params); |
52 var secondReset = result['dateLastAccumulatorReset']; | 52 var secondReset = result['dateLastAccumulatorReset']; |
53 expect(secondReset, isNot(equals(firstReset))); | 53 expect(secondReset, isNot(equals(firstReset))); |
54 | 54 |
55 // gc. | 55 // gc. |
56 params = { | 56 params = { |
57 'gc' : 'full', | 57 'gc' : 'full', |
58 }; | 58 }; |
59 result = await isolate.invokeRpcNoUpgrade('_getAllocationProfile', params); | 59 result = await isolate.invokeRpcNoUpgrade('_getAllocationProfile', params); |
60 expect(result['type'], equals('AllocationProfile')); | 60 expect(result['type'], equals('AllocationProfile')); |
61 expect(result['dateLastAccumulatorReset'], equals(secondReset)); | 61 expect(result['dateLastAccumulatorReset'], equals(secondReset)); |
62 var firstGC = result['dateLastServiceGC']; | 62 var firstGC = result['dateLastServiceGC']; |
63 expect(firstGC, new isInstanceOf<String>()); | 63 expect(firstGC, new isInstanceOf<String>()); |
64 expect(result['heaps'].length, isPositive); | 64 expect(result['heaps'].length, isPositive); |
65 expect(result['heaps']['new']['type'], equals('HeapSpace')); | 65 expect(result['heaps']['new']['type'], equals('HeapSpace')); |
66 expect(result['heaps']['old']['type'], equals('HeapSpace')); | 66 expect(result['heaps']['old']['type'], equals('HeapSpace')); |
67 expect(result['members'].length, isPositive); | 67 expect(result['members'].length, isPositive); |
68 expect(result['members'][0]['type'], equals('ClassHeapStats')); | 68 expect(result['members'][0]['type'], equals('ClassHeapStats')); |
69 | 69 |
70 await sleep(10); | 70 await sleep(1000); |
71 | 71 |
72 result = await isolate.invokeRpcNoUpgrade('_getAllocationProfile', params); | 72 result = await isolate.invokeRpcNoUpgrade('_getAllocationProfile', params); |
73 var secondGC = result['dateLastAccumulatorReset']; | 73 var secondGC = result['dateLastAccumulatorReset']; |
74 expect(secondGC, isNot(equals(firstGC))); | 74 expect(secondGC, isNot(equals(firstGC))); |
75 }, | 75 }, |
76 | 76 |
77 (Isolate isolate) async { | 77 (Isolate isolate) async { |
78 var params = { | 78 var params = { |
79 'reset' : 'banana', | 79 'reset' : 'banana', |
80 }; | 80 }; |
(...skipping 23 matching lines...) Expand all Loading... | |
104 caughtException = true; | 104 caughtException = true; |
105 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 105 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
106 expect(e.data['details'], | 106 expect(e.data['details'], |
107 "_getAllocationProfile: invalid \'gc\' parameter: banana"); | 107 "_getAllocationProfile: invalid \'gc\' parameter: banana"); |
108 } | 108 } |
109 expect(caughtException, isTrue); | 109 expect(caughtException, isTrue); |
110 }, | 110 }, |
111 ]; | 111 ]; |
112 | 112 |
113 main(args) async => runIsolateTests(args, tests); | 113 main(args) async => runIsolateTests(args, tests); |
OLD | NEW |