mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
test(agent): fix lifecycle test flakeyness (#8230)
This commit is contained in:
+26
-25
@@ -35,6 +35,7 @@ import (
|
||||
"go.uber.org/goleak"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/xerrors"
|
||||
"tailscale.com/net/speedtest"
|
||||
"tailscale.com/tailcfg"
|
||||
@@ -1099,7 +1100,7 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
|
||||
StartupScript: "sleep 5",
|
||||
StartupScript: "sleep 3",
|
||||
StartupScriptTimeout: time.Nanosecond,
|
||||
}, 0)
|
||||
|
||||
@@ -1111,10 +1112,10 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
var got []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
got = client.getLifecycleStates()
|
||||
return len(got) > 0 && got[len(got)-1] == want[len(want)-1]
|
||||
return slices.Contains(got, want[len(want)-1])
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
require.Equal(t, want, got[:len(want)])
|
||||
})
|
||||
|
||||
t.Run("StartError", func(t *testing.T) {
|
||||
@@ -1133,10 +1134,10 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
var got []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
got = client.getLifecycleStates()
|
||||
return len(got) > 0 && got[len(got)-1] == want[len(want)-1]
|
||||
return slices.Contains(got, want[len(want)-1])
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
require.Equal(t, want, got[:len(want)])
|
||||
})
|
||||
|
||||
t.Run("Ready", func(t *testing.T) {
|
||||
@@ -1165,14 +1166,12 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, client, _, _, closer := setupAgent(t, agentsdk.Manifest{
|
||||
ShutdownScript: "sleep 5",
|
||||
ShutdownScript: "sleep 3",
|
||||
StartupScriptTimeout: 30 * time.Second,
|
||||
}, 0)
|
||||
|
||||
var ready []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
ready = client.getLifecycleStates()
|
||||
return len(ready) > 0 && ready[len(ready)-1] == codersdk.WorkspaceAgentLifecycleReady
|
||||
return slices.Contains(client.getLifecycleStates(), codersdk.WorkspaceAgentLifecycleReady)
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
// Start close asynchronously so that we an inspect the state.
|
||||
@@ -1187,30 +1186,30 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
})
|
||||
|
||||
want := []codersdk.WorkspaceAgentLifecycle{
|
||||
codersdk.WorkspaceAgentLifecycleStarting,
|
||||
codersdk.WorkspaceAgentLifecycleReady,
|
||||
codersdk.WorkspaceAgentLifecycleShuttingDown,
|
||||
}
|
||||
|
||||
var got []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
got = client.getLifecycleStates()[len(ready):]
|
||||
return len(got) > 0 && got[len(got)-1] == want[len(want)-1]
|
||||
got = client.getLifecycleStates()
|
||||
return slices.Contains(got, want[len(want)-1])
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
require.Equal(t, want, got[:len(want)])
|
||||
})
|
||||
|
||||
t.Run("ShutdownTimeout", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, client, _, _, closer := setupAgent(t, agentsdk.Manifest{
|
||||
ShutdownScript: "sleep 5",
|
||||
ShutdownScript: "sleep 3",
|
||||
ShutdownScriptTimeout: time.Nanosecond,
|
||||
}, 0)
|
||||
|
||||
var ready []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
ready = client.getLifecycleStates()
|
||||
return len(ready) > 0 && ready[len(ready)-1] == codersdk.WorkspaceAgentLifecycleReady
|
||||
return slices.Contains(client.getLifecycleStates(), codersdk.WorkspaceAgentLifecycleReady)
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
// Start close asynchronously so that we an inspect the state.
|
||||
@@ -1225,17 +1224,19 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
})
|
||||
|
||||
want := []codersdk.WorkspaceAgentLifecycle{
|
||||
codersdk.WorkspaceAgentLifecycleStarting,
|
||||
codersdk.WorkspaceAgentLifecycleReady,
|
||||
codersdk.WorkspaceAgentLifecycleShuttingDown,
|
||||
codersdk.WorkspaceAgentLifecycleShutdownTimeout,
|
||||
}
|
||||
|
||||
var got []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
got = client.getLifecycleStates()[len(ready):]
|
||||
return len(got) > 0 && got[len(got)-1] == want[len(want)-1]
|
||||
got = client.getLifecycleStates()
|
||||
return slices.Contains(got, want[len(want)-1])
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
require.Equal(t, want, got[:len(want)])
|
||||
})
|
||||
|
||||
t.Run("ShutdownError", func(t *testing.T) {
|
||||
@@ -1246,10 +1247,8 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
ShutdownScriptTimeout: 30 * time.Second,
|
||||
}, 0)
|
||||
|
||||
var ready []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
ready = client.getLifecycleStates()
|
||||
return len(ready) > 0 && ready[len(ready)-1] == codersdk.WorkspaceAgentLifecycleReady
|
||||
return slices.Contains(client.getLifecycleStates(), codersdk.WorkspaceAgentLifecycleReady)
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
// Start close asynchronously so that we an inspect the state.
|
||||
@@ -1264,17 +1263,19 @@ func TestAgent_Lifecycle(t *testing.T) {
|
||||
})
|
||||
|
||||
want := []codersdk.WorkspaceAgentLifecycle{
|
||||
codersdk.WorkspaceAgentLifecycleStarting,
|
||||
codersdk.WorkspaceAgentLifecycleReady,
|
||||
codersdk.WorkspaceAgentLifecycleShuttingDown,
|
||||
codersdk.WorkspaceAgentLifecycleShutdownError,
|
||||
}
|
||||
|
||||
var got []codersdk.WorkspaceAgentLifecycle
|
||||
assert.Eventually(t, func() bool {
|
||||
got = client.getLifecycleStates()[len(ready):]
|
||||
return len(got) > 0 && got[len(got)-1] == want[len(want)-1]
|
||||
got = client.getLifecycleStates()
|
||||
return slices.Contains(got, want[len(want)-1])
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
require.Equal(t, want, got[:len(want)])
|
||||
})
|
||||
|
||||
t.Run("ShutdownScriptOnce", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user