(t *testing.T)
| 866 | } |
| 867 | |
| 868 | func TestExecutorAutostartMultipleOK(t *testing.T) { |
| 869 | t.Parallel() |
| 870 | |
| 871 | var ( |
| 872 | sched = mustSchedule(t, "CRON_TZ=UTC 0 * * * *") |
| 873 | tickCh = make(chan time.Time) |
| 874 | tickCh2 = make(chan time.Time) |
| 875 | statsCh1 = make(chan autobuild.Stats) |
| 876 | statsCh2 = make(chan autobuild.Stats) |
| 877 | client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 878 | AutobuildTicker: tickCh, |
| 879 | IncludeProvisionerDaemon: true, |
| 880 | AutobuildStats: statsCh1, |
| 881 | }) |
| 882 | _, _ = coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 883 | AutobuildTicker: tickCh2, |
| 884 | IncludeProvisionerDaemon: true, |
| 885 | AutobuildStats: statsCh2, |
| 886 | }) |
| 887 | // Given: we have a user with a workspace that has autostart enabled (default) |
| 888 | workspace = mustProvisionWorkspace(t, client, func(cwr *codersdk.CreateWorkspaceRequest) { |
| 889 | cwr.AutostartSchedule = ptr.Ref(sched.String()) |
| 890 | }) |
| 891 | ) |
| 892 | // Given: workspace is stopped |
| 893 | workspace = coderdtest.MustTransitionWorkspace(t, client, workspace.ID, codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop) |
| 894 | |
| 895 | p, err := coderdtest.GetProvisionerForTags(db, time.Now(), workspace.OrganizationID, nil) |
| 896 | require.NoError(t, err) |
| 897 | |
| 898 | // When: the autobuild executor ticks past the scheduled time |
| 899 | go func() { |
| 900 | tickTime := sched.Next(workspace.LatestBuild.CreatedAt) |
| 901 | coderdtest.UpdateProvisionerLastSeenAt(t, db, p.ID, tickTime) |
| 902 | tickCh <- tickTime |
| 903 | tickCh2 <- tickTime |
| 904 | close(tickCh) |
| 905 | close(tickCh2) |
| 906 | }() |
| 907 | |
| 908 | // Then: the workspace should eventually be started |
| 909 | stats1 := <-statsCh1 |
| 910 | assert.Len(t, stats1.Errors, 0) |
| 911 | assert.Len(t, stats1.Transitions, 1) |
| 912 | assert.Contains(t, stats1.Transitions, workspace.ID) |
| 913 | assert.Equal(t, database.WorkspaceTransitionStart, stats1.Transitions[workspace.ID]) |
| 914 | |
| 915 | // Then: the other executor should not have done anything |
| 916 | stats2 := <-statsCh2 |
| 917 | assert.Len(t, stats2.Errors, 0) |
| 918 | assert.Len(t, stats2.Transitions, 0) |
| 919 | } |
| 920 | |
| 921 | func TestExecutorAutostartWithParameters(t *testing.T) { |
| 922 | t.Parallel() |
nothing calls this directly
no test coverage detected