Skip to content

Commit 1bbe3bb

Browse files
committed
add test that fails since we still trigger autobuilds even if a
provisioner is not available Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 36d2e01 commit 1bbe3bb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

coderd/autobuild/lifecycle_executor_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,3 +1583,47 @@ func mustWorkspaceParameters(t *testing.T, client *codersdk.Client, workspaceID
15831583
func TestMain(m *testing.M) {
15841584
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
15851585
}
1586+
1587+
func TestExecutorAutostartSkipsWhenNoProvisionersAvailable(t *testing.T) {
1588+
t.Parallel()
1589+
1590+
var (
1591+
sched = mustSchedule(t, "CRON_TZ=UTC 0 * * * *")
1592+
tickCh = make(chan time.Time)
1593+
statsCh = make(chan autobuild.Stats)
1594+
)
1595+
1596+
// Create client with provisioner daemon
1597+
client, provisionerCloser := coderdtest.NewWithProvisionerCloser(t, &coderdtest.Options{
1598+
AutobuildTicker: tickCh,
1599+
IncludeProvisionerDaemon: true,
1600+
AutobuildStats: statsCh,
1601+
})
1602+
1603+
// Create workspace with autostart enabled
1604+
workspace := mustProvisionWorkspace(t, client, func(cwr *codersdk.CreateWorkspaceRequest) {
1605+
cwr.AutostartSchedule = ptr.Ref(sched.String())
1606+
})
1607+
1608+
// Stop the workspace while provisioner is available
1609+
workspace = coderdtest.MustTransitionWorkspace(t, client, workspace.ID,
1610+
codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop)
1611+
1612+
// Now shut down the provisioner daemon
1613+
err := provisionerCloser.Close()
1614+
require.NoError(t, err)
1615+
1616+
// Trigger autobuild after scheduled time
1617+
go func() {
1618+
tickCh <- sched.Next(workspace.LatestBuild.CreatedAt)
1619+
close(tickCh)
1620+
}()
1621+
1622+
// Wait for executor to run
1623+
stats := <-statsCh
1624+
require.Len(t, stats.Errors, 0, "should not have errors")
1625+
1626+
// Verify workspace is still stopped
1627+
workspace = coderdtest.MustWorkspace(t, client, workspace.ID)
1628+
require.Equal(t, codersdk.WorkspaceTransitionStop, workspace.LatestBuild.Transition)
1629+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy