Skip to content

Commit 166c5d7

Browse files
mkustermannCommit Queue
authored andcommitted
[vm] Add test for dart:developer registerExtension() method
There was a bugfix in [0] to ensure the passed closure is invoked in the right zone, but it was missing a test. There seems to be also no other tests of `registerExtension()`. => So we'll add a test in this CL. [0] https://dart-review.googlesource.com/c/sdk/+/275842 Issue #53178 Issue flutter/flutter#93676 TEST=dart/flutter_regress_93676_test Change-Id: Ibfdf15026b36beff1db9cef30c69a052b9efc77d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319940 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Tess Strickland <[email protected]>
1 parent 58f4b3a commit 166c5d7

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2023, 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:io';
7+
8+
import 'package:expect/expect.dart';
9+
import 'package:path/path.dart' as path;
10+
11+
import 'isolates/reload_utils.dart';
12+
13+
Future main() async {
14+
if (!currentVmSupportsReload) return;
15+
16+
await withTempDir((String tempDir) async {
17+
final filename = path.join(tempDir, 'testee.dart');
18+
File(filename).writeAsStringSync(dartTestFile('AA', 'BB'));
19+
20+
final helper = await launchOn(filename);
21+
await helper.waitUntilStdoutContains('READY :-)');
22+
23+
final json = await helper.invokeServiceExtension('ext.myextension');
24+
print('Got result: "$json"');
25+
Expect.isTrue(json['identical'] as bool);
26+
Expect.equals('BB', json['value']);
27+
28+
final int exitCode = await helper.close();
29+
Expect.equals(0, exitCode);
30+
});
31+
}
32+
33+
String dartTestFile(String zoneKey, String zoneValue) => '''
34+
import 'dart:async';
35+
import 'dart:convert';
36+
import 'dart:isolate';
37+
import 'dart:developer';
38+
39+
const token = '__token__';
40+
41+
void main() {
42+
print('Waiting for reload');
43+
final rp = ReceivePort();
44+
runZoned(() {
45+
final expectedZone = Zone.current;
46+
registerExtension('ext.myextension', (_, __) async {
47+
final zonesIdentical = identical(expectedZone, Zone.current);
48+
final zoneValue = Zone.current['$zoneKey'];
49+
final result = {
50+
'identical': zonesIdentical,
51+
'value' : '$zoneValue',
52+
};
53+
rp.close();
54+
return ServiceExtensionResponse.result(json.encode(result));
55+
});
56+
}, zoneValues: {'$zoneKey': '$zoneValue'});
57+
print('READY :-)');
58+
}
59+
''';

‎runtime/tests/vm/dart/isolates/reload_utils.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ class Reloader {
181181
await _process.stdin.flush();
182182
}
183183

184+
Future<Map> invokeServiceExtension(String method, [Object? arguments]) async {
185+
arguments ??= {'isolateId': await _remoteVm.mainId};
186+
print('Invoking "$method" service extension');
187+
return await _remoteVm.rpc.sendRequest(method, arguments);
188+
}
189+
184190
Future<Map> reload(String file) async {
185191
print('Reload $file (version: ${_reloadVersion++})');
186192
final Map reloadResult = await _remoteVm.reload(Uri.parse(file));

‎runtime/tests/vm/vm.status‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ dart_2/transferable_throws_oom_test: SkipByDesign # This test tries to allocate
171171
[ $sanitizer == tsan ]
172172
dart/analyze_snapshot_binary_test: SkipSlow
173173
dart/appjit_cha_deopt_test: SkipSlow
174+
dart/flutter_regress_93676_test: Pass, Slow
174175
dart/gc/chunked_binary_trees_array_test: SkipSlow
175176
dart/gc/chunked_binary_trees_test: SkipSlow
176177
dart/gc/fragmentation*: Skip # Uses too much memory with TSAN overhead and kills bot

0 commit comments

Comments
 (0)