Skip to content

Commit

Permalink
Partial static mode changes for vm-service and tests (part 2).
Browse files Browse the repository at this point in the history
Bug: #31587
Change-Id: Ie2605f5043b9f5d2f9156928e3cd39f74e726853
Reviewed-on: https://dart-review.googlesource.com/30681
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
rmacnak-google authored and commit-bot@chromium.org committed Dec 20, 2017
1 parent 4e8c6e7 commit 9f4ffb6
Show file tree
Hide file tree
Showing 23 changed files with 77 additions and 70 deletions.
6 changes: 3 additions & 3 deletions runtime/bin/vmservice/vmservice_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ Future<List<int>> readFileCallback(Uri path) async {
return await file.readAsBytes();
}

Future<List<Map<String, String>>> listFilesCallback(Uri dirPath) async {
Future<List<Map<String, dynamic>>> listFilesCallback(Uri dirPath) async {
var dir = new Directory.fromUri(dirPath);
var dirPathStr = dirPath.path;
var stream = dir.list(recursive: true);
var result = <Map<String, String>>[];
var result = <Map<String, dynamic>>[];
await for (var fileEntity in stream) {
var filePath = new Uri.file(fileEntity.path).path;
var stat = await fileEntity.stat();
if (stat.type == FileSystemEntityType.FILE &&
filePath.startsWith(dirPathStr)) {
var map = {};
var map = <String, dynamic>{};
map['name'] = '/' + filePath.substring(dirPathStr.length);
map['size'] = stat.size;
map['modified'] = stat.modified.millisecondsSinceEpoch;
Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/lib/object_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ class ObjectGraph {
assert(parent[v] != SENTINEL);
}
return true;
});
}());

