Skip to content

Commit

Permalink
internal/{task,workflow}: scale watchdog delay by GO_TEST_TIMEOUT_SCALE
Browse files Browse the repository at this point in the history
Longtest builders are known to apply a scale factor on the default
go test timeout (10 minutes). Do the same in relui.

For golang/go#60443.

Change-Id: If0e7c21fdf7916745ce65db0c73a730091a506f7
Reviewed-on: https://go-review.googlesource.com/c/build/+/504523
Auto-Submit: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Run-TryBot: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
  • Loading branch information
dmitshur authored and gopherbot committed Jun 22, 2023
1 parent 9a22855 commit 6b61669
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/task/buildrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func (b *BuildletStep) TestTarget(ctx *workflow.TaskContext, binaryArchive io.Re
}
}
ctx.Printf("Building (all.bash to ensure tests pass).")
ctx.SetWatchdogScale(b.BuildConfig.GoTestTimeoutScale())
return b.exec(ctx, goDir+"/"+b.BuildConfig.AllScript(), b.BuildConfig.AllScriptArgs(), buildlet.ExecOpts{
ExtraEnv: b.makeEnv(),
})
Expand Down Expand Up @@ -595,6 +596,7 @@ func (b *BuildletStep) RunTryBot(ctx *workflow.TaskContext, sourceArchive io.Rea
}

ctx.Printf("Testing (all.bash).")
ctx.SetWatchdogScale(b.BuildConfig.GoTestTimeoutScale())
err := b.exec(ctx, goDir+"/"+b.BuildConfig.AllScript(), b.BuildConfig.AllScriptArgs(), buildlet.ExecOpts{})
if err != nil {
ctx.Printf("testing failed: %v", err)
Expand Down
16 changes: 14 additions & 2 deletions internal/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ type TaskContext struct {
WorkflowID uuid.UUID

watchdogTimer *time.Timer
watchdogScale int
}

func (c *TaskContext) Printf(format string, v ...interface{}) {
Expand All @@ -463,7 +464,17 @@ func (c *TaskContext) DisableRetries() {
}

func (c *TaskContext) ResetWatchdog() {
c.resetWatchdog(WatchdogDelay)
c.resetWatchdog(WatchdogDelay * time.Duration(c.watchdogScale))
}

// SetWatchdogScale sets the watchdog delay scale factor to max(v, 1),
// and resets the watchdog with the new scale.
func (c *TaskContext) SetWatchdogScale(v int) {
if v < 1 {
v = 1
}
c.watchdogScale = v
c.ResetWatchdog()
}

func (c *TaskContext) DisableWatchdog() {
Expand Down Expand Up @@ -836,7 +847,7 @@ func (w *Workflow) taskArgs(def *taskDefinition) ([]reflect.Value, bool) {
// Maximum number of retries. This could be a workflow property.
var MaxRetries = 3

var WatchdogDelay = 10 * time.Minute
var WatchdogDelay = 11 * time.Minute // A little over go test -timeout's default value of 10 minutes.

func runTask(ctx context.Context, workflowID uuid.UUID, listener Listener, state taskState, args []reflect.Value) taskState {
ctx, cancel := context.WithCancel(ctx)
Expand All @@ -848,6 +859,7 @@ func runTask(ctx context.Context, workflowID uuid.UUID, listener Listener, state
TaskName: state.def.name,
WorkflowID: workflowID,
watchdogTimer: time.AfterFunc(WatchdogDelay, cancel),
watchdogScale: 1,
}

in := append([]reflect.Value{reflect.ValueOf(tctx)}, args...)
Expand Down

0 comments on commit 6b61669

Please sign in to comment.