Initial flame_lua_runtime package
This commit is contained in:
59
test/runtime/lifecycle/runtime_serial_queue_test.dart
Normal file
59
test/runtime/lifecycle/runtime_serial_queue_test.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:flame_lua_runtime/runtime/lifecycle/runtime_serial_queue.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RuntimeSerialQueue', () {
|
||||
test('drains queued items in order on a microtask', () async {
|
||||
final handled = <int>[];
|
||||
final queue = RuntimeSerialQueue<int>(onItem: handled.add);
|
||||
|
||||
queue
|
||||
..enqueue(1)
|
||||
..enqueue(2)
|
||||
..enqueue(3);
|
||||
|
||||
expect(handled, isEmpty);
|
||||
expect(queue.pendingCount, 3);
|
||||
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(handled, [1, 2, 3]);
|
||||
expect(queue.pendingCount, 0);
|
||||
});
|
||||
|
||||
test('stops draining when shouldContinue turns false', () async {
|
||||
final handled = <int>[];
|
||||
var active = true;
|
||||
late final RuntimeSerialQueue<int> queue;
|
||||
queue = RuntimeSerialQueue<int>(
|
||||
shouldContinue: () => active,
|
||||
onItem: (item) {
|
||||
handled.add(item);
|
||||
active = false;
|
||||
},
|
||||
);
|
||||
|
||||
queue
|
||||
..enqueue(1)
|
||||
..enqueue(2);
|
||||
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(handled, [1]);
|
||||
expect(queue.pendingCount, 1);
|
||||
});
|
||||
|
||||
test('dispose drops pending items', () async {
|
||||
final handled = <int>[];
|
||||
final queue = RuntimeSerialQueue<int>(onItem: handled.add);
|
||||
|
||||
queue.enqueue(1);
|
||||
queue.dispose();
|
||||
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(handled, isEmpty);
|
||||
expect(queue.pendingCount, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user