Skip to content

chore: de-flake TestWorkspaceAgent_Metadata (round 2) #7039

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 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions agent/reaper/reaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestReap(t *testing.T) {
// Don't run the reaper test in CI. It does weird
// things like forkexecing which may have unintended
// consequences in CI.
if _, ok := os.LookupEnv("CI"); ok {
if testutil.InCI() {
t.Skip("Detected CI, skipping reaper tests")
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func TestReapInterrupt(t *testing.T) {
// Don't run the reaper test in CI. It does weird
// things like forkexecing which may have unintended
// consequences in CI.
if _, ok := os.LookupEnv("CI"); ok {
if testutil.InCI() {
t.Skip("Detected CI, skipping reaper tests")
}

Expand Down
10 changes: 7 additions & 3 deletions coderd/workspaceagents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,16 +1353,20 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
var update []codersdk.WorkspaceAgentMetadata

check := func(want codersdk.WorkspaceAgentMetadataResult, got codersdk.WorkspaceAgentMetadata) {
require.Greater(t, got.Result.CollectedAt, want.CollectedAt)
require.Equal(t, want.Value, got.Result.Value)
require.Equal(t, want.Error, got.Result.Error)

if testutil.InCI() && (runtime.GOOS == "windows" || testutil.InRaceMode()) {
// Avoid testing timings when flake chance is high.
return
}
require.WithinDuration(t, got.Result.CollectedAt, want.CollectedAt, time.Second)
ageImpliedNow := got.Result.CollectedAt.Add(time.Duration(got.Result.Age) * time.Second)
// We use a long WithinDuration to tolerate slow CI, but we're still making sure
// that Age is within the ballpark.
require.WithinDuration(
t, time.Now(), ageImpliedNow, time.Second*10,
)
require.Equal(t, want.Value, got.Result.Value)
require.Equal(t, want.Error, got.Result.Error)
}

wantMetadata1 := codersdk.WorkspaceAgentMetadataResult{
Expand Down
4 changes: 3 additions & 1 deletion helm/tests/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/stretchr/testify/require"
"golang.org/x/xerrors"

"github.com/coder/coder/testutil"
)

// These tests run `helm template` with the values file specified in each test
Expand Down Expand Up @@ -54,7 +56,7 @@ func TestRenderChart(t *testing.T) {
if *UpdateGoldenFiles {
t.Skip("Golden files are being updated. Skipping test.")
}
if _, runningInCI := os.LookupEnv("CI"); runningInCI {
if testutil.InCI() {
switch runtime.GOOS {
case "windows", "darwin":
t.Skip("Skipping tests on Windows and macOS in CI")
Expand Down
16 changes: 16 additions & 0 deletions testutil/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testutil

import (
"flag"
"os"
)

func InCI() bool {
_, ok := os.LookupEnv("CI")
return ok
}

func InRaceMode() bool {
fl := flag.Lookup("race")
return fl != nil && fl.Value.String() == "true"
}
4 changes: 3 additions & 1 deletion testutil/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

package testutil

import "time"
import (
"time"
)

// Constants for timing out operations, usable for creating contexts
// that timeout or in require.Eventually.
Expand Down