Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit95ce697

Browse files
authored
fix: schedule autobuild directly on TestExecutorAutostopTemplateDisabled (#10453)
Fixes flake seen here:https://github.com/coder/coder/actions/runs/6716682414/job/18253279654The test used a cron schedule to compute autobuild ticks, with ticks every hour on the hour. The default TTL was set to an hour. Usually, the next tick is less than one hour in the future, unless the test runs at :00 past the hour, which it did in my flake'drun. But, given that this is an autostop test, the cron schedule is irrelevant (such schedules are used for auto_start_). So, I've removed it from the test and compute the build ticks directly.Also, the test originally had the workspace TTL set to longer than the default template TTL, and then tested that no build happened when the tick was prior to both. This seems odd to me, as we want to demonstrate the the executor disregards the workspace TTL.So, I changed the test to set the workspace TTL shorter, and then send in a tick between the two, verify that we don't autostop, then a tick after the template TTL and verify that we do.
1 parent94eb9b8 commit95ce697

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

‎coderd/autobuild/lifecycle_executor_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ func TestExecutorAutostopTemplateDisabled(t *testing.T) {
743743

744744
// Given: we have a workspace built from a template that disallows user autostop
745745
var (
746-
sched=mustSchedule(t,"CRON_TZ=UTC 0 * * * *")
747746
tickCh=make(chan time.Time)
748747
statsCh=make(chan autobuild.Stats)
749748

@@ -761,26 +760,38 @@ func TestExecutorAutostopTemplateDisabled(t *testing.T) {
761760
},
762761
},
763762
})
764-
// Given: we have a user with a workspace configured toautostart some time in the future
763+
// Given: we have a user with a workspace configured toautostop 30 minutes in the future
765764
workspace=mustProvisionWorkspace(t,client,func(cwr*codersdk.CreateWorkspaceRequest) {
766-
cwr.TTLMillis=ptr.Ref(8*time.Hour.Milliseconds())
765+
cwr.TTLMillis=ptr.Ref(30*time.Minute.Milliseconds())
767766
})
768767
)
769768

770769
// When: we create the workspace
771770
// Then: the deadline should be set to the template default TTL
772771
assert.WithinDuration(t,workspace.LatestBuild.CreatedAt.Add(time.Hour),workspace.LatestBuild.Deadline.Time,time.Minute)
773772

774-
// When: the autobuild executor ticksbefore thenext scheduled time
773+
// When: the autobuild executor ticksafter theworkspace setting, but before the template setting:
775774
gofunc() {
776-
tickCh<-sched.Next(workspace.LatestBuild.CreatedAt).Add(time.Minute)
777-
close(tickCh)
775+
tickCh<-workspace.LatestBuild.CreatedAt.Add(45*time.Minute)
778776
}()
779777

780778
// Then: nothing should happen
781779
stats:=<-statsCh
782780
assert.NoError(t,stats.Error)
783781
assert.Len(t,stats.Transitions,0)
782+
783+
// When: the autobuild executor ticks after the template setting:
784+
gofunc() {
785+
tickCh<-workspace.LatestBuild.CreatedAt.Add(61*time.Minute)
786+
close(tickCh)
787+
}()
788+
789+
// Then: the workspace should be stopped
790+
stats=<-statsCh
791+
assert.NoError(t,stats.Error)
792+
assert.Len(t,stats.Transitions,1)
793+
assert.Contains(t,stats.Transitions,workspace.ID)
794+
assert.Equal(t,database.WorkspaceTransitionStop,stats.Transitions[workspace.ID])
784795
}
785796

786797
// Test that an AGPL AccessControlStore properly disables

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp