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

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

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

Powered by Google App Engine
This is Rietveld 408576698