Skip to content

Commit fb9c139

Browse files
bkonyiCommit Bot
authored andcommitted
[ package:vm_service ] Add external compilation service tests
These tests are ported from pkg/dds/test/external_compilation_service_* Fixes #47170 Change-Id: I2b538ce8757f7370631ece752862032c115db12a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240301 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
1 parent 4c4e070 commit fb9c139

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2022, 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+
5+
import 'dart:developer';
6+
7+
main() {
8+
debugger();
9+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) 2022, 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+
5+
import 'dart:async';
6+
import 'dart:convert';
7+
import 'dart:io';
8+
9+
import 'package:test/test.dart';
10+
import 'package:vm_service/vm_service.dart';
11+
import 'package:vm_service/vm_service_io.dart';
12+
13+
late Uri remoteVmServiceUri;
14+
15+
Future<Process> spawnDartProcess(String script) async {
16+
final executable = Platform.executable;
17+
final tmpDir = await Directory.systemTemp.createTemp('dart_service');
18+
final serviceInfoUri = tmpDir.uri.resolve('service_info.json');
19+
final serviceInfoFile = await File.fromUri(serviceInfoUri).create();
20+
21+
final arguments = [
22+
'--disable-dart-dev',
23+
'--observe=0',
24+
'--disable-service-auth-codes',
25+
'--write-service-info=$serviceInfoUri',
26+
...Platform.executableArguments,
27+
Platform.script.resolve(script).toString(),
28+
];
29+
final process = await Process.start(executable, arguments);
30+
process.stdout
31+
.transform(utf8.decoder)
32+
.listen((line) => print('TESTEE OUT: $line'));
33+
process.stderr
34+
.transform(utf8.decoder)
35+
.listen((line) => print('TESTEE ERR: $line'));
36+
while ((await serviceInfoFile.length()) <= 5) {
37+
await Future.delayed(const Duration(milliseconds: 50));
38+
}
39+
final content = await serviceInfoFile.readAsString();
40+
final infoJson = json.decode(content);
41+
remoteVmServiceUri =
42+
Uri.parse(infoJson['uri']).replace(scheme: 'ws', path: 'ws');
43+
return process;
44+
}
45+
46+
Future<void> waitForRunnableIsolate(VmService service, Isolate isolate) async {
47+
bool runnable = isolate.runnable!;
48+
while (!runnable) {
49+
await Future.delayed(const Duration(milliseconds: 100));
50+
runnable = (await service.getIsolate(isolate.id!)).runnable!;
51+
}
52+
}
53+
54+
void main() {
55+
group('VM Service', () {
56+
late Process process;
57+
58+
setUp(() async {
59+
process =
60+
await spawnDartProcess('external_compilation_service_script.dart');
61+
});
62+
63+
tearDown(() async {
64+
process.kill();
65+
});
66+
67+
test('evaluate invokes client provided compileExpression RPC', () async {
68+
final service = await vmServiceConnectUri(remoteVmServiceUri.toString());
69+
await service.registerService(
70+
'compileExpression',
71+
'Custom Expression Compilation',
72+
);
73+
bool invokedCompileExpression = false;
74+
service.registerServiceCallback('compileExpression', (params) async {
75+
invokedCompileExpression = true;
76+
throw 'error';
77+
});
78+
final vm = await service.getVM();
79+
final isolate = await service.getIsolate(vm.isolates!.first.id!);
80+
await waitForRunnableIsolate(service, isolate);
81+
try {
82+
await service.evaluate(
83+
isolate.id!, isolate.libraries!.first.id!, '1 + 1');
84+
} catch (_) {
85+
// ignore error
86+
}
87+
expect(invokedCompileExpression, true);
88+
});
89+
90+
test('evaluateInFrame invokes client provided compileExpression RPC',
91+
() async {
92+
final service = await vmServiceConnectUri(remoteVmServiceUri.toString());
93+
await service.registerService(
94+
'compileExpression',
95+
'Custom Expression Compilation',
96+
);
97+
bool invokedCompileExpression = false;
98+
service.registerServiceCallback('compileExpression', (params) async {
99+
invokedCompileExpression = true;
100+
throw 'error';
101+
});
102+
final vm = await service.getVM();
103+
final isolate = await service.getIsolate(vm.isolates!.first.id!);
104+
await waitForRunnableIsolate(service, isolate);
105+
try {
106+
await service.evaluateInFrame(isolate.id!, 0, '1 + 1');
107+
} catch (e) {
108+
// ignore error
109+
}
110+
expect(invokedCompileExpression, true);
111+
});
112+
});
113+
}

0 commit comments

Comments
 (0)