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

TestRcJobList listed the jobs left running in the global job list by
the previous run of the tests, so reset the global job list first.
This commit is contained in:
Nick Craig-Wood committed 2026-09-20 11:14:24 +01:00
1 parent 3cbb7c8545
commit 10cede9f7f
1 file changed
+10 -2
+10 -2
View File
@@ -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)