Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: runtime/observatory/tests/service/test_helper.dart

Issue 1318823002: Use --trace-service to help diagnose flaky tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/observatory/tests/service/pause_on_start_then_step_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 4
5 library test_helper; 5 library test_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'package:observatory/service_io.dart'; 10 import 'package:observatory/service_io.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 bool _isWebSocketDisconnect(e) { 13 bool _isWebSocketDisconnect(e) {
14 return e is NetworkRpcException; 14 return e is NetworkRpcException;
15 } 15 }
16 16
17 // This invocation should set up the state being tested. 17 // This invocation should set up the state being tested.
18 const String _TESTEE_MODE_FLAG = "--testee-mode"; 18 const String _TESTEE_MODE_FLAG = "--testee-mode";
19 19
20 class _TestLauncher { 20 class _TestLauncher {
21 Process process; 21 Process process;
22 final List<String> args; 22 final List<String> args;
23 bool killedByTester = false; 23 bool killedByTester = false;
24 24
25 _TestLauncher() : args = ['--enable-vm-service:0', 25 _TestLauncher() : args = ['--enable-vm-service:0',
26 Platform.script.toFilePath(), 26 Platform.script.toFilePath(),
27 _TESTEE_MODE_FLAG] {} 27 _TESTEE_MODE_FLAG] {}
28 28
29 Future<int> launch(bool pause_on_start, bool pause_on_exit) { 29 Future<int> launch(bool pause_on_start, bool pause_on_exit, bool trace_service ) {
30 assert(pause_on_start != null);
31 assert(pause_on_exit != null);
32 assert(trace_service != null);
30 String dartExecutable = Platform.executable; 33 String dartExecutable = Platform.executable;
31 var fullArgs = []; 34 var fullArgs = [];
32 if (pause_on_start == true) { 35 if (trace_service) {
36 fullArgs.add('--trace-service');
37 }
38 if (pause_on_start) {
33 fullArgs.add('--pause-isolates-on-start'); 39 fullArgs.add('--pause-isolates-on-start');
34 } 40 }
35 if (pause_on_exit == true) { 41 if (pause_on_exit) {
36 fullArgs.add('--pause-isolates-on-exit'); 42 fullArgs.add('--pause-isolates-on-exit');
37 } 43 }
38 fullArgs.addAll(Platform.executableArguments); 44 fullArgs.addAll(Platform.executableArguments);
39 fullArgs.addAll(args); 45 fullArgs.addAll(args);
40 print('** Launching $dartExecutable ${fullArgs.join(' ')}'); 46 print('** Launching $dartExecutable ${fullArgs.join(' ')}');
41 return Process.start(dartExecutable, fullArgs).then((p) { 47 return Process.start(dartExecutable, fullArgs).then((p) {
42 48
43 Completer completer = new Completer(); 49 Completer completer = new Completer();
44 process = p; 50 process = p;
45 var portNumber; 51 var portNumber;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 101
96 /// Runs [tests] in sequence, each of which should take an [Isolate] and 102 /// Runs [tests] in sequence, each of which should take an [Isolate] and
97 /// return a [Future]. Code for setting up state can run before and/or 103 /// return a [Future]. Code for setting up state can run before and/or
98 /// concurrently with the tests. Uses [mainArgs] to determine whether 104 /// concurrently with the tests. Uses [mainArgs] to determine whether
99 /// to run tests or testee in this invokation of the script. 105 /// to run tests or testee in this invokation of the script.
100 void runIsolateTests(List<String> mainArgs, 106 void runIsolateTests(List<String> mainArgs,
101 List<IsolateTest> tests, 107 List<IsolateTest> tests,
102 {void testeeBefore(), 108 {void testeeBefore(),
103 void testeeConcurrent(), 109 void testeeConcurrent(),
104 bool pause_on_start: false, 110 bool pause_on_start: false,
105 bool pause_on_exit: false}) { 111 bool pause_on_exit: false,
112 bool trace_service: false}) {
106 assert(!pause_on_start || testeeBefore == null); 113 assert(!pause_on_start || testeeBefore == null);
107 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { 114 if (mainArgs.contains(_TESTEE_MODE_FLAG)) {
108 if (!pause_on_start) { 115 if (!pause_on_start) {
109 if (testeeBefore != null) { 116 if (testeeBefore != null) {
110 testeeBefore(); 117 testeeBefore();
111 } 118 }
112 print(''); // Print blank line to signal that we are ready. 119 print(''); // Print blank line to signal that we are ready.
113 } 120 }
114 if (testeeConcurrent != null) { 121 if (testeeConcurrent != null) {
115 testeeConcurrent(); 122 testeeConcurrent();
116 } 123 }
117 if (!pause_on_exit) { 124 if (!pause_on_exit) {
118 // Wait around for the process to be killed. 125 // Wait around for the process to be killed.
119 stdin.first.then((_) => exit(0)); 126 stdin.first.then((_) => exit(0));
120 } 127 }
121 } else { 128 } else {
122 var process = new _TestLauncher(); 129 var process = new _TestLauncher();
123 process.launch(pause_on_start, pause_on_exit).then((port) { 130 process.launch(pause_on_start, pause_on_exit, trace_service).then((port) {
124 if (mainArgs.contains("--gdb")) { 131 if (mainArgs.contains("--gdb")) {
125 port = 8181; 132 port = 8181;
126 } 133 }
127 String addr = 'ws://localhost:$port/ws'; 134 String addr = 'ws://localhost:$port/ws';
128 serviceHttpAddress = 'http://localhost:$port'; 135 serviceHttpAddress = 'http://localhost:$port';
129 var testIndex = 1; 136 var testIndex = 1;
130 var totalTests = tests.length; 137 var totalTests = tests.length;
131 var name = Platform.script.pathSegments.last; 138 var name = Platform.script.pathSegments.last;
132 runZoned(() { 139 runZoned(() {
133 new WebSocketVM(new WebSocketVMTarget(addr)).load() 140 new WebSocketVM(new WebSocketVMTarget(addr)).load()
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 277
271 /// Runs [tests] in sequence, each of which should take an [Isolate] and 278 /// Runs [tests] in sequence, each of which should take an [Isolate] and
272 /// return a [Future]. Code for setting up state can run before and/or 279 /// return a [Future]. Code for setting up state can run before and/or
273 /// concurrently with the tests. Uses [mainArgs] to determine whether 280 /// concurrently with the tests. Uses [mainArgs] to determine whether
274 /// to run tests or testee in this invokation of the script. 281 /// to run tests or testee in this invokation of the script.
275 Future runVMTests(List<String> mainArgs, 282 Future runVMTests(List<String> mainArgs,
276 List<VMTest> tests, 283 List<VMTest> tests,
277 {Future testeeBefore(), 284 {Future testeeBefore(),
278 Future testeeConcurrent(), 285 Future testeeConcurrent(),
279 bool pause_on_start: false, 286 bool pause_on_start: false,
280 bool pause_on_exit: false}) async { 287 bool pause_on_exit: false,
288 bool trace_service: false}) async {
281 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { 289 if (mainArgs.contains(_TESTEE_MODE_FLAG)) {
282 if (!pause_on_start) { 290 if (!pause_on_start) {
283 if (testeeBefore != null) { 291 if (testeeBefore != null) {
284 await testeeBefore(); 292 await testeeBefore();
285 } 293 }
286 print(''); // Print blank line to signal that we are ready. 294 print(''); // Print blank line to signal that we are ready.
287 } 295 }
288 if (testeeConcurrent != null) { 296 if (testeeConcurrent != null) {
289 await testeeConcurrent(); 297 await testeeConcurrent();
290 } 298 }
291 if (!pause_on_exit) { 299 if (!pause_on_exit) {
292 // Wait around for the process to be killed. 300 // Wait around for the process to be killed.
293 stdin.first.then((_) => exit(0)); 301 stdin.first.then((_) => exit(0));
294 } 302 }
295 } else { 303 } else {
296 var process = new _TestLauncher(); 304 var process = new _TestLauncher();
297 process.launch(pause_on_start, pause_on_exit).then((port) async { 305 process.launch(pause_on_start,
306 pause_on_exit,
307 trace_service).then((port) async {
298 if (mainArgs.contains("--gdb")) { 308 if (mainArgs.contains("--gdb")) {
299 port = 8181; 309 port = 8181;
300 } 310 }
301 String addr = 'ws://localhost:$port/ws'; 311 String addr = 'ws://localhost:$port/ws';
302 serviceHttpAddress = 'http://localhost:$port'; 312 serviceHttpAddress = 'http://localhost:$port';
303 var testIndex = 1; 313 var testIndex = 1;
304 var totalTests = tests.length; 314 var totalTests = tests.length;
305 var name = Platform.script.pathSegments.last; 315 var name = Platform.script.pathSegments.last;
306 runZoned(() { 316 runZoned(() {
307 new WebSocketVM(new WebSocketVMTarget(addr)).load() 317 new WebSocketVM(new WebSocketVMTarget(addr)).load()
308 .then((VM vm) => Future.forEach(tests, (test) { 318 .then((VM vm) => Future.forEach(tests, (test) {
309 print('Running $name [$testIndex/$totalTests]'); 319 print('Running $name [$testIndex/$totalTests]');
310 testIndex++; 320 testIndex++;
311 return test(vm); 321 return test(vm);
312 })).then((_) => process.requestExit()); 322 })).then((_) => process.requestExit());
313 }, onError: (e, st) { 323 }, onError: (e, st) {
314 process.requestExit(); 324 process.requestExit();
315 if (!_isWebSocketDisconnect(e)) { 325 if (!_isWebSocketDisconnect(e)) {
316 print('Unexpected exception in service tests: $e $st'); 326 print('Unexpected exception in service tests: $e $st');
317 throw e; 327 throw e;
318 } 328 }
319 }); 329 });
320 }); 330 });
321 } 331 }
322 } 332 }
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/pause_on_start_then_step_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698