|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:querya_desktop/core/database/redis_connection.dart'; |
| 3 | + |
| 4 | +/// Counts outbound commands to prove [typesAndTtls] fires TYPE+TTL without |
| 5 | +/// awaiting between keys (true pipeline enqueue). |
| 6 | +class _CountingRedisFake extends RedisConnectionTestFake { |
| 7 | + _CountingRedisFake() : super(firstScanKeys: const []); |
| 8 | + |
| 9 | + final List<String> ops = []; |
| 10 | + |
| 11 | + @override |
| 12 | + Future<dynamic> sendCommand(List<dynamic> args) async { |
| 13 | + ops.add(args.first.toString().toUpperCase()); |
| 14 | + // Delay so overlapping awaits would change order if callers awaited per key. |
| 15 | + await Future<void>.delayed(Duration.zero); |
| 16 | + return super.sendCommand(args); |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +void main() { |
| 21 | + test('typesAndTtls enqueues all TYPE then all TTL before settling', () async { |
| 22 | + final fake = _CountingRedisFake(); |
| 23 | + await fake.connect(); |
| 24 | + |
| 25 | + final metas = await fake.typesAndTtls(['a', 'b', 'c']); |
| 26 | + |
| 27 | + expect(metas, hasLength(3)); |
| 28 | + expect(metas.map((m) => m.type), everyElement('string')); |
| 29 | + expect(metas.map((m) => m.ttl), everyElement(-1)); |
| 30 | + |
| 31 | + // All TYPE writes precede all TTL writes (single burst, not TYPE+TTL per key). |
| 32 | + expect( |
| 33 | + fake.ops, |
| 34 | + ['TYPE', 'TYPE', 'TYPE', 'TTL', 'TTL', 'TTL'], |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + test('typesAndTtls returns empty for empty keys', () async { |
| 39 | + final fake = RedisConnectionTestFake(); |
| 40 | + await fake.connect(); |
| 41 | + expect(await fake.typesAndTtls(const []), isEmpty); |
| 42 | + }); |
| 43 | +} |
0 commit comments