Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

jobs: fix tests failing and racing when run with -count > 1

Nick Craig-Wooddd07bb33ba6e
diff --git a/fs/rc/jobs/job_test.go b/fs/rc/jobs/job_test.go
index 424e2d4d5..c4f1ca7de 100644
--- a/fs/rc/jobs/job_test.go
+++ b/fs/rc/jobs/job_test.go
@@ -25,7 +25,9 @@ func TestNewJobs(t *testing.T) {
func TestJobsKickExpire(t *testing.T) {
testy.SkipUnreliable(t)
jobs := newJobs()
- jobs.opt.JobExpireInterval = fs.Duration(time.Millisecond)
+ opt := rc.Opt // copy so we don't change the global options
+ opt.JobExpireInterval = fs.Duration(time.Millisecond)
+ jobs.opt = &opt
assert.Equal(t, false, jobs.expireRunning)
jobs.kickExpire()
jobs.mu.Lock()
@@ -42,7 +44,9 @@ func TestJobsExpire(t *testing.T) {
ctx := context.Background()
wait := make(chan struct{})
jobs := newJobs()
- jobs.opt.JobExpireInterval = fs.Duration(time.Millisecond)
+ opt := rc.Opt // copy so we don't change the global options
+ opt.JobExpireInterval = fs.Duration(time.Millisecond)
+ jobs.opt = &opt
assert.Equal(t, false, jobs.expireRunning)
var gotJobID int64
var gotJob *Job
@@ -553,6 +557,10 @@ func TestRcJobStatus(t *testing.T) {
func TestRcJobList(t *testing.T) {
ctx := context.Background()
jobID.Store(0)
+ // Don't list the jobs left running by other tests
+ running.mu.Lock()
+ running.jobs = map[int64]*Job{}
+ running.mu.Unlock()
_, _, err := NewJob(ctx, longFn, rc.Params{"_async": true})
assert.NoError(t, err)