Unverified Commit 6be4d1c8 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

Revert "Handle more cases where the tool receives RPCError 112 (#74574)" (#74601)

This reverts commit c87f15fe.
parent c87f15fe
......@@ -97,21 +97,19 @@ class ScreenshotCommand extends FlutterCommand {
outputFile = globals.fs.file(stringArg(_kOut));
}
bool success = true;
switch (stringArg(_kType)) {
case _kDeviceType:
await runScreenshot(outputFile);
break;
return FlutterCommandResult.success();
case _kSkiaType:
success = await runSkia(outputFile);
break;
await runSkia(outputFile);
return FlutterCommandResult.success();
case _kRasterizerType:
success = await runRasterizer(outputFile);
break;
await runRasterizer(outputFile);
return FlutterCommandResult.success();
}
return success ? FlutterCommandResult.success()
: FlutterCommandResult.fail();
return FlutterCommandResult.success();
}
Future<void> runScreenshot(File outputFile) async {
......@@ -128,17 +126,10 @@ class ScreenshotCommand extends FlutterCommand {
_showOutputFileInfo(outputFile);
}
Future<bool> runSkia(File outputFile) async {
Future<void> runSkia(File outputFile) async {
final Uri observatoryUri = Uri.parse(stringArg(_kObservatoryUri));
final vm_service.VmService vmService = await connectToVmService(observatoryUri);
final vm_service.Response skp = await vmService.screenshotSkp();
if (skp == null) {
globals.printError(
'The Skia picture request failed, probably because the device was '
'disconnected',
);
return false;
}
outputFile ??= globals.fsUtils.getUniqueFile(
globals.fs.currentDirectory,
'flutter',
......@@ -149,20 +140,12 @@ class ScreenshotCommand extends FlutterCommand {
await sink.close();
_showOutputFileInfo(outputFile);
_ensureOutputIsNotJsonRpcError(outputFile);
return true;
}
Future<bool> runRasterizer(File outputFile) async {
Future<void> runRasterizer(File outputFile) async {
final Uri observatoryUri = Uri.parse(stringArg(_kObservatoryUri));
final vm_service.VmService vmService = await connectToVmService(observatoryUri);
final vm_service.Response response = await vmService.screenshot();
if (response == null) {
globals.printError(
'The screenshot request failed, probably because the device was '
'disconnected',
);
return false;
}
outputFile ??= globals.fsUtils.getUniqueFile(
globals.fs.currentDirectory,
'flutter',
......@@ -173,7 +156,6 @@ class ScreenshotCommand extends FlutterCommand {
await sink.close();
_showOutputFileInfo(outputFile);
_ensureOutputIsNotJsonRpcError(outputFile);
return true;
}
void _ensureOutputIsNotJsonRpcError(File outputFile) {
......
......@@ -419,15 +419,8 @@ class DevFS {
final vm_service.Response response = await _vmService.createDevFS(fsName);
_baseUri = Uri.parse(response.json['uri'] as String);
} on vm_service.RPCError catch (rpcException) {
if (rpcException.code == RPCErrorCodes.kServiceDisappeared) {
// This can happen if the device has been disconnected, so translate to
// a DevFSException, which the caller will handle.
throw DevFSException('Service disconnected', rpcException);
}
// 1001 is kFileSystemAlreadyExists in //dart/runtime/vm/json_stream.h
if (rpcException.code != 1001) {
// Other RPCErrors are unexpected. Rethrow so it will hit crash
// logging.
rethrow;
}
_logger.printTrace('DevFS: Creating failed. Destroying and trying again');
......
......@@ -32,7 +32,7 @@ class Tracing {
final Logger _logger;
Future<void> startTracing() async {
await vmService.setTimelineFlags(<String>['Compiler', 'Dart', 'Embedder', 'GC']);
await vmService.setVMTimelineFlags(<String>['Compiler', 'Dart', 'Embedder', 'GC']);
await vmService.clearVMTimeline();
}
......@@ -78,13 +78,8 @@ class Tracing {
}
status.stop();
}
final vm_service.Response timeline = await vmService.getTimeline();
await vmService.setTimelineFlags(<String>[]);
if (timeline == null) {
throwToolExit(
'The device disconnected before the timeline could be retrieved.',
);
}
final vm_service.Timeline timeline = await vmService.getVMTimeline();
await vmService.setVMTimelineFlags(<String>[]);
return timeline.json;
}
}
......
......@@ -728,12 +728,23 @@ extension FlutterVmService on vm_service.VmService {
return null;
}
Future<vm_service.Response> _checkedCallServiceExtension(
/// Invoke a flutter extension method, if the flutter extension is not
/// available, returns null.
Future<Map<String, dynamic>> invokeFlutterExtensionRpcRaw(
String method, {
@required String isolateId,
Map<String, dynamic> args,
}) async {
try {
return await callServiceExtension(method, args: args);
final vm_service.Response response = await callServiceExtension(
method,
args: <String, Object>{
'isolateId': isolateId,
...?args,
},
);
return response.json;
} on vm_service.RPCError catch (err) {
// If an application is not using the framework or the VM service
// disappears while handling a request, return null.
......@@ -745,23 +756,6 @@ extension FlutterVmService on vm_service.VmService {
}
}
/// Invoke a flutter extension method, if the flutter extension is not
/// available, returns null.
Future<Map<String, dynamic>> invokeFlutterExtensionRpcRaw(
String method, {
@required String isolateId,
Map<String, dynamic> args,
}) async {
final vm_service.Response response = await _checkedCallServiceExtension(
method,
args: <String, Object>{
'isolateId': isolateId,
...?args,
},
);
return response.json;
}
/// List all [FlutterView]s attached to the current VM.
///
/// If this returns an empty list, it will poll forever unless [returnEarly]
......@@ -805,34 +799,26 @@ extension FlutterVmService on vm_service.VmService {
/// Create a new development file system on the device.
Future<vm_service.Response> createDevFS(String fsName) {
// Call the unchecked version of `callServiceExtension` because the caller
// has custom handling of certain RPCErrors.
return callServiceExtension(
'_createDevFS',
args: <String, dynamic>{'fsName': fsName},
);
return callServiceExtension('_createDevFS', args: <String, dynamic>{'fsName': fsName});
}
/// Delete an existing file system.
Future<void> deleteDevFS(String fsName) async {
await _checkedCallServiceExtension(
'_deleteDevFS',
args: <String, dynamic>{'fsName': fsName},
);
Future<vm_service.Response> deleteDevFS(String fsName) {
return callServiceExtension('_deleteDevFS', args: <String, dynamic>{'fsName': fsName});
}
Future<vm_service.Response> screenshot() {
return _checkedCallServiceExtension(kScreenshotMethod);
return callServiceExtension(kScreenshotMethod);
}
Future<vm_service.Response> screenshotSkp() {
return _checkedCallServiceExtension(kScreenshotSkpMethod);
return callServiceExtension(kScreenshotSkpMethod);
}
/// Set the VM timeline flags.
Future<void> setTimelineFlags(List<String> recordedStreams) async {
Future<vm_service.Response> setVMTimelineFlags(List<String> recordedStreams) {
assert(recordedStreams != null);
await _checkedCallServiceExtension(
return callServiceExtension(
'setVMTimelineFlags',
args: <String, dynamic>{
'recordedStreams': recordedStreams,
......@@ -840,8 +826,8 @@ extension FlutterVmService on vm_service.VmService {
);
}
Future<vm_service.Response> getTimeline() {
return _checkedCallServiceExtension('getVMTimeline');
Future<vm_service.Response> getVMTimeline() {
return callServiceExtension('getVMTimeline');
}
}
......
......@@ -31,20 +31,6 @@ final FakeVmServiceRequest createDevFSRequest = FakeVmServiceRequest(
}
);
const FakeVmServiceRequest failingCreateDevFSRequest = FakeVmServiceRequest(
method: '_createDevFS',
args: <String, Object>{
'fsName': 'test',
},
errorCode: RPCErrorCodes.kServiceDisappeared,
);
const FakeVmServiceRequest failingDeleteDevFSRequest = FakeVmServiceRequest(
method: '_deleteDevFS',
args: <String, dynamic>{'fsName': 'test'},
errorCode: RPCErrorCodes.kServiceDisappeared,
);
void main() {
testWithoutContext('DevFSByteContent', () {
final DevFSByteContent content = DevFSByteContent(<int>[4, 5, 6]);
......@@ -107,73 +93,6 @@ void main() {
expect(content.isModified, isFalse);
});
testWithoutContext('DevFS create throws a DevFSException when vmservice disconnects unexpectedly', () async {
final HttpClient httpClient = MockHttpClient();
final FileSystem fileSystem = MemoryFileSystem.test();
final OperatingSystemUtils osUtils = MockOperatingSystemUtils();
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[failingCreateDevFSRequest],
);
setHttpAddress(Uri.parse('http://localhost'), fakeVmServiceHost.vmService);
final MockHttpClientRequest httpRequest = MockHttpClientRequest();
when(httpRequest.headers).thenReturn(MockHttpHeaders());
when(httpClient.putUrl(any)).thenAnswer((Invocation invocation) {
return Future<HttpClientRequest>.value(httpRequest);
});
final MockHttpClientResponse httpClientResponse = MockHttpClientResponse();
when(httpRequest.close()).thenAnswer((Invocation invocation) {
return Future<HttpClientResponse>.value(httpClientResponse);
});
final DevFS devFS = DevFS(
fakeVmServiceHost.vmService,
'test',
fileSystem.currentDirectory,
osUtils: osUtils,
fileSystem: fileSystem,
logger: BufferLogger.test(),
httpClient: httpClient,
);
expect(() async => await devFS.create(), throwsA(isA<DevFSException>()));
});
testWithoutContext('DevFS destroy is resiliant to vmservice disconnection', () async {
final HttpClient httpClient = MockHttpClient();
final FileSystem fileSystem = MemoryFileSystem.test();
final OperatingSystemUtils osUtils = MockOperatingSystemUtils();
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
createDevFSRequest,
failingDeleteDevFSRequest,
],
);
setHttpAddress(Uri.parse('http://localhost'), fakeVmServiceHost.vmService);
final MockHttpClientRequest httpRequest = MockHttpClientRequest();
when(httpRequest.headers).thenReturn(MockHttpHeaders());
when(httpClient.putUrl(any)).thenAnswer((Invocation invocation) {
return Future<HttpClientRequest>.value(httpRequest);
});
final MockHttpClientResponse httpClientResponse = MockHttpClientResponse();
when(httpRequest.close()).thenAnswer((Invocation invocation) {
return Future<HttpClientResponse>.value(httpClientResponse);
});
final DevFS devFS = DevFS(
fakeVmServiceHost.vmService,
'test',
fileSystem.currentDirectory,
osUtils: osUtils,
fileSystem: fileSystem,
logger: BufferLogger.test(),
httpClient: httpClient,
);
expect(await devFS.create(), isNotNull);
await devFS.destroy(); // Testing that this does not throw.
});
testWithoutContext('DevFS retries uploads when connection reset by peer', () async {
final HttpClient httpClient = MockHttpClient();
final FileSystem fileSystem = MemoryFileSystem.test();
......
......@@ -130,29 +130,6 @@ void main() {
});
});
testWithoutContext('throws tool exit if the vmservice disconnects', () async {
final BufferLogger logger = BufferLogger.test();
final FileSystem fileSystem = MemoryFileSystem.test();
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <FakeVmServiceRequest>[
...vmServiceSetup,
const FakeVmServiceRequest(
method: 'getVMTimeline',
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(
method: 'setVMTimelineFlags',
args: <String, Object>{
'recordedStreams': <Object>[],
},
),
]);
await expectLater(() async => await downloadStartupTrace(fakeVmServiceHost.vmService,
output: fileSystem.currentDirectory,
logger: logger,
), throwsToolExit(message: 'The device disconnected before the timeline could be retrieved.'));
});
testWithoutContext('throws tool exit if timeline is missing the engine start event', () async {
final BufferLogger logger = BufferLogger.test();
final FileSystem fileSystem = MemoryFileSystem.test();
......
......@@ -315,58 +315,20 @@ void main() {
testWithoutContext('Framework service extension invocations return null if service disappears ', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
const FakeVmServiceRequest(
method: kGetSkSLsMethod,
args: <String, Object>{
'viewId': '1234',
},
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(
method: kListViewsMethod,
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(
method: kScreenshotMethod,
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(
method: kScreenshotSkpMethod,
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(
method: 'setVMTimelineFlags',
args: <String, dynamic>{
'recordedStreams': <String>['test'],
},
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(
method: 'getVMTimeline',
errorCode: RPCErrorCodes.kServiceDisappeared,
),
const FakeVmServiceRequest(method: kGetSkSLsMethod, args: <String, Object>{
'viewId': '1234',
}, errorCode: RPCErrorCodes.kServiceDisappeared),
const FakeVmServiceRequest(method: kListViewsMethod, errorCode: RPCErrorCodes.kServiceDisappeared),
]
);
final Map<String, Object> skSLs = await fakeVmServiceHost.vmService.getSkSLs(
viewId: '1234',
);
expect(skSLs, isNull);
expect(skSLs, null);
final List<FlutterView> views = await fakeVmServiceHost.vmService.getFlutterViews();
expect(views, isNull);
final vm_service.Response screenshot = await fakeVmServiceHost.vmService.screenshot();
expect(screenshot, isNull);
final vm_service.Response screenshotSkp = await fakeVmServiceHost.vmService.screenshotSkp();
expect(screenshotSkp, isNull);
// Checking that this doesn't throw.
await fakeVmServiceHost.vmService.setTimelineFlags(<String>['test']);
final vm_service.Response timeline = await fakeVmServiceHost.vmService.getTimeline();
expect(timeline, isNull);
expect(views, null);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment