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

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

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

Powered by Google App Engine
This is Rietveld 408576698