Files
sm-emby-share/test/features/player/session/relink_scheduler_test.dart
T

48 lines
1.3 KiB
Dart
Raw Normal View History

2026-07-14 11:11:36 +08:00
import 'package:fake_async/fake_async.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:smplayer/features/player/session/relink_scheduler.dart';
void main() {
group('RelinkScheduler', () {
test('schedule cancels pending sustain timer (attempts must accumulate)',
() {
fakeAsync((async) {
final s = RelinkScheduler();
var gaveUp = false;
void failOnce() {
s.schedule(onRelink: (_) {}, onGiveUp: () => gaveUp = true);
async.flushTimers(flushPeriodicTimers: false);
s.armSustain(sustain: const Duration(seconds: 10));
async.elapse(const Duration(seconds: 5));
}
failOnce();
failOnce();
failOnce();
expect(gaveUp, isFalse);
s.schedule(onRelink: (_) {}, onGiveUp: () => gaveUp = true);
expect(gaveUp, isTrue);
s.dispose();
});
});
test('sustained playback resets attempts', () {
fakeAsync((async) {
final s = RelinkScheduler();
s.schedule(onRelink: (_) {}, onGiveUp: () {});
async.flushTimers(flushPeriodicTimers: false);
expect(s.attempts, 1);
s.armSustain(sustain: const Duration(seconds: 10));
async.elapse(const Duration(seconds: 11));
expect(s.attempts, 0);
s.dispose();
});
});
});
}