mirror of
https://github.com/samuelncui/acp.git
synced 2026-09-03 14:47:17 +00:00
fix copy status handoff before cleanup
This commit is contained in:
@@ -83,12 +83,12 @@ func (c *Copyer) copy(ctx context.Context, prepared <-chan *writeJob) <-chan *ba
|
||||
|
||||
func (c *Copyer) write(ctx context.Context, job *writeJob, ch chan<- *baseJob, cntr *counter, noSpaceDevices mapset.Set[string]) {
|
||||
job.setStatus(jobStatusCopying)
|
||||
defer job.setStatus(jobStatusFinishing)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer func() {
|
||||
wg.Wait()
|
||||
job.done()
|
||||
job.setStatus(jobStatusFinishing)
|
||||
ch <- job.baseJob
|
||||
}()
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package acp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
)
|
||||
|
||||
func TestCopyEmptyFile(t *testing.T) {
|
||||
@@ -73,3 +77,20 @@ func TestCopyEmptyFile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWritePublishesFinishingJob(t *testing.T) {
|
||||
// Build a target-free write Job so only the worker-to-cleanup handoff is exercised.
|
||||
copyer := &Copyer{option: newOption(), eventCh: make(chan Event, 8)}
|
||||
job := newWriteJob(&baseJob{
|
||||
copyer: copyer,
|
||||
src: &source{},
|
||||
stat: &stat{},
|
||||
}, io.NopCloser(bytes.NewReader(nil)), 0, false)
|
||||
completed := make(chan *baseJob, 1)
|
||||
|
||||
// The copy worker must finish all mutations before publishing ownership to cleanup.
|
||||
copyer.write(context.Background(), job, completed, new(counter), mapset.NewSet[string]())
|
||||
if status := (<-completed).status; status != jobStatusFinishing {
|
||||
t.Fatalf("published status = %q, want %q", status, jobStatusFinishing)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user