Roll package:dds to 1.4.0 and update error handling (#66836)

This commit is contained in:
Ben Konyi
2020-09-29 10:28:17 -07:00
committed by GitHub
parent d693d2b9d2
commit 65a81c7cd3
13 changed files with 147 additions and 37 deletions

View File

@@ -90,8 +90,10 @@ void main() {
when(portForwarder.unforward(any))
.thenAnswer((_) async {});
when(device.dds).thenReturn(mockDds);
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.startDartDevelopmentService(any, any, false, any)).thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
final HttpClientRequest httpClientRequest = MockHttpClientRequest();
httpClient = MockHttpClient();
when(httpClient.putUrl(any))
@@ -299,6 +301,8 @@ void main() {
.thenReturn(portForwarder);
when(device.dds)
.thenReturn(mockDds);
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
.thenAnswer((_) async => hostPort);
when(portForwarder.forwardedPorts)
@@ -379,6 +383,8 @@ void main() {
.thenReturn(portForwarder);
when(device.dds)
.thenReturn(mockDds);
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) => mockLogReader);
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
@@ -449,6 +455,8 @@ void main() {
when(mockDds.startDartDevelopmentService(any, any, any, any))
.thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
});
testUsingContext('succeeds in ipv4 mode', () async {

View File

@@ -2328,10 +2328,12 @@ void main() {
final MockDevice mockDevice = MockDevice();
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
final MockDeviceLogReader mockLogReader = MockDeviceLogReader();
final Completer<void> noopCompleter = Completer<void>();
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(mockLogReader);
when(mockDevice.dds).thenReturn(mockDds);
when(mockDds.startDartDevelopmentService(any, any, any, any)).thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
final TestFlutterDevice flutterDevice = TestFlutterDevice(
mockDevice,

View File

@@ -0,0 +1,43 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/file.dart';
import '../src/common.dart';
import 'test_data/project_with_immediate_exit.dart';
import 'test_driver.dart';
import 'test_utils.dart';
void main() {
Directory tempDir;
final ProjectWithImmediateExit _project = ProjectWithImmediateExit();
FlutterRunTestDriver _flutter;
setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
await _project.setUpIn(tempDir);
_flutter = FlutterRunTestDriver(tempDir);
});
tearDown(() async {
tryToDelete(tempDir);
});
testWithoutContext('flutter_tools gracefully handles quick app shutdown', () async {
try {
await _flutter.run();
} on Exception {
expect(_flutter.lastErrorInfo, contains('Error connecting to the service protocol:'));
expect(
_flutter.lastErrorInfo.contains(
// Looks for stack trace entry of the form:
// test/integration.shard/test_driver.dart 379:18 FlutterTestDriver._waitFor.<fn>
RegExp('^(.+)\/([^\/]+)\.dart \d*:\d*\s*.*\$')
),
isFalse
);
}
});
}

View File

@@ -0,0 +1,31 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'project.dart';
class ProjectWithImmediateExit extends Project {
@override
final String pubspec = '''
name: test
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
''';
@override
final String main = r'''
import 'dart:async';
import 'dart:io';
Future<void> main() async {
await Future.delayed(const Duration(milliseconds: 50));
exit(0);
}
''';
}

View File

@@ -376,7 +376,7 @@ abstract class FlutterTestDriver {
if (json['params'] != null && json['params']['trace'] != null) {
error.write('${json['params']['trace']}\n\n');
}
response.completeError(error.toString());
response.completeError(Exception(error.toString()));
}
});
@@ -536,7 +536,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
// fast.
unawaited(_process.exitCode.then((_) {
if (!prematureExitGuard.isCompleted) {
prematureExitGuard.completeError('Process exited prematurely: ${args.join(' ')}: $_errorBuffer');
prematureExitGuard.completeError(Exception('Process exited prematurely: ${args.join(' ')}: $_errorBuffer'));
}
}));
@@ -567,7 +567,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
_currentRunningAppId = (await started)['params']['appId'] as String;
prematureExitGuard.complete();
} on Exception catch (error, stackTrace) {
prematureExitGuard.completeError(error, stackTrace);
prematureExitGuard.completeError(Exception(error.toString()), stackTrace);
}
}());