Commit 0c7fe40e authored by TruongSinh Tran-Nguyen's avatar TruongSinh Tran-Nguyen Committed by Michael Goderbauer

fix #19175 How should addTime be used from a test? (#25202)

parent ec27e045
...@@ -125,6 +125,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -125,6 +125,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
@protected @protected
bool get disableShadows => false; bool get disableShadows => false;
/// Increase the timeout for the current test by the given duration.
void addTime(Duration duration) {
// Noop, see [AutomatedTestWidgetsFlutterBinding. addTime] for an actual implementation.
}
/// The value to set [debugCheckIntrinsicSizes] to while tests are running. /// The value to set [debugCheckIntrinsicSizes] to while tests are running.
/// ///
/// This can be used to enable additional checks. For example, /// This can be used to enable additional checks. For example,
...@@ -843,7 +848,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -843,7 +848,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
_timeoutCompleter.completeError( _timeoutCompleter.completeError(
TimeoutException( TimeoutException(
'The test exceeded the timeout. It may have hung.\n' 'The test exceeded the timeout. It may have hung.\n'
'Consider using "addTime" to increase the timeout before expensive operations.', 'Consider using "tester.binding.addTime" to increase the timeout before expensive operations.',
_timeout, _timeout,
), ),
); );
...@@ -873,6 +878,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -873,6 +878,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
/// ///
/// * [defaultTestTimeout], the maximum that the timeout can reach. /// * [defaultTestTimeout], the maximum that the timeout can reach.
/// (That timeout is implemented by the test package.) /// (That timeout is implemented by the test package.)
@override
void addTime(Duration duration) { void addTime(Duration duration) {
assert(_timeout != null, 'addTime can only be called during a test.'); assert(_timeout != null, 'addTime can only be called during a test.');
_timeout += duration; _timeout += duration;
......
...@@ -49,6 +49,14 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester); ...@@ -49,6 +49,14 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
/// ///
/// The callback can be asynchronous (using `async`/`await` or /// The callback can be asynchronous (using `async`/`await` or
/// using explicit [Future]s). /// using explicit [Future]s).
/// Tests using the [AutomatedTestWidgetsFlutterBinding]
/// have a default time out of two seconds,
/// which is automatically increased for some expensive operations,
/// and can also be manually increased by calling
/// [AutomatedTestWidgetsFlutterBinding.addTime].
/// The maximum that this timeout can reach (automatically or manually increased)
/// is defined by the timeout property,
/// which defaults to [TestWidgetsFlutterBinding.defaultTestTimeout].
/// ///
/// This function uses the [test] function in the test package to /// This function uses the [test] function in the test package to
/// register the given callback as a test. The callback, when run, /// register the given callback as a test. The callback, when run,
...@@ -56,6 +64,11 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester); ...@@ -56,6 +64,11 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
/// provides convenient widget [Finder]s for use with the /// provides convenient widget [Finder]s for use with the
/// [WidgetTester]. /// [WidgetTester].
/// ///
/// See also:
///
/// * [AutomatedTestWidgetsFlutterBinding.addTime] to learn more about
/// timeout and how to manually increase timeouts.
///
/// ## Sample code /// ## Sample code
/// ///
/// ```dart /// ```dart
......
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