mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-13 04:26:16 -08:00
fix(downloads): refresh stable season skips
This commit is contained in:
1 parent
3ef5293cf4
commit
dc8da931ea
4 files changed
+55
-16
No files matched your search
+38
-1
@@ -183,7 +183,44 @@ describe('SeasonDownloadCoordinator', () => {
|
||||
|
||||
expect(restored.prepare).toHaveBeenCalledTimes(1);
|
||||
expect(downloadsService.startDownload).toHaveBeenCalledTimes(1);
|
||||
expect(downloadsService.loadDownloads).not.toHaveBeenCalled();
|
||||
expect(downloadsService.loadDownloads).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('refreshes once after a season contains only submitted stable skips', async () => {
|
||||
const first = candidate(FIRST_IDENTITY);
|
||||
const second = candidate(identity(102, 2));
|
||||
const refresh = deferred<void>();
|
||||
const refreshStarted = deferred<void>();
|
||||
downloadsService.startDownload
|
||||
.mockResolvedValueOnce({
|
||||
success: false,
|
||||
reason: 'already-downloaded' as never,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
success: false,
|
||||
reason: 'already-in-progress',
|
||||
});
|
||||
downloadsService.loadDownloads.mockImplementation(() => {
|
||||
refreshStarted.resolve(undefined);
|
||||
return refresh.promise;
|
||||
});
|
||||
|
||||
const submission = coordinator.enqueueSeason([first, second]);
|
||||
await refreshStarted.promise;
|
||||
|
||||
expect(downloadsService.startDownload).toHaveBeenCalledTimes(2);
|
||||
expect(downloadsService.loadDownloads).toHaveBeenCalledTimes(1);
|
||||
expect(coordinator.isPending(first.identity)).toBe(true);
|
||||
expect(coordinator.isPending(second.identity)).toBe(true);
|
||||
|
||||
refresh.resolve(undefined);
|
||||
await expect(submission).resolves.toEqual({
|
||||
added: 0,
|
||||
skipped: 2,
|
||||
failed: 0,
|
||||
});
|
||||
expect(coordinator.isPending(first.identity)).toBe(false);
|
||||
expect(coordinator.isPending(second.identity)).toBe(false);
|
||||
});
|
||||
|
||||
it('continues after preparation rejects and refreshes once after successes', async () => {
|
||||
|
||||
+6
-6
@@ -57,7 +57,7 @@ export class SeasonDownloadCoordinator {
|
||||
}
|
||||
|
||||
const submission = await this.submit(candidate);
|
||||
if (submission !== EPISODE_DOWNLOAD_SUBMISSIONS.Added) {
|
||||
if (submission === EPISODE_DOWNLOAD_SUBMISSIONS.Failed) {
|
||||
this.release(candidate.identity);
|
||||
return submission;
|
||||
}
|
||||
@@ -84,22 +84,22 @@ export class SeasonDownloadCoordinator {
|
||||
reserved.push(candidate);
|
||||
}
|
||||
|
||||
const accepted: EpisodeDownloadIdentity[] = [];
|
||||
const refreshPending: EpisodeDownloadIdentity[] = [];
|
||||
for (const candidate of reserved) {
|
||||
const submission = await this.submit(candidate);
|
||||
result[submission] += 1;
|
||||
if (submission === EPISODE_DOWNLOAD_SUBMISSIONS.Added) {
|
||||
accepted.push(candidate.identity);
|
||||
if (submission !== EPISODE_DOWNLOAD_SUBMISSIONS.Failed) {
|
||||
refreshPending.push(candidate.identity);
|
||||
} else {
|
||||
this.release(candidate.identity);
|
||||
}
|
||||
}
|
||||
|
||||
if (accepted.length > 0) {
|
||||
if (refreshPending.length > 0) {
|
||||
try {
|
||||
await this.downloadsService.loadDownloads();
|
||||
} finally {
|
||||
this.releaseAll(accepted);
|
||||
this.releaseAll(refreshPending);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user