完善遥控权限、控制发送和急停反馈
This commit is contained in:
84
test/control_frame_scheduler_test.dart
Normal file
84
test/control_frame_scheduler_test.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/tcp/control_frame_scheduler.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('movement waits 250ms and replaces pending older input', (
|
||||
tester,
|
||||
) async {
|
||||
var nowUs = 0;
|
||||
final scheduler = ControlFrameScheduler(nowUs: () => nowUs);
|
||||
final writes = <int>[];
|
||||
Future<bool> write(int input) async {
|
||||
writes.add(input);
|
||||
return true;
|
||||
}
|
||||
|
||||
final first = scheduler.submit(
|
||||
() => write(10),
|
||||
priority: false,
|
||||
isCurrent: () => true,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(await first, isTrue);
|
||||
nowUs = 100000;
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
final replaced = scheduler.submit(
|
||||
() => write(20),
|
||||
priority: false,
|
||||
isCurrent: () => true,
|
||||
);
|
||||
nowUs = 200000;
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
final latest = scheduler.submit(
|
||||
() => write(30),
|
||||
priority: false,
|
||||
isCurrent: () => true,
|
||||
);
|
||||
expect(await replaced, isFalse);
|
||||
expect(writes, [10]);
|
||||
nowUs = 249000;
|
||||
await tester.pump(const Duration(milliseconds: 49));
|
||||
expect(writes, [10]);
|
||||
nowUs = 250000;
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(await latest, isTrue);
|
||||
expect(writes, [10, 30]);
|
||||
});
|
||||
|
||||
testWidgets('priority zero replaces movement and shares the 250ms gate', (
|
||||
tester,
|
||||
) async {
|
||||
var nowUs = 0;
|
||||
final scheduler = ControlFrameScheduler(nowUs: () => nowUs);
|
||||
final writes = <int>[];
|
||||
Future<bool> write(int input) async {
|
||||
writes.add(input);
|
||||
return true;
|
||||
}
|
||||
|
||||
scheduler.submit(() => write(50), priority: false, isCurrent: () => true);
|
||||
await tester.pump();
|
||||
nowUs = 100000;
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
final movement = scheduler.submit(
|
||||
() => write(75),
|
||||
priority: false,
|
||||
isCurrent: () => true,
|
||||
);
|
||||
nowUs = 150000;
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
final stop = scheduler.submit(
|
||||
() => write(0),
|
||||
priority: true,
|
||||
isCurrent: () => true,
|
||||
);
|
||||
expect(await movement, isFalse);
|
||||
nowUs = 249000;
|
||||
await tester.pump(const Duration(milliseconds: 99));
|
||||
expect(writes, [50]);
|
||||
nowUs = 250000;
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(await stop, isTrue);
|
||||
expect(writes, [50, 0]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user