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 { ...@@ -97,21 +97,19 @@ class ScreenshotCommand extends FlutterCommand {
outputFile = globals.fs.file(stringArg(_kOut)); outputFile = globals.fs.file(stringArg(_kOut));
} }
bool success = true;
switch (stringArg(_kType)) { switch (stringArg(_kType)) {
case _kDeviceType: case _kDeviceType:
await runScreenshot(outputFile); await runScreenshot(outputFile);
break; return FlutterCommandResult.success();
case _kSkiaType: case _kSkiaType:
success = await runSkia(outputFile); await runSkia(outputFile);
break; return FlutterCommandResult.success();
case _kRasterizerType: case _kRasterizerType:
success = await runRasterizer(outputFile); await runRasterizer(outputFile);
break; return FlutterCommandResult.success();
} }
return success ? FlutterCommandResult.success() return FlutterCommandResult.success();
: FlutterCommandResult.fail();
} }
Future<void> runScreenshot(File outputFile) async { Future<void> runScreenshot(File outputFile) async {
...@@ -128,17 +126,10 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -128,17 +126,10 @@ class ScreenshotCommand extends FlutterCommand {
_showOutputFileInfo(outputFile); _showOutputFileInfo(outputFile);
} }
Future<bool> runSkia(File outputFile) async { Future<void> runSkia(File outputFile) async {
final Uri observatoryUri = Uri.parse(stringArg(_kObservatoryUri)); final Uri observatoryUri = Uri.parse(stringArg(_kObservatoryUri));
final vm_service.VmService vmService = await connectToVmService(observatoryUri); final vm_service.VmService vmService = await connectToVmService(observatoryUri);
final vm_service.Response skp = await vmService.screenshotSkp(); 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( outputFile ??= globals.fsUtils.getUniqueFile(
globals.fs.currentDirectory, globals.fs.currentDirectory,
'flutter', 'flutter',
...@@ -149,20 +140,12 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -149,20 +140,12 @@ class ScreenshotCommand extends FlutterCommand {
await sink.close(); await sink.close();
_showOutputFileInfo(outputFile); _showOutputFileInfo(outputFile);
_ensureOutputIsNotJsonRpcError(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 Uri observatoryUri = Uri.parse(stringArg(_kObservatoryUri));
final vm_service.VmService vmService = await connectToVmService(observatoryUri); final vm_service.VmService vmService = await connectToVmService(observatoryUri);
final vm_service.Response response = await vmService.screenshot(); 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( outputFile ??= globals.fsUtils.getUniqueFile(
globals.fs.currentDirectory, globals.fs.currentDirectory,
'flutter', 'flutter',
...@@ -173,7 +156,6 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -173,7 +156,6 @@ class ScreenshotCommand extends FlutterCommand {
await sink.close(); await sink.close();
_showOutputFileInfo(outputFile); _showOutputFileInfo(outputFile);
_ensureOutputIsNotJsonRpcError(outputFile); _ensureOutputIsNotJsonRpcError(outputFile);
return true;
} }
void _ensureOutputIsNotJsonRpcError(File outputFile) { void _ensureOutputIsNotJsonRpcError(File outputFile) {
......
...@@ -419,15 +419,8 @@ class DevFS { ...@@ -419,15 +419,8 @@ class DevFS {
final vm_service.Response response = await _vmService.createDevFS(fsName); final vm_service.Response response = await _vmService.createDevFS(fsName);
_baseUri = Uri.parse(response.json['uri'] as String); _baseUri = Uri.parse(response.json['uri'] as String);
} on vm_service.RPCError catch (rpcException) { } 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 // 1001 is kFileSystemAlreadyExists in //dart/runtime/vm/json_stream.h
if (rpcException.code != 1001) { if (rpcException.code != 1001) {
// Other RPCErrors are unexpected. Rethrow so it will hit crash
// logging.
rethrow; rethrow;
} }
_logger.printTrace('DevFS: Creating failed. Destroying and trying again'); _logger.printTrace('DevFS: Creating failed. Destroying and trying again');
......
...@@ -32,7 +32,7 @@ class Tracing { ...@@ -32,7 +32,7 @@ class Tracing {
final Logger _logger; final Logger _logger;
Future<void> startTracing() async { Future<void> startTracing() async {
await vmService.setTimelineFlags(<String>['Compiler', 'Dart', 'Embedder', 'GC']); await vmService.setVMTimelineFlags(<String>['Compiler', 'Dart', 'Embedder', 'GC']);
await vmService.clearVMTimeline(); await vmService.clearVMTimeline();
} }
...@@ -78,13 +78,8 @@ class Tracing { ...@@ -78,13 +78,8 @@ class Tracing {
} }
status.stop(); status.stop();
} }
final vm_service.Response timeline = await vmService.getTimeline(); final vm_service.Timeline timeline = await vmService.getVMTimeline();
await vmService.setTimelineFlags(<String>[]); await vmService.setVMTimelineFlags(<String>[]);
if (timeline == null) {
throwToolExit(
'The device disconnected before the timeline could be retrieved.',
);
}
return timeline.json; return timeline.json;
} }
} }
......
...@@ -728,12 +728,23 @@ extension FlutterVmService on vm_service.VmService { ...@@ -728,12 +728,23 @@ extension FlutterVmService on vm_service.VmService {
return null; 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, { String method, {
@required String isolateId,
Map<String, dynamic> args, Map<String, dynamic> args,
}) async { }) async {
try { 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) { } on vm_service.RPCError catch (err) {
// If an application is not using the framework or the VM service // If an application is not using the framework or the VM service
// disappears while handling a request, return null. // disappears while handling a request, return null.
...@@ -745,23 +756,6 @@ extension FlutterVmService on vm_service.VmService { ...@@ -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. /// List all [FlutterView]s attached to the current VM.
/// ///
/// If this returns an empty list, it will poll forever unless [returnEarly] /// If this returns an empty list, it will poll forever unless [returnEarly]
...@@ -805,34 +799,26 @@ extension FlutterVmService on vm_service.VmService { ...@@ -805,34 +799,26 @@ extension FlutterVmService on vm_service.VmService {
/// Create a new development file system on the device. /// Create a new development file system on the device.
Future<vm_service.Response> createDevFS(String fsName) { Future<vm_service.Response> createDevFS(String fsName) {
// Call the unchecked version of `callServiceExtension` because the caller return callServiceExtension('_createDevFS', args: <String, dynamic>{'fsName': fsName});
// has custom handling of certain RPCErrors.
return callServiceExtension(
'_createDevFS',
args: <String, dynamic>{'fsName': fsName},
);
} }
/// Delete an existing file system. /// Delete an existing file system.
Future<void> deleteDevFS(String fsName) async { Future<vm_service.Response> deleteDevFS(String fsName) {
await _checkedCallServiceExtension( return callServiceExtension('_deleteDevFS', args: <String, dynamic>{'fsName': fsName});
'_deleteDevFS',
args: <String, dynamic>{'fsName': fsName},
);
} }
Future<vm_service.Response> screenshot() { Future<vm_service.Response> screenshot() {
return _checkedCallServiceExtension(kScreenshotMethod); return callServiceExtension(kScreenshotMethod);
} }
Future<vm_service.Response> screenshotSkp() { Future<vm_service.Response> screenshotSkp() {
return _checkedCallServiceExtension(kScreenshotSkpMethod); return callServiceExtension(kScreenshotSkpMethod);
} }
/// Set the VM timeline flags. /// Set the VM timeline flags.
Future<void> setTimelineFlags(List<String> recordedStreams) async { Future<vm_service.Response> setVMTimelineFlags(List<String> recordedStreams) {
assert(recordedStreams != null); assert(recordedStreams != null);
await _checkedCallServiceExtension( return callServiceExtension(
'setVMTimelineFlags', 'setVMTimelineFlags',
args: <String, dynamic>{ args: <String, dynamic>{
'recordedStreams': recordedStreams, 'recordedStreams': recordedStreams,
...@@ -840,8 +826,8 @@ extension FlutterVmService on vm_service.VmService { ...@@ -840,8 +826,8 @@ extension FlutterVmService on vm_service.VmService {
); );
} }
Future<vm_service.Response> getTimeline() { Future<vm_service.Response> getVMTimeline() {
return _checkedCallServiceExtension('getVMTimeline'); return callServiceExtension('getVMTimeline');
} }
} }
......
...@@ -31,20 +31,6 @@ final FakeVmServiceRequest createDevFSRequest = FakeVmServiceRequest( ...@@ -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() { void main() {
testWithoutContext('DevFSByteContent', () { testWithoutContext('DevFSByteContent', () {
final DevFSByteContent content = DevFSByteContent(<int>[4, 5, 6]); final DevFSByteContent content = DevFSByteContent(<int>[4, 5, 6]);
...@@ -107,73 +93,6 @@ void main() { ...@@ -107,73 +93,6 @@ void main() {
expect(content.isModified, isFalse); 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 { testWithoutContext('DevFS retries uploads when connection reset by peer', () async {
final HttpClient httpClient = MockHttpClient(); final HttpClient httpClient = MockHttpClient();
final FileSystem fileSystem = MemoryFileSystem.test(); final FileSystem fileSystem = MemoryFileSystem.test();
......
...@@ -130,29 +130,6 @@ void main() { ...@@ -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 { testWithoutContext('throws tool exit if timeline is missing the engine start event', () async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final FileSystem fileSystem = MemoryFileSystem.test(); final FileSystem fileSystem = MemoryFileSystem.test();
......
...@@ -315,58 +315,20 @@ void main() { ...@@ -315,58 +315,20 @@ void main() {
testWithoutContext('Framework service extension invocations return null if service disappears ', () async { testWithoutContext('Framework service extension invocations return null if service disappears ', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost( final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[ requests: <VmServiceExpectation>[
const FakeVmServiceRequest( const FakeVmServiceRequest(method: kGetSkSLsMethod, args: <String, Object>{
method: kGetSkSLsMethod, 'viewId': '1234',
args: <String, Object>{ }, errorCode: RPCErrorCodes.kServiceDisappeared),
'viewId': '1234', const FakeVmServiceRequest(method: kListViewsMethod, errorCode: RPCErrorCodes.kServiceDisappeared),
},
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,
),
] ]
); );
final Map<String, Object> skSLs = await fakeVmServiceHost.vmService.getSkSLs( final Map<String, Object> skSLs = await fakeVmServiceHost.vmService.getSkSLs(
viewId: '1234', viewId: '1234',
); );
expect(skSLs, isNull); expect(skSLs, null);
final List<FlutterView> views = await fakeVmServiceHost.vmService.getFlutterViews(); final List<FlutterView> views = await fakeVmServiceHost.vmService.getFlutterViews();
expect(views, isNull); expect(views, null);
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(fakeVmServiceHost.hasRemainingExpectations, false); 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