if (dfsNumber != N) {
// Remove successors of unconnected nodes
Expand Down
4 changes: 2 additions & 2 deletions runtime/observatory/lib/service_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ abstract class CommonWebSocketVM extends VM {
try {
_webSocket.connect(
target.networkAddress, _onOpen, _onMessage, _onError, _onClose);
} catch (_) {
} catch (_, stack) {
_webSocket = null;
var exception = new NetworkRpcException('WebSocket closed');
return new Future.error(exception);
return new Future.error(exception, stack);
}
}
if (_disconnected.isCompleted) {
Expand Down
10 changes: 5 additions & 5 deletions runtime/observatory/lib/src/service/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ class _EventStreamState {
return new Future.value(null);
}

Future<Stream> addStream() async {
Future<Stream<ServiceEvent>> addStream() async {
var controller;
controller =
new StreamController(onCancel: () => _cancelController(controller));
controller = new StreamController<ServiceEvent>(
onCancel: () => _cancelController(controller));
_controllers.add(controller);
if (_cancelFuture != null) {
try {
Expand Down Expand Up @@ -934,12 +934,12 @@ abstract class VM extends ServiceObjectOwner implements M.VM {
static const kServiceStream = '_Service';

/// Returns a single-subscription Stream object for a VM event stream.
Future<Stream> getEventStream(String streamId) async {
Future<Stream<ServiceEvent>> getEventStream(String streamId) async {
var eventStream = _eventStreams.putIfAbsent(
streamId,
() => new _EventStreamState(
this, streamId, () => _eventStreams.remove(streamId)));
Stream stream = await eventStream.addStream();
Stream<ServiceEvent> stream = await eventStream.addStream();
return stream;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Utils {
static bool runningInJavaScript() => identical(1.0, 1);

static formatStringAsLiteral(String value, [bool wasTruncated = false]) {
var result = new List();
var result = new List<int>();
result.add("'".codeUnitAt(0));
for (int codeUnit in value.codeUnits) {
if (codeUnit == '\n'.codeUnitAt(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var tests = <IsolateTest>[
}
if (event.kind == ServiceEvent.kPauseBreakpoint) {
subscription.cancel();
completer.complete(null);
completer.complete();
}
});
await isolate.resume();
Expand All @@ -85,7 +85,7 @@ var tests = <IsolateTest>[
subscription = stream.listen((ServiceEvent event) async {
if (event.kind == ServiceEvent.kPauseBreakpoint) {
subscription.cancel();
completer.complete(null);
completer.complete();
}
});
await isolate.resume();
Expand Down Expand Up @@ -132,7 +132,7 @@ var tests = <IsolateTest>[
}
if (event.kind == ServiceEvent.kPauseBreakpoint) {
subscription.cancel();
completer.complete(null);
completer.complete();
}
});
await isolate.resume();
Expand All @@ -156,7 +156,7 @@ var tests = <IsolateTest>[
subscription = stream.listen((ServiceEvent event) async {
if (event.kind == ServiceEvent.kPauseBreakpoint) {
subscription.cancel();
completer.complete(null);
completer.complete();
}
});
await isolate.resume();
Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/tests/service/crash_dump_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var tests = <VMTest>[
await client.getUrl(Uri.parse('$serviceHttpAddress/_getCrashDump'));
var response = await request.close();
print('Received response');
Completer completer = new Completer();
Completer completer = new Completer<String>();
StringBuffer sb = new StringBuffer();
response.transform(UTF8.decoder).listen((chunk) {
sb.write(chunk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:unittest/unittest.dart';
import 'test_helper.dart';

Future<String> readResponse(HttpClientResponse response) {
var completer = new Completer();
var completer = new Completer<String>();
var contents = new StringBuffer();
response.transform(UTF8.decoder).listen((String data) {
contents.write(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:unittest/unittest.dart';
import 'test_helper.dart';

Future<String> readResponse(HttpClientResponse response) {
var completer = new Completer();
var completer = new Completer<String>();
var contents = new StringBuffer();
response.transform(UTF8.decoder).listen((String data) {
contents.write(data);
Expand Down
27 changes: 15 additions & 12 deletions runtime/observatory/tests/service/dev_fs_spawn_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ main(args, msg) {
await hasStoppedAtBreakpoint(spawnedIsolate);

// Make sure that we are running code from the spawned isolate.
result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()');
expect(result.type, equals('Instance'));
expect(result.kind, equals(M.InstanceKind.string));
expect(result.valueAsString, equals('I live!'));
var instance = (await spawnedIsolate.rootLibrary.evaluate('proofOfLife()'))
as Instance;
expect(instance.type, equals('Instance'));
expect(instance.kind, equals(M.InstanceKind.string));
expect(instance.valueAsString, equals('I live!'));

// Spawn the script with arguments.
completer = new Completer();
Expand All @@ -165,10 +166,11 @@ main(args, msg) {
await hasStoppedAtBreakpoint(spawnedIsolate);

// Make sure that we are running code from the spawned isolate.
result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()');
expect(result.type, equals('Instance'));
expect(result.kind, equals(M.InstanceKind.string));
expect(result.valueAsString, equals('I live, [one, two, three]!'));
instance = (await spawnedIsolate.rootLibrary.evaluate('proofOfLife()'))
as Instance;
expect(instance.type, equals('Instance'));
expect(instance.kind, equals(M.InstanceKind.string));
expect(instance.valueAsString, equals('I live, [one, two, three]!'));

// Spawn the script with arguments and message
completer = new Completer();
Expand All @@ -195,10 +197,11 @@ main(args, msg) {
await hasStoppedAtBreakpoint(spawnedIsolate);

// Make sure that we are running code from the spawned isolate.
result = await spawnedIsolate.rootLibrary.evaluate('proofOfLife()');
expect(result.type, equals('Instance'));
expect(result.kind, equals(M.InstanceKind.string));
expect(result.valueAsString, equals('I live, [A, B, C], test!'));
instance = (await spawnedIsolate.rootLibrary.evaluate('proofOfLife()'))
as Instance;
expect(instance.type, equals('Instance'));
expect(instance.kind, equals(M.InstanceKind.string));
expect(instance.valueAsString, equals('I live, [A, B, C], test!'));

// Delete the fs.
result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/tests/service/dev_fs_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:unittest/unittest.dart';
import 'test_helper.dart';

Future<String> readResponse(HttpClientResponse response) {
var completer = new Completer();
var completer = new Completer<String>();
var contents = new StringBuffer();
response.transform(UTF8.decoder).listen((String data) {
contents.write(data);
Expand Down
4 changes: 2 additions & 2 deletions runtime/observatory/tests/service/echo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import 'test_helper.dart';

var tests = <IsolateTest>[
(Isolate isolate) =>
isolate.vm.invokeRpc('_echo', {'text': 'hello'}).then((result) {
isolate.vm.invokeRpcNoUpgrade('_echo', {'text': 'hello'}).then((result) {
expect(result['type'], equals('_EchoResponse'));
expect(result['text'], equals('hello'));
}),
(Isolate isolate) =>
isolate.invokeRpc('_echo', {'text': 'hello'}).then((result) {
isolate.invokeRpcNoUpgrade('_echo', {'text': 'hello'}).then((result) {
expect(result['type'], equals('_EchoResponse'));
expect(result['text'], equals('hello'));
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var tests = <IsolateTest>[
WebSocket _socket_invoker =
await WebSocket.connect((vm as WebSocketVM).target.networkAddress);

final socket = new StreamController();
final socket_invoker = new StreamController();
final socket = new StreamController<Map>();
final socket_invoker = new StreamController<Map>();

// Avoid to manually encode and decode messages from the stream
socket.stream.map(JSON.encode).pipe(_socket);
Expand Down
4 changes: 2 additions & 2 deletions runtime/observatory/tests/service/object_graph_user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:unittest/unittest.dart';
import 'test_helper.dart';

class Foo {
Object left;
Object right;
dynamic left;
dynamic right;
}

Foo r;
Expand Down
4 changes: 2 additions & 2 deletions runtime/observatory/tests/service/object_graph_vm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:unittest/unittest.dart';
import 'test_helper.dart';

class Foo {
Object left;
Object right;
dynamic left;
dynamic right;
}

Foo r;
Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/tests/service/regress_28443_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_code() async {
}
}

Future<Isolate> stepThroughProgram(Isolate isolate) async {
Future stepThroughProgram(Isolate isolate) async {
Completer completer = new Completer();
int pauseEventsSeen = 0;

Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/tests/service/regress_28980_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Future<Null> test_code() async {
}
}

Future<Isolate> stepThroughProgram(Isolate isolate) async {
Future stepThroughProgram(Isolate isolate) async {
Completer completer = new Completer();
int pauseEventsSeen = 0;

Expand Down
1 change: 0 additions & 1 deletion runtime/observatory/tests/service/service_kernel.status
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ pause_on_unhandled_exceptions_test: CompileTimeError
positive_token_pos_test: CompileTimeError
process_service_test: CompileTimeError
reachable_size_test: CompileTimeError
read_stream_test: CompileTimeError
regexp_function_test: CompileTimeError
regress_28443_test: CompileTimeError
regress_28980_test: CompileTimeError
Expand Down
34 changes: 18 additions & 16 deletions runtime/observatory/tests/service/service_test_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import 'package:unittest/unittest.dart';

typedef Future IsolateTest(Isolate isolate);
typedef Future VMTest(VM vm);
typedef void ServiceEventHandler(ServiceEvent event);

Map<String, StreamSubscription> streamSubscriptions = {};

Future subscribeToStream(VM vm, String streamName, onEvent) async {
Future subscribeToStream(
VM vm, String streamName, ServiceEventHandler onEvent) async {
assert(streamSubscriptions[streamName] == null);

Stream stream = await vm.getEventStream(streamName);
Stream<ServiceEvent> stream = await vm.getEventStream(streamName);
StreamSubscription subscription = stream.listen(onEvent);
streamSubscriptions[streamName] = subscription;
}
Expand All @@ -32,7 +34,7 @@ Future cancelStreamSubscription(String streamName) async {
Future smartNext(Isolate isolate) async {
print('smartNext');
if (isolate.status == M.IsolateStatus.paused) {
var event = isolate.pauseEvent;
dynamic event = isolate.pauseEvent;
if (event.atAsyncSuspension) {
return asyncNext(isolate);
} else {
Expand All @@ -46,7 +48,7 @@ Future smartNext(Isolate isolate) async {
Future asyncNext(Isolate isolate) async {
print('asyncNext');
if (isolate.status == M.IsolateStatus.paused) {
var event = isolate.pauseEvent;
dynamic event = isolate.pauseEvent;
if (!event.atAsyncSuspension) {
throw 'No async continuation at this location';
} else {
Expand Down Expand Up @@ -86,7 +88,7 @@ Future asyncStepOver(Isolate isolate) async {
}

// Subscribe to the debugger event stream.
Stream stream;
Stream<ServiceEvent> stream;
try {
stream = await isolate.vm.getEventStream(VM.kDebugStream);
} catch (e) {
Expand Down Expand Up @@ -151,7 +153,7 @@ bool isEventOfKind(M.Event event, String kind) {
}
}

Future<Isolate> hasPausedFor(Isolate isolate, String kind) {
Future hasPausedFor(Isolate isolate, String kind) {
// Set up a listener to wait for breakpoint events.
Completer completer = new Completer();
isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
Expand Down Expand Up @@ -186,27 +188,27 @@ Future<Isolate> hasPausedFor(Isolate isolate, String kind) {
return completer.future; // Will complete when breakpoint hit.
}

Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) {
Future hasStoppedAtBreakpoint(Isolate isolate) {
return hasPausedFor(isolate, ServiceEvent.kPauseBreakpoint);
}

Future<Isolate> hasStoppedPostRequest(Isolate isolate) {
Future hasStoppedPostRequest(Isolate isolate) {
return hasPausedFor(isolate, ServiceEvent.kPausePostRequest);
}

Future<Isolate> hasStoppedWithUnhandledException(Isolate isolate) {
Future hasStoppedWithUnhandledException(Isolate isolate) {
return hasPausedFor(isolate, ServiceEvent.kPauseException);
}

Future<Isolate> hasStoppedAtExit(Isolate isolate) {
Future hasStoppedAtExit(Isolate isolate) {
return hasPausedFor(isolate, ServiceEvent.kPauseExit);
}

Future<Isolate> hasPausedAtStart(Isolate isolate) {
Future hasPausedAtStart(Isolate isolate) {
return hasPausedFor(isolate, ServiceEvent.kPauseStart);
}

Future<Isolate> markDartColonLibrariesDebuggable(Isolate isolate) async {
Future markDartColonLibrariesDebuggable(Isolate isolate) async {
await isolate.reload();
for (Library lib in isolate.libraries) {
await lib.load();
Expand Down Expand Up @@ -327,7 +329,7 @@ IsolateTest stoppedInFunction(String functionName,
};
}

Future<Isolate> resumeIsolate(Isolate isolate) {
Future resumeIsolate(Isolate isolate) {
Completer completer = new Completer();
isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
var subscription;
Expand Down Expand Up @@ -363,17 +365,17 @@ IsolateTest resumeIsolateAndAwaitEvent(stream, onEvent) {
resumeAndAwaitEvent(isolate, stream, onEvent);
}

Future<Isolate> stepOver(Isolate isolate) async {
Future stepOver(Isolate isolate) async {
await isolate.stepOver();
return hasStoppedAtBreakpoint(isolate);
}

Future<Isolate> stepInto(Isolate isolate) async {
Future stepInto(Isolate isolate) async {
await isolate.stepInto();
return hasStoppedAtBreakpoint(isolate);
}

Future<Isolate> stepOut(Isolate isolate) async {
Future stepOut(Isolate isolate) async {
await isolate.stepOut();
return hasStoppedAtBreakpoint(isolate);
}
Expand Down
Loading

0 comments on commit 9f4ffb6

Please sign in to comment.