use of org.dartlang.vm.service.element.ElementList in project flutter-intellij by flutter.
the class FlutterTestRunner method run.
protected RunContentDescriptor run(@NotNull TestLaunchState launcher, @NotNull ExecutionEnvironment env) throws ExecutionException {
final ExecutionResult executionResult = launcher.execute(env.getExecutor(), this);
final ObservatoryConnector connector = new Connector(executionResult.getProcessHandler());
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// Poll, waiting for "flutter run" to give us a websocket.
// This is adapted from DartVmServiceDebugProcess::scheduleConnect.
String url = connector.getWebSocketUrl();
while (url == null) {
if (launcher.isTerminated()) {
return;
}
TimeoutUtil.sleep(100);
url = connector.getWebSocketUrl();
}
if (launcher.isTerminated()) {
return;
}
final VmService vmService;
try {
vmService = VmService.connect(url);
} catch (IOException | RuntimeException e) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Failed to connect to the VM service at: " + url + "\n" + e.toString() + "\n", ProcessOutputTypes.STDERR);
}
return;
}
// Listen for debug 'PauseStart' events for isolates after the initial connect and resume those isolates.
vmService.streamListen(VmService.DEBUG_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
vmService.addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void received(String streamId, Event event) {
if (EventKind.PauseStart.equals(event.getKind())) {
resumePausedAtStartIsolate(launcher, vmService, event.getIsolate());
}
}
});
// Resume any isolates paused at the initial connect.
vmService.getVM(new VMConsumer() {
@Override
public void received(VM response) {
final ElementList<IsolateRef> isolates = response.getIsolates();
for (IsolateRef isolateRef : isolates) {
resumePausedAtStartIsolate(launcher, vmService, isolateRef);
}
}
@Override
public void onError(RPCError error) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Error connecting to VM: " + error.getCode() + " " + error.getMessage() + "\n", ProcessOutputTypes.STDERR);
}
}
});
});
return new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
}
Aggregations