MCPcopy Index your code
hub / github.com/coder/coder / TestPrebuildsAutobuild

Function TestPrebuildsAutobuild

enterprise/coderd/workspaces_test.go:1912–2658  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1910}
1911
1912func TestPrebuildsAutobuild(t *testing.T) {
1913 t.Parallel()
1914
1915 getRunningPrebuilds := func(
1916 t *testing.T,
1917 ctx context.Context,
1918 db database.Store,
1919 prebuildInstances int,
1920 ) []database.GetRunningPrebuiltWorkspacesRow {
1921 t.Helper()
1922
1923 var runningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
1924 testutil.Eventually(ctx, t, func(context.Context) bool {
1925 rows, err := db.GetRunningPrebuiltWorkspaces(ctx)
1926 if err != nil {
1927 return false
1928 }
1929
1930 for _, row := range rows {
1931 runningPrebuilds = append(runningPrebuilds, row)
1932
1933 agents, err := db.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, row.ID)
1934 if err != nil {
1935 return false
1936 }
1937
1938 for _, agent := range agents {
1939 err = db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
1940 ID: agent.ID,
1941 LifecycleState: database.WorkspaceAgentLifecycleStateReady,
1942 StartedAt: sql.NullTime{Time: time.Now().Add(time.Hour), Valid: true},
1943 ReadyAt: sql.NullTime{Time: time.Now().Add(-1 * time.Hour), Valid: true},
1944 })
1945 if err != nil {
1946 return false
1947 }
1948 }
1949 }
1950
1951 t.Logf("found %d running prebuilds so far, want %d", len(runningPrebuilds), prebuildInstances)
1952 return len(runningPrebuilds) == prebuildInstances
1953 }, testutil.IntervalSlow, "prebuilds not running")
1954
1955 return runningPrebuilds
1956 }
1957
1958 runReconciliationLoop := func(
1959 t *testing.T,
1960 ctx context.Context,
1961 db database.Store,
1962 reconciler *prebuilds.StoreReconciler,
1963 presets []codersdk.Preset,
1964 ) {
1965 t.Helper()
1966
1967 state, err := reconciler.SnapshotState(ctx, db)
1968 require.NoError(t, err)
1969 ps, err := state.FilterByPreset(presets[0].ID)

Callers

nothing calls this directly

Calls 15

SnapshotStateMethod · 0.95
CalculateActionsMethod · 0.95
ReconcilePresetMethod · 0.95
EventuallyFunction · 0.92
GetRandomNameFunction · 0.92
RefFunction · 0.92
MustWorkspaceFunction · 0.92
ContextFunction · 0.92
NewDBFunction · 0.92
WithDumpOnFailureFunction · 0.92
LoggerFunction · 0.92

Tested by

no test coverage detected