Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Josh van Leeuwen <[email protected]>
Signed-off-by: Cassie Coyle <[email protected]>
  • Loading branch information
cicoyle and JoshVanL authored Nov 25, 2024
1 parent d445bf3 commit 662be31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
4 changes: 0 additions & 4 deletions cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ func Test_Run(t *testing.T) {
cron := cronI.(*cron)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh1 := make(chan error)
errCh2 := make(chan error)

go func() {
errCh1 <- cronI.Run(ctx)
close(errCh1)
}()

select {
Expand All @@ -66,7 +64,6 @@ func Test_Run(t *testing.T) {

go func() {
errCh2 <- cronI.Run(ctx)
close(errCh2)
}()

select {
Expand Down Expand Up @@ -112,7 +109,6 @@ func Test_Run(t *testing.T) {

go func() {
errCh <- cronI.Run(ctx)
close(errCh)
}()

// wait until ready
Expand Down
25 changes: 8 additions & 17 deletions internal/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,16 @@ func Test_Run(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, engine)

ctx1, cancel1 := context.WithCancel(context.Background())
defer cancel1()

startedCh := make(chan struct{})
go func() {
close(startedCh)
_ = engine.Run(ctx1)
}()
<-startedCh // ensure engine starts

ctx2, cancel2 := context.WithCancel(context.Background())
defer cancel2()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

err = engine.Run(ctx2)
require.Error(t, err)
assert.Contains(t, err.Error(), "engine is already running")
errCh := make(chan error)
go func() { errCh <- engine.Run(ctx) }()
go func() { errCh <- engine.Run(ctx) }()
require.Error(t, <-errCh)
cancel()
require.NoError(t, <-errCh)

// Cancel the first Run to allow cleanup
cancel1()
})
}

Expand Down

0 comments on commit 662be31

Please sign in to comment.