Skip to content

Commit

Permalink
fix scheduler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Jan 8, 2025
1 parent ae34a38 commit 9bedc01
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions flutter/test/replay/scheduler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ void main() {
expect(fixture.calls, 0);
await fixture.drawFrame();
expect(fixture.calls, 1);
await fixture.drawFrame();
await fixture.drawFrame();
await fixture.drawFrame();
await fixture
.drawFrame()
.timeout(const Duration(milliseconds: 200), onTimeout: () => null);
expect(fixture.calls, 1);

guard.complete();
Expand All @@ -77,7 +77,7 @@ void main() {
class _Fixture {
var calls = 0;
late final Scheduler sut;
FrameCallback? registeredCallback;
var registeredCallback = Completer<FrameCallback>();
var _frames = 0;

_Fixture([SchedulerCallback? callback]) {
Expand All @@ -93,17 +93,18 @@ class _Fixture {

void _addPostFrameCallbackMock(FrameCallback callback,
{String debugLabel = 'callback'}) {
registeredCallback = callback;
if (!registeredCallback.isCompleted) {
registeredCallback.complete(callback);
}
}

factory _Fixture.started() {
return _Fixture()..sut.start();
}

Future<void> drawFrame() async {
await Future.delayed(const Duration(milliseconds: 8), () {});
_frames++;
registeredCallback?.call(Duration(milliseconds: _frames));
registeredCallback = null;
Future<void> drawFrame() {
registeredCallback = Completer<FrameCallback>();
return registeredCallback.future
.then((fn) => fn(Duration(milliseconds: ++_frames)));
}
}

0 comments on commit 9bedc01

Please sign in to comment.