Skip to content

Commit c6d5a95

Browse files
committed
chore: de-flake TestWorkspaceAgent_Metadata (round 2)
This time, we keep the timing / "racey" tests, but avoid running them in the harsher CI conditions.
1 parent e114999 commit c6d5a95

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

agent/reaper/reaper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestReap(t *testing.T) {
2323
// Don't run the reaper test in CI. It does weird
2424
// things like forkexecing which may have unintended
2525
// consequences in CI.
26-
if _, ok := os.LookupEnv("CI"); ok {
26+
if testutil.InCI() {
2727
t.Skip("Detected CI, skipping reaper tests")
2828
}
2929

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

coderd/workspaceagents_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,16 +1353,20 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
13531353
var update []codersdk.WorkspaceAgentMetadata
13541354

13551355
check := func(want codersdk.WorkspaceAgentMetadataResult, got codersdk.WorkspaceAgentMetadata) {
1356-
require.Greater(t, got.Result.CollectedAt, want.CollectedAt)
1356+
require.Equal(t, want.Value, got.Result.Value)
1357+
require.Equal(t, want.Error, got.Result.Error)
13571358

1359+
if testutil.InCI() && (runtime.GOOS == "windows" || testutil.InRaceMode()) {
1360+
// Avoid testing timings when flake chance is high.
1361+
return
1362+
}
1363+
require.WithinDuration(t, got.Result.CollectedAt, want.CollectedAt, time.Second)
13581364
ageImpliedNow := got.Result.CollectedAt.Add(time.Duration(got.Result.Age) * time.Second)
13591365
// We use a long WithinDuration to tolerate slow CI, but we're still making sure
13601366
// that Age is within the ballpark.
13611367
require.WithinDuration(
13621368
t, time.Now(), ageImpliedNow, time.Second*10,
13631369
)
1364-
require.Equal(t, want.Value, got.Result.Value)
1365-
require.Equal(t, want.Error, got.Result.Error)
13661370
}
13671371

13681372
wantMetadata1 := codersdk.WorkspaceAgentMetadataResult{

helm/tests/chart_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/stretchr/testify/require"
1313
"golang.org/x/xerrors"
14+
15+
"github.com/coder/coder/testutil"
1416
)
1517

1618
// These tests run `helm template` with the values file specified in each test
@@ -54,7 +56,7 @@ func TestRenderChart(t *testing.T) {
5456
if *UpdateGoldenFiles {
5557
t.Skip("Golden files are being updated. Skipping test.")
5658
}
57-
if _, runningInCI := os.LookupEnv("CI"); runningInCI {
59+
if testutil.InCI() {
5860
switch runtime.GOOS {
5961
case "windows", "darwin":
6062
t.Skip("Skipping tests on Windows and macOS in CI")

testutil/ci.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package testutil
2+
3+
import (
4+
"flag"
5+
"os"
6+
)
7+
8+
func InCI() bool {
9+
_, ok := os.LookupEnv("CI")
10+
return ok
11+
}
12+
13+
func InRaceMode() bool {
14+
fl := flag.Lookup("-race")
15+
return fl != nil && fl.Value.String() == "true"
16+
}

testutil/duration.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
package testutil
44

5-
import "time"
5+
import (
6+
"time"
7+
)
68

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy