mirror of
https://github.com/coder/coder.git
synced 2025-03-14 10:09:57 +00:00
chore: fix more flaky tests on Windows with Postgres (#15629)
Addresses the following flakes: - https://github.com/coder/internal/issues/222 - https://github.com/coder/internal/issues/223 - https://github.com/coder/internal/issues/224 - https://github.com/coder/internal/issues/225 - https://github.com/coder/internal/issues/226 - https://github.com/coder/internal/issues/227 - https://github.com/coder/internal/issues/228 - https://github.com/coder/internal/issues/229 - https://github.com/coder/internal/issues/230
This commit is contained in:
@ -220,16 +220,29 @@ func WorkspaceAgentScriptTimings(t testing.TB, db database.Store, script databas
|
||||
}
|
||||
|
||||
func WorkspaceAgentScriptTiming(t testing.TB, db database.Store, orig database.WorkspaceAgentScriptTiming) database.WorkspaceAgentScriptTiming {
|
||||
timing, err := db.InsertWorkspaceAgentScriptTimings(genCtx, database.InsertWorkspaceAgentScriptTimingsParams{
|
||||
StartedAt: takeFirst(orig.StartedAt, dbtime.Now()),
|
||||
EndedAt: takeFirst(orig.EndedAt, dbtime.Now()),
|
||||
Stage: takeFirst(orig.Stage, database.WorkspaceAgentScriptTimingStageStart),
|
||||
ScriptID: takeFirst(orig.ScriptID, uuid.New()),
|
||||
ExitCode: takeFirst(orig.ExitCode, 0),
|
||||
Status: takeFirst(orig.Status, database.WorkspaceAgentScriptTimingStatusOk),
|
||||
})
|
||||
require.NoError(t, err, "insert workspace agent script")
|
||||
return timing
|
||||
// retry a few times in case of a unique constraint violation
|
||||
for i := 0; i < 10; i++ {
|
||||
timing, err := db.InsertWorkspaceAgentScriptTimings(genCtx, database.InsertWorkspaceAgentScriptTimingsParams{
|
||||
StartedAt: takeFirst(orig.StartedAt, dbtime.Now()),
|
||||
EndedAt: takeFirst(orig.EndedAt, dbtime.Now()),
|
||||
Stage: takeFirst(orig.Stage, database.WorkspaceAgentScriptTimingStageStart),
|
||||
ScriptID: takeFirst(orig.ScriptID, uuid.New()),
|
||||
ExitCode: takeFirst(orig.ExitCode, 0),
|
||||
Status: takeFirst(orig.Status, database.WorkspaceAgentScriptTimingStatusOk),
|
||||
})
|
||||
if err == nil {
|
||||
return timing
|
||||
}
|
||||
// Some tests run WorkspaceAgentScriptTiming in a loop and run into
|
||||
// a unique violation - 2 rows get the same started_at value.
|
||||
if (database.IsUniqueViolation(err, database.UniqueWorkspaceAgentScriptTimingsScriptIDStartedAtKey) && orig.StartedAt == time.Time{}) {
|
||||
// Wait 1 millisecond so dbtime.Now() changes
|
||||
time.Sleep(time.Millisecond * 1)
|
||||
continue
|
||||
}
|
||||
require.NoError(t, err, "insert workspace agent script")
|
||||
}
|
||||
panic("failed to insert workspace agent script timing")
|
||||
}
|
||||
|
||||
func Workspace(t testing.TB, db database.Store, orig database.WorkspaceTable) database.WorkspaceTable {
|
||||
|
@ -54,7 +54,7 @@ func TestPurge(t *testing.T) {
|
||||
|
||||
//nolint:paralleltest // It uses LockIDDBPurge.
|
||||
func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
now := dbtime.Now()
|
||||
|
@ -921,7 +921,7 @@ func TestPGCoordinatorPropogatedPeerContext(t *testing.T) {
|
||||
t.Skip("test only with postgres")
|
||||
}
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
store, ps := dbtestutil.NewDB(t)
|
||||
logger := testutil.Logger(t)
|
||||
|
||||
|
@ -7,10 +7,10 @@ import "time"
|
||||
//
|
||||
// Windows durations are adjusted for slow CI workers.
|
||||
const (
|
||||
WaitShort = 15 * time.Second
|
||||
WaitMedium = 20 * time.Second
|
||||
WaitLong = 35 * time.Second
|
||||
WaitSuperLong = 120 * time.Second
|
||||
WaitShort = 30 * time.Second
|
||||
WaitMedium = 40 * time.Second
|
||||
WaitLong = 70 * time.Second
|
||||
WaitSuperLong = 240 * time.Second
|
||||
)
|
||||
|
||||
// Constants for delaying repeated operations, e.g. in
|
||||
@ -18,7 +18,7 @@ const (
|
||||
//
|
||||
// Windows durations are adjusted for slow CI workers.
|
||||
const (
|
||||
IntervalFast = 50 * time.Millisecond
|
||||
IntervalMedium = 500 * time.Millisecond
|
||||
IntervalSlow = 2 * time.Second
|
||||
IntervalFast = 100 * time.Millisecond
|
||||
IntervalMedium = 1000 * time.Millisecond
|
||||
IntervalSlow = 4 * time.Second
|
||||
)
|
||||
|
Reference in New Issue
Block a user