Skip to content

Commit

Permalink
Fix context usage in some tests, add metrics processing delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Dec 15, 2020
1 parent b0b06c9 commit c12f449
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions api/v1/status_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ func TestPatchStatus(t *testing.T) {
require.NoError(t, err)
engine, err := core.NewEngine(execScheduler, options, logger)
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
run, _, err := engine.Init(ctx, ctx)
globalCtx, globalCancel := context.WithTimeout(context.Background(), 2*time.Second)
runCtx, runCancel := context.WithCancel(globalCtx)
run, waitFn, err := engine.Init(globalCtx, runCtx)
require.NoError(t, err)
defer func() {
runCancel()
// Wait for metrics processing to finish
time.Sleep(100 * time.Millisecond)
globalCancel()
waitFn()
}()

go func() { _ = run() }()
// wait for the executor to initialize to avoid a potential data race below
Expand Down
2 changes: 2 additions & 0 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func newTestEngine( //nolint:golint
if runCancel != nil {
runCancel()
}
// Wait for metrics processing to finish
time.Sleep(100 * time.Millisecond)
globalCancel()
waitFn()
}
Expand Down

0 comments on commit c12f449

Please sign in to comment.