pumpBenchmark method
- 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;
void handleError(dynamic error, StackTrace stackTrace) => caughtException ??= error;
await Future<void>.microtask(() { binding.handleBeginFrame(duration); }).catchError(handleError);
await idle();
await Future<void>.microtask(() { binding.handleDrawFrame(); }).catchError(handleError);
await idle();
if (caughtException != null) {
throw caughtException as Object; // ignore: only_throw_errors, rethrowing caught exception.
}
}