Fix flaky test (#52088)

This commit is contained in:
Dan Field
2020-03-06 13:01:42 -08:00
committed by GitHub
parent e7d70fbf75
commit a42d38a2f8
4 changed files with 30 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:io' as io;
import 'package:flutter_tools/src/android/android_workflow.dart';
import 'package:flutter_tools/src/base/bot_detector.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart';
@@ -37,6 +38,7 @@ import 'package:mockito/mockito.dart';
import 'common.dart';
import 'fake_process_manager.dart';
import 'mocks.dart';
import 'throwing_pub.dart';
export 'package:flutter_tools/src/base/context.dart' show Generator;
@@ -164,6 +166,15 @@ void testUsingContext(
});
},
);
}, overrides: <Type, Generator>{
// This has to go here so that runInContext will pick it up when it tries
// to do bot detection before running the closure. This is important
// because the test may be giving us a fake HttpClientFactory, which may
// throw in unexpected/abnormal ways.
// If a test needs a BotDetector that does not always return true, it
// can provide the AlwaysFalseBotDetector in the overrides, or its own
// BotDetector implementation in the overrides.
BotDetector: overrides[BotDetector] ?? () => const AlwaysTrueBotDetector(),
});
}, testOn: testOn, skip: skip);
}

View File

@@ -11,6 +11,7 @@ import 'package:platform/platform.dart';
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/android/android_sdk.dart' show AndroidSdk;
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/bot_detector.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart' hide IOSink;
import 'package:flutter_tools/src/base/io.dart';
@@ -761,3 +762,18 @@ class MockStdIn extends Mock implements IOSink {
}
class MockStream extends Mock implements Stream<List<int>> {}
class AlwaysTrueBotDetector implements BotDetector {
const AlwaysTrueBotDetector();
@override
Future<bool> get isRunningOnBot async => true;
}
class AlwaysFalseBotDetector implements BotDetector {
const AlwaysFalseBotDetector();
@override
Future<bool> get isRunningOnBot async => false;
}