Skip to content

test: add logging to TestWorkspaceActivityBump/Dial #15089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: include avg check time in eventually loop
If the hypothesis of a 10s time drift is true, this loop might be
acting slow.
  • Loading branch information
Emyrk committed Oct 15, 2024
commit 81b08ab5e7bf85badb92830c00d6b70cefd6ec8f
19 changes: 15 additions & 4 deletions coderd/activitybump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func TestWorkspaceActivityBump(t *testing.T) {
return
}

// maxTimeDrift is how long we are willing wait for a deadline to
// be increased. Since it could have been bumped at the intial
maxTimeDrift := testutil.WaitMedium

var updatedAfter time.Time
// waitedFor is purely for debugging failed tests. If a test fails,
// it helps to know how long it took for the deadline bump to be
Expand All @@ -132,25 +136,32 @@ func TestWorkspaceActivityBump(t *testing.T) {
waitedFor := time.Now()
// lastChecked is for logging within the Eventually loop.
// Debouncing log lines to every second to prevent spam.
lastChecked := time.Now()
lastChecked := time.Time{}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made to time.Time so the first loop is always logged.

// checks is for keeping track of the average check time.
// If CI is running slow, this could be useful to know checks
// are taking longer than expected.
checks := 0

// The Deadline bump occurs asynchronously.
require.Eventuallyf(t,
func() bool {
checks++
workspace, err = client.Workspace(ctx, workspace.ID)
require.NoError(t, err)
updatedAfter = dbtime.Now()

if workspace.LatestBuild.Deadline.Time.Equal(firstDeadline) {
updatedAfter = time.Now()
if time.Since(lastChecked) > time.Second {
t.Logf("deadline still not updated, will continue to check: deadline=%v", workspace.LatestBuild.Deadline.Time)
avgCheckTime := time.Since(waitedFor) / time.Duration(checks)
t.Logf("deadline still not updated, will continue to check: avg_check_dur=%s checks=%d deadline=%v", avgCheckTime, checks, workspace.LatestBuild.Deadline.Time)
lastChecked = time.Now()
}
return false
}
return true
},
testutil.WaitMedium, testutil.IntervalFast,
maxTimeDrift, testutil.IntervalFast,
"deadline %v never updated", firstDeadline,
)

Expand All @@ -176,7 +187,7 @@ func TestWorkspaceActivityBump(t *testing.T) {
firstDeadline, workspace.LatestBuild.Deadline.Time, now,
now.Sub(workspace.LatestBuild.Deadline.Time),
)
require.WithinDuration(t, now.Add(ttl), workspace.LatestBuild.Deadline.Time, testutil.WaitShort)
require.WithinDuration(t, now.Add(ttl), workspace.LatestBuild.Deadline.Time, maxTimeDrift)
}
}

Expand Down