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

Side by Side Diff: tests/standalone/vmservice/test_helper.dart

Issue 22577007: Add verbose output to vmservice tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 vmservice_test_helper; 5 library vmservice_test_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:json' as JSON; 9 import 'dart:json' as JSON;
10 import 'dart:utf' as UTF; 10 import 'dart:utf' as UTF;
11 import 'package:expect/expect.dart'; 11 import 'package:expect/expect.dart';
12 12
13 abstract class VmServiceRequestHelper { 13 abstract class VmServiceRequestHelper {
14 final Uri uri; 14 final Uri uri;
15 final HttpClient client; 15 final HttpClient client;
16 16
17 VmServiceRequestHelper(String url) : 17 VmServiceRequestHelper(String url) :
18 uri = Uri.parse(url), 18 uri = Uri.parse(url),
19 client = new HttpClient(); 19 client = new HttpClient();
20 20
21 Future makeRequest() { 21 Future makeRequest() {
22 return client.getUrl(uri) 22 return client.getUrl(uri)
23 .then((HttpClientRequest request) => request.close()) 23 .then((HttpClientRequest request) => request.close())
24 .then((HttpClientResponse response) { 24 .then((HttpClientResponse response) {
25 return response 25 return response
26 .fold(new BytesBuilder(), (b, d) => b..add(d)) 26 .fold(new BytesBuilder(), (b, d) => b..add(d))
27 .then((builder) { 27 .then((builder) {
28 print('** GET: $uri');
28 _requestCompleted(builder.takeBytes(), response); 29 _requestCompleted(builder.takeBytes(), response);
29 }); 30 });
30 }).catchError((error) { 31 }).catchError((error) {
31 onRequestFailed(error); 32 onRequestFailed(error);
32 }); 33 });
33 } 34 }
34 35
35 void _requestCompleted(List<int> data, HttpClientResponse response) { 36 void _requestCompleted(List<int> data, HttpClientResponse response) {
36 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code'); 37 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code');
37 var replyAsString; 38 var replyAsString;
38 try { 39 try {
39 replyAsString = UTF.decodeUtf8(data, 0, null, null); 40 replyAsString = UTF.decodeUtf8(data, 0, null, null);
40 } catch (e) { 41 } catch (e) {
41 onRequestFailed(e); 42 onRequestFailed(e);
42 return; 43 return;
43 } 44 }
45 print('** Response: $replyAsString');
44 var reply; 46 var reply;
45 try { 47 try {
46 reply = JSON.parse(replyAsString); 48 reply = JSON.parse(replyAsString);
47 } catch (e) { 49 } catch (e) {
48 onRequestFailed(e); 50 onRequestFailed(e);
49 return; 51 return;
50 } 52 }
51 if (reply is! Map) { 53 if (reply is! Map) {
52 onRequestFailed('Reply was not a map: $reply'); 54 onRequestFailed('Reply was not a map: $reply');
53 return; 55 return;
(...skipping 24 matching lines...) Expand all
78 80
79 String get scriptPath { 81 String get scriptPath {
80 var dartScript = Platform.script; 82 var dartScript = Platform.script;
81 var splitPoint = dartScript.lastIndexOf(Platform.pathSeparator); 83 var splitPoint = dartScript.lastIndexOf(Platform.pathSeparator);
82 var scriptDirectory = dartScript.substring(0, splitPoint); 84 var scriptDirectory = dartScript.substring(0, splitPoint);
83 return scriptDirectory + Platform.pathSeparator + script; 85 return scriptDirectory + Platform.pathSeparator + script;
84 } 86 }
85 87
86 Future<int> launch() { 88 Future<int> launch() {
87 String dartExecutable = Platform.executable; 89 String dartExecutable = Platform.executable;
90 print('** Launching $scriptPath');
88 return Process.start(dartExecutable, 91 return Process.start(dartExecutable,
89 ['--enable-vm-service:0', scriptPath]).then((p) { 92 ['--enable-vm-service:0', scriptPath]).then((p) {
90 93
91 Completer completer = new Completer(); 94 Completer completer = new Completer();
92 process = p; 95 process = p;
93 var portNumber; 96 var portNumber;
94 var blank; 97 var blank;
95 var first = true; 98 var first = true;
96 process.stdout.transform(new StringDecoder()) 99 process.stdout.transform(new StringDecoder())
97 .transform(new LineTransformer()).listen((line) { 100 .transform(new LineTransformer()).listen((line) {
98 if (line.startsWith('VmService listening on port ')) { 101 if (line.startsWith('VmService listening on port ')) {
99 RegExp portExp = new RegExp(r"\d+"); 102 RegExp portExp = new RegExp(r"\d+");
100 var port = portExp.stringMatch(line); 103 var port = portExp.stringMatch(line);
101 portNumber = int.parse(port); 104 portNumber = int.parse(port);
102 } 105 }
103 if (line == '') { 106 if (line == '') {
104 // Received blank line. 107 // Received blank line.
105 blank = true; 108 blank = true;
106 } 109 }
107 if (portNumber != null && blank == true && first == true) { 110 if (portNumber != null && blank == true && first == true) {
108 completer.complete(portNumber); 111 completer.complete(portNumber);
109 // Stop repeat completions. 112 // Stop repeat completions.
110 first = false; 113 first = false;
114 print('** Signaled to run test queries on $portNumber');
111 } 115 }
112 print(line); 116 print(line);
113 }); 117 });
114 process.stderr.transform(new StringDecoder()) 118 process.stderr.transform(new StringDecoder())
115 .transform(new LineTransformer()).listen((line) { 119 .transform(new LineTransformer()).listen((line) {
116 print(line); 120 print(line);
117 }); 121 });
118 process.exitCode.then((code) { 122 process.exitCode.then((code) {
119 Expect.equals(0, code, 'Launched dart executable exited with error.'); 123 Expect.equals(0, code, 'Launched dart executable exited with error.');
120 }); 124 });
121 return completer.future; 125 return completer.future;
122 }); 126 });
123 } 127 }
124 128
125 void requestExit() { 129 void requestExit() {
130 print('** Requesting script to exit.');
126 process.stdin.add([32, 13, 10]); 131 process.stdin.add([32, 13, 10]);
127 } 132 }
128 } 133 }
129 134
130 class IsolateListTester { 135 class IsolateListTester {
131 final Map isolateList; 136 final Map isolateList;
132 137
133 IsolateListTester(this.isolateList) { 138 IsolateListTester(this.isolateList) {
134 // The reply is an IsolateList. 139 // The reply is an IsolateList.
135 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); 140 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.');
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if (isolate['id'] == id) { 173 if (isolate['id'] == id) {
169 exists = true; 174 exists = true;
170 Expect.isTrue(isolate['name'].startsWith(name), 175 Expect.isTrue(isolate['name'].startsWith(name),
171 'Isolate $id does not have name prefix: $name' 176 'Isolate $id does not have name prefix: $name'
172 ' (was ${isolate['name']})'); 177 ' (was ${isolate['name']})');
173 } 178 }
174 }); 179 });
175 Expect.isTrue(exists, 'No isolate with id: $id'); 180 Expect.isTrue(exists, 'No isolate with id: $id');
176 } 181 }
177 } 182 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698