mirror of https://github.com/go-co-op/gocron.git
Allow more time for requestJobCtx (#699)
* allow more time for jobout request * gofmt
This commit is contained in:
parent
ebec5e9f91
commit
b0bd435279
|
|
@ -1350,6 +1350,48 @@ func TestScheduler_RemoveJob(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestScheduler_RemoveLotsOfJobs(t *testing.T) {
|
||||
goleak.VerifyNone(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
numJobs int
|
||||
}{
|
||||
{
|
||||
"10 successes",
|
||||
10,
|
||||
},
|
||||
{
|
||||
"100 successes",
|
||||
100,
|
||||
},
|
||||
{
|
||||
"1000 successes",
|
||||
1000,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := newTestScheduler(t)
|
||||
|
||||
var ids []uuid.UUID
|
||||
for i := 0; i < tt.numJobs; i++ {
|
||||
j, err := s.NewJob(DurationJob(time.Second), NewTask(func() { time.Sleep(20 * time.Second) }))
|
||||
require.NoError(t, err)
|
||||
ids = append(ids, j.ID())
|
||||
}
|
||||
|
||||
for _, id := range ids {
|
||||
err := s.RemoveJob(id)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Len(t, s.Jobs(), 0)
|
||||
require.NoError(t, s.Shutdown())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestScheduler_WithEventListeners(t *testing.T) {
|
||||
goleak.VerifyNone(t)
|
||||
|
||||
|
|
|
|||
8
util.go
8
util.go
|
|
@ -44,18 +44,12 @@ func requestJob(id uuid.UUID, ch chan jobOutRequest) *internalJob {
|
|||
|
||||
func requestJobCtx(ctx context.Context, id uuid.UUID, ch chan jobOutRequest) *internalJob {
|
||||
resp := make(chan internalJob, 1)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case ch <- jobOutRequest{
|
||||
id: id,
|
||||
outChan: resp,
|
||||
}:
|
||||
default:
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
}
|
||||
var j internalJob
|
||||
|
|
|
|||
Loading…
Reference in New Issue