(t *testing.T)
| 632 | } |
| 633 | |
| 634 | func TestPrebuildScheduling(t *testing.T) { |
| 635 | t.Parallel() |
| 636 | |
| 637 | templateDeleted := false |
| 638 | |
| 639 | // The test includes 2 presets, each with 2 schedules. |
| 640 | // It checks that the number of created prebuilds match expectations for various provided times, |
| 641 | // based on the corresponding schedules. |
| 642 | testCases := []struct { |
| 643 | name string |
| 644 | // now specifies the current time. |
| 645 | now time.Time |
| 646 | // expected prebuild counts for preset1 and preset2, respectively. |
| 647 | expectedPrebuildCounts []int |
| 648 | }{ |
| 649 | { |
| 650 | name: "Before the 1st schedule", |
| 651 | now: mustParseTime(t, time.RFC1123, "Mon, 02 Jun 2025 01:00:00 UTC"), |
| 652 | expectedPrebuildCounts: []int{1, 1}, |
| 653 | }, |
| 654 | { |
| 655 | name: "1st schedule", |
| 656 | now: mustParseTime(t, time.RFC1123, "Mon, 02 Jun 2025 03:00:00 UTC"), |
| 657 | expectedPrebuildCounts: []int{2, 1}, |
| 658 | }, |
| 659 | { |
| 660 | name: "2nd schedule", |
| 661 | now: mustParseTime(t, time.RFC1123, "Mon, 02 Jun 2025 07:00:00 UTC"), |
| 662 | expectedPrebuildCounts: []int{3, 1}, |
| 663 | }, |
| 664 | { |
| 665 | name: "3rd schedule", |
| 666 | now: mustParseTime(t, time.RFC1123, "Mon, 02 Jun 2025 11:00:00 UTC"), |
| 667 | expectedPrebuildCounts: []int{1, 4}, |
| 668 | }, |
| 669 | { |
| 670 | name: "4th schedule", |
| 671 | now: mustParseTime(t, time.RFC1123, "Mon, 02 Jun 2025 15:00:00 UTC"), |
| 672 | expectedPrebuildCounts: []int{1, 5}, |
| 673 | }, |
| 674 | } |
| 675 | |
| 676 | for _, tc := range testCases { |
| 677 | t.Run(tc.name, func(t *testing.T) { |
| 678 | t.Parallel() |
| 679 | clock := quartz.NewMock(t) |
| 680 | clock.Set(tc.now) |
| 681 | ctx := testutil.Context(t, testutil.WaitShort) |
| 682 | cfg := codersdk.PrebuildsConfig{} |
| 683 | logger := slogtest.Make( |
| 684 | t, &slogtest.Options{IgnoreErrors: true}, |
| 685 | ).Leveled(slog.LevelDebug) |
| 686 | db, pubSub := dbtestutil.NewDB(t) |
| 687 | cache := files.New(prometheus.NewRegistry(), &coderdtest.FakeAuthorizer{}) |
| 688 | controller := prebuilds.NewStoreReconciler( |
| 689 | db, pubSub, cache, cfg, logger, |
| 690 | clock, |
| 691 | prometheus.NewRegistry(), |
nothing calls this directly
no test coverage detected