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

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

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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 'dart:convert'; 7 import 'dart:convert';
8 import 'package:observatory/models.dart' as M; 8 import 'package:observatory/models.dart' as M;
9 import 'package:observatory/service_io.dart'; 9 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 import 'service_test_common.dart'; 11 import 'service_test_common.dart';
12 import 'test_helper.dart'; 12 import 'test_helper.dart';
13 13
14 var tests = [ 14 var tests = [
15 (VM vm) async { 15 (VM vm) async {
16 // Create a new fs. 16 // Create a new fs.
17 var fsName = 'scratch'; 17 var fsName = 'scratch';
18 var result = await vm.invokeRpcNoUpgrade('_createDevFS', { 18 var result = await vm.invokeRpcNoUpgrade('_createDevFS', {
19 'fsName': fsName, 19 'fsName': fsName,
20 }); 20 });
21 expect(result['type'], equals('FileSystem')); 21 expect(result['type'], equals('FileSystem'));
22 expect(result['name'], equals('scratch')); 22 expect(result['name'], equals('scratch'));
23 expect(result['uri'], new isInstanceOf<String>()); 23 expect(result['uri'], new isInstanceOf<String>());
24 var fsUri = result['uri']; 24 var fsUri = result['uri'];
25 25
26 // Spawn a script with a bad uri and make sure that the error is 26 // Spawn a script with a bad uri and make sure that the error is
27 // delivered asynchronously. 27 // delivered asynchronously.
28 Completer completer = new Completer(); 28 Completer completer = new Completer();
29 var sub; 29 var sub;
30 sub = await vm.listenEventStream(VM.kIsolateStream, (ServiceEvent event) { 30 sub = await vm.listenEventStream(
31 if (event.kind == ServiceEvent.kIsolateSpawn) { 31 VM.kIsolateStream,
32 expect(event.spawnToken, equals('someSpawnToken')); 32 (ServiceEvent event) {
33 expect(event.spawnError, 33 if (event.kind == ServiceEvent.kIsolateSpawn) {
34 startsWith('IsolateSpawnException: Unable to spawn isolate: ')); 34 expect(event.spawnToken, equals('someSpawnToken'));
35 expect(event.isolate, isNull); 35 expect(event.spawnError, startsWith(
36 completer.complete(); 36 'IsolateSpawnException: Unable to spawn isolate: '));
37 sub.cancel(); 37 expect(event.isolate, isNull);
38 } 38 completer.complete();
39 }); 39 sub.cancel();
40 }
41 });
40 42
41 result = await vm.invokeRpcNoUpgrade('_spawnUri', { 43 result = await vm.invokeRpcNoUpgrade('_spawnUri', {
42 'token': 'someSpawnToken', 44 'token': 'someSpawnToken',
43 'uri': '${fsUri}doesnotexist.dart', 45 'uri': '${fsUri}doesnotexist.dart',
44 }); 46 });
45 expect(result['type'], equals('Success')); 47 expect(result['type'], equals('Success'));
46 await completer.future; 48 await completer.future;
47 49
48 // Delete the fs. 50 // Delete the fs.
49 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { 51 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
50 'fsName': fsName, 52 'fsName': fsName,
51 }); 53 });
52 expect(result['type'], equals('Success')); 54 expect(result['type'], equals('Success'));
53 }, 55 },
56
54 (VM vm) async { 57 (VM vm) async {
55 // Create a new fs. 58 // Create a new fs.
56 var fsName = 'scratch'; 59 var fsName = 'scratch';
57 var result = await vm.invokeRpcNoUpgrade('_createDevFS', { 60 var result = await vm.invokeRpcNoUpgrade('_createDevFS', {
58 'fsName': fsName, 61 'fsName': fsName,
59 }); 62 });
60 expect(result['type'], equals('FileSystem')); 63 expect(result['type'], equals('FileSystem'));
61 expect(result['name'], equals('scratch')); 64 expect(result['name'], equals('scratch'));
62 expect(result['uri'], new isInstanceOf<String>()); 65 expect(result['uri'], new isInstanceOf<String>());
63 var fsUri = result['uri']; 66 var fsUri = result['uri'];
64 67
65 var filePaths = [ 68 var filePaths = [
66 'devfs_file0.dart', 69 'devfs_file0.dart',
67 'devfs_file1.dart', 70 'devfs_file1.dart',
68 'devfs_file2.dart' 71 'devfs_file2.dart'
69 ]; 72 ];
70 var scripts = [ 73 var scripts = [
71 ''' 74 '''
72 import 'dart:developer'; 75 import 'dart:developer';
73 proofOfLife() => 'I live!'; 76 proofOfLife() => 'I live!';
74 main() { 77 main() {
75 print('HELLO WORLD 1'); 78 print('HELLO WORLD 1');
76 debugger(); 79 debugger();
77 } 80 }
78 ''', 81 ''',
79 ''' 82 '''
80 import 'dart:developer'; 83 import 'dart:developer';
81 var globalArgs; 84 var globalArgs;
82 proofOfLife() => 'I live, \${globalArgs}!'; 85 proofOfLife() => 'I live, \${globalArgs}!';
83 main(args) { 86 main(args) {
84 globalArgs = args; 87 globalArgs = args;
85 print('HELLO WORLD 2'); 88 print('HELLO WORLD 2');
86 debugger(); 89 debugger();
87 } 90 }
88 ''', 91 ''',
89 ''' 92 '''
90 import 'dart:developer'; 93 import 'dart:developer';
91 var globalArgs; 94 var globalArgs;
92 var globalMsg; 95 var globalMsg;
93 proofOfLife() => 'I live, \${globalArgs}, \${globalMsg}!'; 96 proofOfLife() => 'I live, \${globalArgs}, \${globalMsg}!';
94 main(args, msg) { 97 main(args, msg) {
95 globalArgs = args; 98 globalArgs = args;
96 globalMsg = msg; 99 globalMsg = msg;
97 print('HELLO WORLD 3'); 100 print('HELLO WORLD 3');
98 debugger(); 101 debugger();
99 } 102 }
100 ''', 103 ''',
101 ]; 104 ];
102 105
103 // Write three scripts to the fs. 106 // Write three scripts to the fs.
104 for (int i = 0; i < 3; i++) { 107 for (int i = 0; i < 3; i++) {
105 var fileContents = BASE64.encode(UTF8.encode(scripts[i])); 108 var fileContents = BASE64.encode(UTF8.encode(scripts[i]));
106 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', { 109 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', {
107 'fsName': fsName, 110 'fsName': fsName,
108 'path': filePaths[i], 111 'path': filePaths[i],
109 'fileContents': fileContents 112 'fileContents': fileContents
110 }); 113 });
111 expect(result['type'], equals('Success')); 114 expect(result['type'], equals('Success'));
112 } 115 }
113 116
114 // Spawn the script with no arguments or message and make sure 117 // Spawn the script with no arguments or message and make sure
115 // that we are notified. 118 // that we are notified.
116 Completer completer = new Completer(); 119 Completer completer = new Completer();
117 var sub; 120 var sub;
118 sub = await vm.listenEventStream(VM.kIsolateStream, (ServiceEvent event) { 121 sub = await vm.listenEventStream(
119 if (event.kind == ServiceEvent.kIsolateSpawn) { 122 VM.kIsolateStream,
120 expect(event.spawnToken, equals('mySpawnToken0')); 123 (ServiceEvent event) {
121 expect(event.isolate, isNotNull); 124 if (event.kind == ServiceEvent.kIsolateSpawn) {
122 expect(event.isolate.name, equals('devfs_file0.dart\$main')); 125 expect(event.spawnToken, equals('mySpawnToken0'));
123 completer.complete(event.isolate); 126 expect(event.isolate, isNotNull);
124 sub.cancel(); 127 expect(event.isolate.name, equals('devfs_file0.dart\$main'));
125 } 128 completer.complete(event.isolate);
126 }); 129 sub.cancel();
130 }
131 });
127 result = await vm.invokeRpcNoUpgrade('_spawnUri', { 132 result = await vm.invokeRpcNoUpgrade('_spawnUri', {
128 'token': 'mySpawnToken0', 133 'token': 'mySpawnToken0',
129 'uri': '${fsUri}${filePaths[0]}', 134 'uri': '${fsUri}${filePaths[0]}',
130 }); 135 });
131 expect(result['type'], equals('Success')); 136 expect(result['type'], equals('Success'));
132 var spawnedIsolate = await completer.future; 137 var spawnedIsolate = await completer.future;
133 138
134 // Wait for the spawned isolate to hit a breakpoint. 139 // Wait for the spawned isolate to hit a breakpoint.
135 await spawnedIsolate.load(); 140 await spawnedIsolate.load();
136 await hasStoppedAtBreakpoint(spawnedIsolate); 141 await hasStoppedAtBreakpoint(spawnedIsolate);
137 142
138 // Make sure that we are running code from the spawned isolate. 143 // Make sure that we are running code from the spawned isolate.
139 result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()'); 144 result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()');
140 expect(result.type, equals('Instance')); 145 expect(result.type, equals('Instance'));
141 expect(result.kind, equals(M.InstanceKind.string)); 146 expect(result.kind, equals(M.InstanceKind.string));
142 expect(result.valueAsString, equals('I live!')); 147 expect(result.valueAsString, equals('I live!'));
143 148
144 // Spawn the script with arguments. 149 // Spawn the script with arguments.
145 completer = new Completer(); 150 completer = new Completer();
146 sub = await vm.listenEventStream(VM.kIsolateStream, (ServiceEvent event) { 151 sub = await vm.listenEventStream(
147 if (event.kind == ServiceEvent.kIsolateSpawn) { 152 VM.kIsolateStream,
148 expect(event.spawnToken, equals('mySpawnToken1')); 153 (ServiceEvent event) {
149 expect(event.isolate, isNotNull); 154 if (event.kind == ServiceEvent.kIsolateSpawn) {
150 expect(event.isolate.name, equals('devfs_file1.dart\$main')); 155 expect(event.spawnToken, equals('mySpawnToken1'));
151 completer.complete(event.isolate); 156 expect(event.isolate, isNotNull);
152 sub.cancel(); 157 expect(event.isolate.name, equals('devfs_file1.dart\$main'));
153 } 158 completer.complete(event.isolate);
154 }); 159 sub.cancel();
160 }
161 });
155 result = await vm.invokeRpcNoUpgrade('_spawnUri', { 162 result = await vm.invokeRpcNoUpgrade('_spawnUri', {
156 'token': 'mySpawnToken1', 163 'token': 'mySpawnToken1',
157 'uri': '${fsUri}${filePaths[1]}', 164 'uri': '${fsUri}${filePaths[1]}',
158 'args': ['one', 'two', 'three'] 165 'args': ['one', 'two', 'three']
159 }); 166 });
160 expect(result['type'], equals('Success')); 167 expect(result['type'], equals('Success'));
161 spawnedIsolate = await completer.future; 168 spawnedIsolate = await completer.future;
162 169
163 // Wait for the spawned isolate to hit a breakpoint. 170 // Wait for the spawned isolate to hit a breakpoint.
164 await spawnedIsolate.load(); 171 await spawnedIsolate.load();
165 await hasStoppedAtBreakpoint(spawnedIsolate); 172 await hasStoppedAtBreakpoint(spawnedIsolate);
166 173
167 // Make sure that we are running code from the spawned isolate. 174 // Make sure that we are running code from the spawned isolate.
168 result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()'); 175 result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()');
169 expect(result.type, equals('Instance')); 176 expect(result.type, equals('Instance'));
170 expect(result.kind, equals(M.InstanceKind.string)); 177 expect(result.kind, equals(M.InstanceKind.string));
171 expect(result.valueAsString, equals('I live, [one, two, three]!')); 178 expect(result.valueAsString, equals('I live, [one, two, three]!'));
172 179
173 // Spawn the script with arguments and message 180 // Spawn the script with arguments and message
174 completer = new Completer(); 181 completer = new Completer();
175 sub = await vm.listenEventStream(VM.kIsolateStream, (ServiceEvent event) { 182 sub = await vm.listenEventStream(
176 if (event.kind == ServiceEvent.kIsolateSpawn) { 183 VM.kIsolateStream,
177 expect(event.spawnToken, equals('mySpawnToken2')); 184 (ServiceEvent event) {
178 expect(event.isolate, isNotNull); 185 if (event.kind == ServiceEvent.kIsolateSpawn) {
179 expect(event.isolate.name, equals('devfs_file2.dart\$main')); 186 expect(event.spawnToken, equals('mySpawnToken2'));
180 completer.complete(event.isolate); 187 expect(event.isolate, isNotNull);
181 sub.cancel(); 188 expect(event.isolate.name, equals('devfs_file2.dart\$main'));
182 } 189 completer.complete(event.isolate);
183 }); 190 sub.cancel();
191 }
192 });
184 result = await vm.invokeRpcNoUpgrade('_spawnUri', { 193 result = await vm.invokeRpcNoUpgrade('_spawnUri', {
185 'token': 'mySpawnToken2', 194 'token': 'mySpawnToken2',
186 'uri': '${fsUri}${filePaths[2]}', 195 'uri': '${fsUri}${filePaths[2]}',
187 'args': ['A', 'B', 'C'], 196 'args': ['A', 'B', 'C'],
188 'message': 'test' 197 'message': 'test'
189 }); 198 });
190 expect(result['type'], equals('Success')); 199 expect(result['type'], equals('Success'));
191 spawnedIsolate = await completer.future; 200 spawnedIsolate = await completer.future;
192 201
193 // Wait for the spawned isolate to hit a breakpoint. 202 // Wait for the spawned isolate to hit a breakpoint.
194 await spawnedIsolate.load(); 203 await spawnedIsolate.load();
195 await hasStoppedAtBreakpoint(spawnedIsolate); 204 await hasStoppedAtBreakpoint(spawnedIsolate);
196 205
197 // Make sure that we are running code from the spawned isolate. 206 // Make sure that we are running code from the spawned isolate.
198 result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()'); 207 result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()');
199 expect(result.type, equals('Instance')); 208 expect(result.type, equals('Instance'));
200 expect(result.kind, equals(M.InstanceKind.string)); 209 expect(result.kind, equals(M.InstanceKind.string));
201 expect(result.valueAsString, equals('I live, [A, B, C], test!')); 210 expect(result.valueAsString, equals('I live, [A, B, C], test!'));
202 211
203 // Delete the fs. 212 // Delete the fs.
204 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { 213 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
205 'fsName': fsName, 214 'fsName': fsName,
206 }); 215 });
207 expect(result['type'], equals('Success')); 216 expect(result['type'], equals('Success'));
208 }, 217 },
209 ]; 218 ];
210 219
211 main(args) async => runVMTests(args, tests); 220 main(args) async => runVMTests(args, tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698