pumpBenchmark method

Future<void> pumpBenchmark(
  1. Duration duration
)

Triggers a frame after duration amount of time, return as soon as the frame is drawn.

This enables driving an artificially high CPU load by rendering frames in a tight loop. It must be used with the frame policy set to LiveTestWidgetsFlutterBindingFramePolicy.benchmark.

Similarly to pump, this doesn't actually wait for duration, just advances the clock.

Implementation

Future<void> pumpBenchmark(Duration duration) async {
  assert(() {
    final TestWidgetsFlutterBinding widgetsBinding = binding;
    return widgetsBinding is LiveTestWidgetsFlutterBinding &&
           widgetsBinding.framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
  }());

  dynamic caughtException;
  StackTrace? stackTrace;
  void handleError(dynamic error, StackTrace trace)  {
    caughtException ??= error;
    stackTrace ??= trace;
  }

  await Future<void>.microtask(() { binding.handleBeginFrame(duration); }).catchError(handleError);
  await idle();
  await Future<void>.microtask(() { binding.handleDrawFrame(); }).catchError(handleError);
  await idle();

  if (caughtException != null) {
    Error.throwWithStackTrace(caughtException as Object, stackTrace!);
  }
}