mirror of https://github.com/coder/coder.git
chore: de-flake TestWorkspaceAgent_Metadata (round 2) (#7039)
This time, we keep the timing / "racey" tests, but avoid running them in the harsher CI conditions.
This commit is contained in:
parent
e1149992d8
commit
24d8644c0b
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
@ -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")
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue