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

Function MustWaitForProvisionersAvailable

coderd/coderdtest/coderdtest.go:1878–1924  ·  view source on GitHub ↗

MustWaitForProvisionersAvailable waits for provisioners to be available for a specific workspace.

(t *testing.T, db database.Store, workspace codersdk.Workspace, ts time.Time)

Source from the content-addressed store, hash-verified

1876
1877// MustWaitForProvisionersAvailable waits for provisioners to be available for a specific workspace.
1878func MustWaitForProvisionersAvailable(t *testing.T, db database.Store, workspace codersdk.Workspace, ts time.Time) uuid.UUID {
1879 t.Helper()
1880 ctx := ctxWithProvisionerPermissions(testutil.Context(t, testutil.WaitLong))
1881 id := uuid.UUID{}
1882 // Get the workspace from the database
1883 testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
1884 ws, err := db.GetWorkspaceByID(ctx, workspace.ID)
1885 if err != nil {
1886 return false
1887 }
1888
1889 // Get the latest build
1890 latestBuild, err := db.GetWorkspaceBuildByID(ctx, workspace.LatestBuild.ID)
1891 if err != nil {
1892 return false
1893 }
1894
1895 // Get the template version job
1896 templateVersionJob, err := db.GetProvisionerJobByID(ctx, latestBuild.JobID)
1897 if err != nil {
1898 return false
1899 }
1900
1901 // Check if provisioners are available using the same logic as hasAvailableProvisioners
1902 provisionerDaemons, err := db.GetProvisionerDaemonsByOrganization(ctx, database.GetProvisionerDaemonsByOrganizationParams{
1903 OrganizationID: ws.OrganizationID,
1904 WantTags: templateVersionJob.Tags,
1905 })
1906 if err != nil {
1907 return false
1908 }
1909
1910 // Check if any provisioners are active (not stale)
1911 for _, pd := range provisionerDaemons {
1912 if pd.LastSeenAt.Valid {
1913 age := ts.Sub(pd.LastSeenAt.Time)
1914 if age <= provisionerdserver.StaleInterval {
1915 id = pd.ID
1916 return true // Found an active provisioner
1917 }
1918 }
1919 }
1920 return false // No active provisioners found
1921 }, testutil.IntervalFast, "no active provisioners available for workspace, expected at least one (non-stale)")
1922
1923 return id
1924}

Callers 1

TestPrebuildsAutobuildFunction · 0.92

Calls 8

ContextFunction · 0.92
EventuallyFunction · 0.92
HelperMethod · 0.65
GetWorkspaceByIDMethod · 0.65
GetWorkspaceBuildByIDMethod · 0.65
GetProvisionerJobByIDMethod · 0.65

Tested by 1

TestPrebuildsAutobuildFunction · 0.74