TestReconcilerLifecycle tests that a StoreReconciler can be stopped and a new one created to simulate the prebuilds feature being disabled and re-enabled.
(t *testing.T)
| 1794 | // TestReconcilerLifecycle tests that a StoreReconciler can be stopped and a new one |
| 1795 | // created to simulate the prebuilds feature being disabled and re-enabled. |
| 1796 | func TestReconcilerLifecycle(t *testing.T) { |
| 1797 | t.Parallel() |
| 1798 | |
| 1799 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1800 | logger := testutil.Logger(t) |
| 1801 | db, ps := dbtestutil.NewDB(t) |
| 1802 | cfg := codersdk.PrebuildsConfig{ |
| 1803 | ReconciliationInterval: serpent.Duration(testutil.WaitLong), |
| 1804 | } |
| 1805 | registry := prometheus.NewRegistry() |
| 1806 | cache := files.New(prometheus.NewRegistry(), &coderdtest.FakeAuthorizer{}) |
| 1807 | |
| 1808 | // Given: a running reconciler (simulating the prebuilds feature being enabled) |
| 1809 | reconciler := prebuilds.NewStoreReconciler( |
| 1810 | db, ps, cache, cfg, logger, |
| 1811 | quartz.NewMock(t), |
| 1812 | registry, |
| 1813 | newNoopEnqueuer(), |
| 1814 | newNoopUsageCheckerPtr(), |
| 1815 | noop.NewTracerProvider(), |
| 1816 | 10, |
| 1817 | nil, |
| 1818 | ) |
| 1819 | |
| 1820 | // When: the reconciler is stopped (simulating the prebuilds feature being disabled) |
| 1821 | reconciler.Stop(ctx, xerrors.New("entitlements change")) |
| 1822 | |
| 1823 | // Then: a new reconciler can be created without error |
| 1824 | // (simulating the prebuilds feature being re-enabled) |
| 1825 | reconciler = prebuilds.NewStoreReconciler( |
| 1826 | db, ps, cache, cfg, logger, |
| 1827 | quartz.NewMock(t), |
| 1828 | registry, |
| 1829 | newNoopEnqueuer(), |
| 1830 | newNoopUsageCheckerPtr(), |
| 1831 | noop.NewTracerProvider(), |
| 1832 | 10, |
| 1833 | nil, |
| 1834 | ) |
| 1835 | |
| 1836 | // Gracefully stop the reconciliation loop |
| 1837 | reconciler.Stop(ctx, nil) |
| 1838 | } |
| 1839 | |
| 1840 | func TestFailedBuildBackoff(t *testing.T) { |
| 1841 | t.Parallel() |
nothing calls this directly
no test coverage detected