Commit d53115ab authored by done's avatar done Committed by Dan Field

fix FlutterDriver timeout (#31824)

parent c731e3e6
...@@ -63,7 +63,8 @@ const List<TimelineStream> _defaultStreams = <TimelineStream>[TimelineStream.all ...@@ -63,7 +63,8 @@ const List<TimelineStream> _defaultStreams = <TimelineStream>[TimelineStream.all
/// How long to wait before showing a message saying that /// How long to wait before showing a message saying that
/// things seem to be taking a long time. /// things seem to be taking a long time.
const Duration _kUnusuallyLongTimeout = Duration(seconds: 5); @visibleForTesting
const Duration kUnusuallyLongTimeout = Duration(seconds: 5);
/// The amount of time we wait prior to making the next attempt to connect to /// The amount of time we wait prior to making the next attempt to connect to
/// the VM service. /// the VM service.
...@@ -102,16 +103,6 @@ Future<T> _warnIfSlow<T>({ ...@@ -102,16 +103,6 @@ Future<T> _warnIfSlow<T>({
return future..timeout(timeout, onTimeout: () { _log.warning(message); }); return future..timeout(timeout, onTimeout: () { _log.warning(message); });
} }
Duration _maxDuration(Duration a, Duration b) {
if (a == null)
return b;
if (b == null)
return a;
if (a > b)
return a;
return b;
}
/// A convenient accessor to frequently used finders. /// A convenient accessor to frequently used finders.
/// ///
/// Examples: /// Examples:
...@@ -334,7 +325,7 @@ class FlutterDriver { ...@@ -334,7 +325,7 @@ class FlutterDriver {
// register it. If that happens, show a message but continue waiting. // register it. If that happens, show a message but continue waiting.
await _warnIfSlow<String>( await _warnIfSlow<String>(
future: whenServiceExtensionReady, future: whenServiceExtensionReady,
timeout: _kUnusuallyLongTimeout, timeout: kUnusuallyLongTimeout,
message: 'Flutter Driver extension is taking a long time to become available. ' message: 'Flutter Driver extension is taking a long time to become available. '
'Ensure your test app (often "lib/main.dart") imports ' 'Ensure your test app (often "lib/main.dart") imports '
'"package:flutter_driver/driver_extension.dart" and ' '"package:flutter_driver/driver_extension.dart" and '
...@@ -416,7 +407,7 @@ class FlutterDriver { ...@@ -416,7 +407,7 @@ class FlutterDriver {
).then<Map<String, dynamic>>((Object value) => value); ).then<Map<String, dynamic>>((Object value) => value);
response = await _warnIfSlow<Map<String, dynamic>>( response = await _warnIfSlow<Map<String, dynamic>>(
future: future, future: future,
timeout: _maxDuration(command.timeout, _kUnusuallyLongTimeout), timeout: command.timeout ?? kUnusuallyLongTimeout,
message: '${command.kind} message is taking a long time to complete...', message: '${command.kind} message is taking a long time to complete...',
); );
_logCommunication('<<< $response'); _logCommunication('<<< $response');
...@@ -736,7 +727,7 @@ class FlutterDriver { ...@@ -736,7 +727,7 @@ class FlutterDriver {
/// operation. /// operation.
Future<void> startTracing({ Future<void> startTracing({
List<TimelineStream> streams = _defaultStreams, List<TimelineStream> streams = _defaultStreams,
Duration timeout = _kUnusuallyLongTimeout, Duration timeout = kUnusuallyLongTimeout,
}) async { }) async {
assert(streams != null && streams.isNotEmpty); assert(streams != null && streams.isNotEmpty);
assert(timeout != null); assert(timeout != null);
...@@ -763,7 +754,7 @@ class FlutterDriver { ...@@ -763,7 +754,7 @@ class FlutterDriver {
/// operation exceeds the specified timeout; it does not actually cancel the /// operation exceeds the specified timeout; it does not actually cancel the
/// operation. /// operation.
Future<Timeline> stopTracingAndDownloadTimeline({ Future<Timeline> stopTracingAndDownloadTimeline({
Duration timeout = _kUnusuallyLongTimeout, Duration timeout = kUnusuallyLongTimeout,
}) async { }) async {
assert(timeout != null); assert(timeout != null);
try { try {
...@@ -832,7 +823,7 @@ class FlutterDriver { ...@@ -832,7 +823,7 @@ class FlutterDriver {
/// operation exceeds the specified timeout; it does not actually cancel the /// operation exceeds the specified timeout; it does not actually cancel the
/// operation. /// operation.
Future<void> clearTimeline({ Future<void> clearTimeline({
Duration timeout = _kUnusuallyLongTimeout, Duration timeout = kUnusuallyLongTimeout,
}) async { }) async {
assert(timeout != null); assert(timeout != null);
try { try {
......
...@@ -386,7 +386,7 @@ void main() { ...@@ -386,7 +386,7 @@ void main() {
}); });
group('sendCommand error conditions', () { group('sendCommand error conditions', () {
test('local timeout', () async { test('local default timeout', () async {
final List<String> log = <String>[]; final List<String> log = <String>[];
final StreamSubscription<LogRecord> logSub = flutterDriverLog.listen((LogRecord s) => log.add(s.toString())); final StreamSubscription<LogRecord> logSub = flutterDriverLog.listen((LogRecord s) => log.add(s.toString()));
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
...@@ -396,7 +396,24 @@ void main() { ...@@ -396,7 +396,24 @@ void main() {
FakeAsync().run((FakeAsync time) { FakeAsync().run((FakeAsync time) {
driver.waitFor(find.byTooltip('foo')); driver.waitFor(find.byTooltip('foo'));
expect(log, <String>[]); expect(log, <String>[]);
time.elapse(const Duration(hours: 1)); time.elapse(kUnusuallyLongTimeout);
});
expect(log, <String>['[warning] FlutterDriver: waitFor message is taking a long time to complete...']);
await logSub.cancel();
});
test('local custom timeout', () async {
final List<String> log = <String>[];
final StreamSubscription<LogRecord> logSub = flutterDriverLog.listen((LogRecord s) => log.add(s.toString()));
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
// completer never completed to trigger timeout
return Completer<Map<String, dynamic>>().future;
});
FakeAsync().run((FakeAsync time) {
final Duration customTimeout = kUnusuallyLongTimeout - const Duration(seconds: 1);
driver.waitFor(find.byTooltip('foo'), timeout: customTimeout);
expect(log, <String>[]);
time.elapse(customTimeout);
}); });
expect(log, <String>['[warning] FlutterDriver: waitFor message is taking a long time to complete...']); expect(log, <String>['[warning] FlutterDriver: waitFor message is taking a long time to complete...']);
await logSub.cancel(); await logSub.cancel();
......
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