Skip to content

Commit

Permalink
fix: scheduler test
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Jan 8, 2025
1 parent 32f5b35 commit 9d4a3f9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions flutter/test/replay/scheduler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ void main() {
await fixture.drawFrame();
expect(fixture.calls, 1);
await fixture.drawFrame();
expect(fixture.calls, 2);
await fixture.sut.stop();
await fixture.drawFrame();
await fixture.drawFrame(awaitCallback: false);
expect(fixture.calls, 2);
});

Expand All @@ -47,7 +48,7 @@ void main() {
await fixture.drawFrame();
expect(fixture.calls, 1);
await fixture.sut.stop();
await fixture.drawFrame();
await fixture.drawFrame(awaitCallback: false);
expect(fixture.calls, 1);
fixture.sut.start();
await fixture.drawFrame();
Expand All @@ -63,9 +64,7 @@ void main() {
expect(fixture.calls, 0);
await fixture.drawFrame();
expect(fixture.calls, 1);
await fixture
.drawFrame()
.timeout(const Duration(milliseconds: 200), onTimeout: () => null);
await fixture.drawFrame(awaitCallback: false);
expect(fixture.calls, 1);

guard.complete();
Expand Down Expand Up @@ -102,9 +101,15 @@ class _Fixture {
return _Fixture()..sut.start();
}

Future<void> drawFrame() {
Future<void> drawFrame({bool awaitCallback = true}) async {
registeredCallback = Completer<FrameCallback>();
final timestamp = Duration(milliseconds: ++_frames);
return registeredCallback.future.then((fn) => fn(timestamp));
final future = registeredCallback.future.then((fn) => fn(timestamp));
if (awaitCallback) {
return future;
} else {
return future.timeout(const Duration(milliseconds: 200),
onTimeout: () {});
}
}
}

0 comments on commit 9d4a3f9

Please sign in to comment.