Skip to content

Commit

Permalink
Allow more time for requestJobCtx (#699)
Browse files Browse the repository at this point in the history
* allow more time for jobout request

* gofmt
  • Loading branch information
drewgonzales360 committed Mar 23, 2024
1 parent ebec5e9 commit b0bd435
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
42 changes: 42 additions & 0 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 1 addition & 7 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0bd435

Please sign in to comment.