Skip to content

Commit

Permalink
fix(test): Notify ctx to be cancelled on OS interrupt and termination…
Browse files Browse the repository at this point in the history
… signals

Signed-off-by: Alex Castilio dos Santos <[email protected]>
  • Loading branch information
alexcastilio committed Feb 6, 2025
1 parent 7d44787 commit 13c5e07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion test/e2e/framework/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package helpers

import (
"context"
"os/signal"
"syscall"
"testing"
"time"
)
Expand All @@ -20,5 +22,8 @@ func Context(t *testing.T) (context.Context, context.CancelFunc) {
// Subtract a minute from the deadline to ensure we have time to cleanup
deadline = deadline.Add(-time.Minute)

return context.WithDeadline(context.Background(), deadline)
ctx, cancel := context.WithDeadline(context.Background(), deadline)
ctx, cancel = signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)

return ctx, cancel
}
2 changes: 1 addition & 1 deletion test/e2e/framework/types/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *Runner) Run(ctx context.Context) {
}()
select {
case <-ctx.Done():
r.t.Fatal("Test deadline exceeded. If more time is needed, set -timeout flag to a higher value")
r.t.Fatal("Failed to complete execution:", ctx.Err())
case err := <-runComplete:
require.NoError(r.t, err)
}
Expand Down

0 comments on commit 13c5e07

Please sign in to comment.