Unverified Commit c130aa95 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Add FakeAsync to delay tests (#58644)

parent e48e2e6a
...@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/base/process.dart'; ...@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:quiver/testing/async.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -193,25 +194,34 @@ void main() { ...@@ -193,25 +194,34 @@ void main() {
flakes: 1, flakes: 1,
delay: delay, delay: delay,
); );
FakeAsync().run((FakeAsync time) async {
final Duration timeout = delay + const Duration(seconds: 1);
final RunResult result = await flakyProcessUtils.run( final RunResult result = await flakyProcessUtils.run(
<String>['dummy'], <String>['dummy'],
timeout: delay + const Duration(seconds: 1), timeout: timeout,
); );
time.elapse(timeout);
expect(result.exitCode, -9); expect(result.exitCode, -9);
}); });
});
testWithoutContext(' flaky process succeeds with retry', () async { testWithoutContext(' flaky process succeeds with retry', () async {
flakyProcessManager.processFactory = flakyProcessFactory( flakyProcessManager.processFactory = flakyProcessFactory(
flakes: 1, flakes: 1,
delay: delay, delay: delay,
); );
FakeAsync().run((FakeAsync time) async {
final Duration timeout = delay - const Duration(milliseconds: 500);
final RunResult result = await flakyProcessUtils.run( final RunResult result = await flakyProcessUtils.run(
<String>['dummy'], <String>['dummy'],
timeout: delay - const Duration(milliseconds: 500), timeout: timeout,
timeoutRetries: 1, timeoutRetries: 1,
); );
time.elapse(timeout);
expect(result.exitCode, 0); expect(result.exitCode, 0);
}); });
});
testWithoutContext(' flaky process generates ProcessException on timeout', () async { testWithoutContext(' flaky process generates ProcessException on timeout', () async {
final Completer<List<int>> flakyStderr = Completer<List<int>>(); final Completer<List<int>> flakyStderr = Completer<List<int>>();
...@@ -230,11 +240,16 @@ void main() { ...@@ -230,11 +240,16 @@ void main() {
flakyStdout.complete(<int>[]); flakyStdout.complete(<int>[]);
return true; return true;
}); });
FakeAsync().run((FakeAsync time) async {
final Duration timeout = delay - const Duration(milliseconds: 500);
expect(() => flakyProcessUtils.run( expect(() => flakyProcessUtils.run(
<String>['dummy'], <String>['dummy'],
timeout: delay - const Duration(milliseconds: 500), timeout: timeout,
timeoutRetries: 0, timeoutRetries: 0,
), throwsA(isA<ProcessException>())); ), throwsA(isA<ProcessException>()));
time.elapse(timeout);
});
}); });
}); });
......
...@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/devfs.dart'; ...@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import 'package:quiver/testing/async.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
...@@ -140,6 +141,7 @@ void main() { ...@@ -140,6 +141,7 @@ void main() {
); );
await devFS.create(); await devFS.create();
FakeAsync().run((FakeAsync time) async {
final UpdateFSReport report = await devFS.update( final UpdateFSReport report = await devFS.update(
mainUri: Uri.parse('lib/foo.txt'), mainUri: Uri.parse('lib/foo.txt'),
dillOutputPath: 'lib/foo.dill', dillOutputPath: 'lib/foo.dill',
...@@ -149,6 +151,7 @@ void main() { ...@@ -149,6 +151,7 @@ void main() {
invalidatedFiles: <Uri>[], invalidatedFiles: <Uri>[],
packageConfig: PackageConfig.empty, packageConfig: PackageConfig.empty,
); );
time.elapse(const Duration(seconds: 2));
expect(report.syncedBytes, 5); expect(report.syncedBytes, 5);
expect(report.success, isTrue); expect(report.success, isTrue);
...@@ -156,6 +159,7 @@ void main() { ...@@ -156,6 +159,7 @@ void main() {
verify(httpRequest.close()).called(kFailedAttempts + 1); verify(httpRequest.close()).called(kFailedAttempts + 1);
verify(osUtils.gzipLevel1Stream(any)).called(kFailedAttempts + 1); verify(osUtils.gzipLevel1Stream(any)).called(kFailedAttempts + 1);
}); });
});
testWithoutContext('DevFS reports unsuccessful compile when errors are returned', () async { testWithoutContext('DevFS reports unsuccessful compile when errors are returned', () async {
final FileSystem fileSystem = MemoryFileSystem.test(); final FileSystem fileSystem = MemoryFileSystem.test();
......
...@@ -261,16 +261,19 @@ void main() { ...@@ -261,16 +261,19 @@ void main() {
]) ])
); );
FakeAsync().run((FakeAsync time) async {
final LaunchResult launchResult = await iosDevice.startApp( final LaunchResult launchResult = await iosDevice.startApp(
buildableIOSApp, buildableIOSApp,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
platformArgs: <String, Object>{}, platformArgs: <String, Object>{},
); );
time.elapse(const Duration(seconds: 2));
expect(logger.statusText, expect(logger.statusText,
contains('Xcode build failed due to concurrent builds, will retry in 2 seconds')); contains('Xcode build failed due to concurrent builds, will retry in 2 seconds'));
expect(launchResult.started, true); expect(launchResult.started, true);
expect(processManager.hasRemainingExpectations, false); expect(processManager.hasRemainingExpectations, false);
});
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => processManager, ProcessManager: () => processManager,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
......
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