Unverified Commit a42d38a2 authored by Dan Field's avatar Dan Field Committed by GitHub

Fix flaky test (#52088)

parent e7d70fbf
......@@ -18,25 +18,9 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart' show MockProcessManager, MockStdio, PromptingProcess;
import '../../src/mocks.dart' show MockProcessManager, MockStdio, PromptingProcess, AlwaysTrueBotDetector, AlwaysFalseBotDetector;
import '../../src/testbed.dart';
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;
}
void main() {
Cache.disableLocking();
group('packages get/upgrade', () {
......
......@@ -28,7 +28,7 @@ void main() {
String basePath;
setUpAll(() {
fs = MemoryFileSystem();
fs = MemoryFileSystem.test();
filePath = fs.path.join('lib', 'foo.txt');
});
......@@ -69,7 +69,7 @@ void main() {
file.parent.createSync(recursive: true);
file.writeAsBytesSync(<int>[1, 2, 3], flush: true);
final DateTime fiveSecondsAgo = DateTime.now().subtract(const Duration(seconds:5));
final DateTime fiveSecondsAgo = file.statSync().modified.subtract(const Duration(seconds: 5));
expect(content.isModifiedAfter(fiveSecondsAgo), isTrue);
expect(content.isModifiedAfter(fiveSecondsAgo), isTrue);
expect(content.isModifiedAfter(null), isTrue);
......
......@@ -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);
}
......
......@@ -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;
}
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