mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 06:43:42 +00:00
feat: queue extractions (#1227)
This commit is contained in:
1 parent
de0afb1481
commit
24db9bb58b
35 files changed
+1047
-159
No files matched your search
@@ -1420,6 +1420,7 @@ func TestExtractStatus(t *testing.T) {
|
||||
expected string
|
||||
}{
|
||||
{ExtractStatusNone, ""},
|
||||
{ExtractStatusQueued, "queued"},
|
||||
{ExtractStatusExtracting, "extracting"},
|
||||
{ExtractStatusDone, "done"},
|
||||
{ExtractStatusError, "error"},
|
||||
@@ -2083,7 +2084,7 @@ func TestDownloader_CheckAllMultiPartTasksDone_NoRelatedTasks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownloader_IsMultiPartExtractionInProgress(t *testing.T) {
|
||||
func TestDownloader_TryClaimMultiPartExtraction(t *testing.T) {
|
||||
downloader := NewDownloader(nil)
|
||||
if err := downloader.Setup(); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -2097,50 +2098,58 @@ func TestDownloader_IsMultiPartExtractionInProgress(t *testing.T) {
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
baseName := "archive.7z"
|
||||
basePath := filepath.Join(tempDir, baseName)
|
||||
// GetMultiPartArchiveBaseName returns filepath.Join(dir, baseName)
|
||||
fullBaseName := filepath.Join(tempDir, baseName)
|
||||
|
||||
// Create task with no extraction status
|
||||
// Create tasks
|
||||
task1 := &Task{
|
||||
ID: "task1",
|
||||
Status: base.DownloadStatusDone,
|
||||
Meta: &fetcher.FetcherMeta{
|
||||
Opts: &base.Options{Path: tempDir},
|
||||
Res: &base.Resource{
|
||||
Files: []*base.FileInfo{{Name: baseName + ".001"}},
|
||||
Files: []*base.FileInfo{{Name: baseName + ".001", Path: ""}},
|
||||
},
|
||||
},
|
||||
Progress: &Progress{ExtractStatus: ExtractStatusNone},
|
||||
}
|
||||
initTask(task1)
|
||||
downloader.tasks = []*Task{task1}
|
||||
|
||||
// No extraction in progress
|
||||
if downloader.isMultiPartExtractionInProgress(basePath) {
|
||||
t.Error("isMultiPartExtractionInProgress() = true, want false")
|
||||
task2 := &Task{
|
||||
ID: "task2",
|
||||
Status: base.DownloadStatusDone,
|
||||
Meta: &fetcher.FetcherMeta{
|
||||
Opts: &base.Options{Path: tempDir},
|
||||
Res: &base.Resource{
|
||||
Files: []*base.FileInfo{{Name: baseName + ".002", Path: ""}},
|
||||
},
|
||||
},
|
||||
Progress: &Progress{ExtractStatus: ExtractStatusNone},
|
||||
}
|
||||
initTask(task2)
|
||||
|
||||
downloader.tasks = []*Task{task1, task2}
|
||||
|
||||
// Task1 should be able to claim extraction (no one has claimed yet)
|
||||
if !downloader.tryClaimMultiPartExtraction(task1, fullBaseName) {
|
||||
t.Error("tryClaimMultiPartExtraction() = false, want true (first claim)")
|
||||
}
|
||||
// task1's status should now be Queued
|
||||
if task1.Progress.ExtractStatus != ExtractStatusQueued {
|
||||
t.Errorf("task1.ExtractStatus = %v, want %v", task1.Progress.ExtractStatus, ExtractStatusQueued)
|
||||
}
|
||||
|
||||
// Set to extracting
|
||||
task1.Progress.ExtractStatus = ExtractStatusExtracting
|
||||
if !downloader.isMultiPartExtractionInProgress(basePath) {
|
||||
t.Error("isMultiPartExtractionInProgress() = false, want true (extracting)")
|
||||
// Task2 should NOT be able to claim (task1 already claimed via sync.Map)
|
||||
if downloader.tryClaimMultiPartExtraction(task2, fullBaseName) {
|
||||
t.Error("tryClaimMultiPartExtraction() = true, want false (already claimed)")
|
||||
}
|
||||
|
||||
// Set to done
|
||||
task1.Progress.ExtractStatus = ExtractStatusDone
|
||||
if !downloader.isMultiPartExtractionInProgress(basePath) {
|
||||
t.Error("isMultiPartExtractionInProgress() = false, want true (done)")
|
||||
}
|
||||
// Release the claim
|
||||
downloader.releaseMultiPartExtractionClaim(fullBaseName)
|
||||
|
||||
// Set to error
|
||||
task1.Progress.ExtractStatus = ExtractStatusError
|
||||
if !downloader.isMultiPartExtractionInProgress(basePath) {
|
||||
t.Error("isMultiPartExtractionInProgress() = false, want true (error)")
|
||||
}
|
||||
|
||||
// Set to waiting parts (not in progress)
|
||||
task1.Progress.ExtractStatus = ExtractStatusWaitingParts
|
||||
if downloader.isMultiPartExtractionInProgress(basePath) {
|
||||
t.Error("isMultiPartExtractionInProgress() = true, want false (waitingParts)")
|
||||
// Now task2 CAN claim (claim was released)
|
||||
if !downloader.tryClaimMultiPartExtraction(task2, fullBaseName) {
|
||||
t.Error("tryClaimMultiPartExtraction() = false, want true (claim was released)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user