perf(downloads): bound native queue state

This commit is contained in:
zarzet
2026-08-27 00:17:25 +07:00
parent 5e8608cef9
commit 04c42bd511
10 changed files with 483 additions and 108 deletions
+40
View File
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
@@ -688,6 +689,45 @@ void main() {
expect(item.toJson()['errorType'], 'network');
expect(item.toJson()['preparationStage'], isEmpty);
});
test('persists restart-safe state without transient transfer progress', () {
final item = DownloadItem(
id: 'download-active',
track: sampleTrack(),
service: 'tidal',
createdAt: DateTime.utc(2026),
status: DownloadStatus.finalizing,
progress: 0.97,
speedMBps: 3.5,
bytesReceived: 970,
bytesTotal: 1000,
preparationStage: 'embedding_metadata',
);
final persisted =
jsonDecode(encodeDownloadQueueItemForPersistence(item))
as Map<String, dynamic>;
expect(persisted['id'], item.id);
expect(persisted['status'], DownloadStatus.queued.name);
expect(persisted['progress'], 0.0);
expect(persisted['speedMBps'], 0.0);
expect(persisted['bytesReceived'], 0);
expect(persisted['bytesTotal'], 0);
expect(persisted['preparationStage'], isEmpty);
});
});
group('Download queue processing gate', () {
test('allows only one asynchronous startup at a time', () {
final gate = QueueProcessingGate();
expect(gate.tryEnter(), isTrue);
expect(gate.tryEnter(), isFalse);
expect(gate.leave(), isTrue);
expect(gate.tryEnter(), isTrue);
expect(gate.leave(), isFalse);
});
});
group('Download queue lookup', () {