OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'dart:async'; |
| 7 import 'dart:developer'; |
| 8 import 'package:observatory/service_io.dart'; |
| 9 import 'package:unittest/unittest.dart'; |
| 10 import 'service_test_common.dart'; |
| 11 import 'test_helper.dart'; |
| 12 |
| 13 primeDartTimeline() { |
| 14 while (true) { |
| 15 Timeline.startSync('apple'); |
| 16 Timeline.finishSync(); |
| 17 } |
| 18 } |
| 19 |
| 20 bool isDart(Map event) => event['cat'] == 'Dart'; |
| 21 |
| 22 List<Map> filterEvents(List<Map> events, filter) { |
| 23 return events.where(filter).toList(); |
| 24 } |
| 25 |
| 26 Completer completer = new Completer(); |
| 27 int eventCount = 0; |
| 28 |
| 29 onTimelineEvent(ServiceEvent event) { |
| 30 eventCount++; |
| 31 expect(filterEvents(event.timelineEvents, isDart).length, greaterThan(0)); |
| 32 if (eventCount == 5) { |
| 33 completer.complete(eventCount); |
| 34 } |
| 35 } |
| 36 |
| 37 var tests = [ |
| 38 (Isolate isolate) async { |
| 39 // Subscribe to the Timeline stream. |
| 40 await subscribeToStream(isolate.vm, VM.kTimelineStream, onTimelineEvent); |
| 41 }, |
| 42 (Isolate isolate) async { |
| 43 // Ensure we don't get any events before enabling Dart. |
| 44 await new Future.delayed(new Duration(seconds: 5)); |
| 45 expect(eventCount, 0); |
| 46 }, |
| 47 (Isolate isolate) async { |
| 48 // Get the flags. |
| 49 Map flags = await isolate.vm.invokeRpcNoUpgrade('_getVMTimelineFlags', {}); |
| 50 expect(flags['type'], 'TimelineFlags'); |
| 51 // Confirm that 'Dart' is available. |
| 52 expect(flags['availableStreams'].contains('Dart'), isTrue); |
| 53 // Confirm that nothing is being recorded. |
| 54 expect(flags['recordedStreams'].length, equals(0)); |
| 55 }, |
| 56 (Isolate isolate) async { |
| 57 // Enable the Dart category. |
| 58 await isolate.vm.invokeRpcNoUpgrade('_setVMTimelineFlags', { |
| 59 "recordedStreams": ["Dart"] |
| 60 }); |
| 61 }, |
| 62 (Isolate isolate) async { |
| 63 // Wait to receive events. |
| 64 await completer.future; |
| 65 cancelStreamSubscription(VM.kTimelineStream); |
| 66 }, |
| 67 ]; |
| 68 |
| 69 main(args) async => runIsolateTests(args, |
| 70 tests, |
| 71 testeeConcurrent: primeDartTimeline); |
OLD | NEW |