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:
Ammar Bandukwala
2023-04-06 16:10:13 -05:00
committed by GitHub
parent e1149992d8
commit 24d8644c0b
5 changed files with 31 additions and 7 deletions

View File

@ -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{