(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestServerMaintenance(t *testing.T) { |
| 60 | ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant) |
| 61 | |
| 62 | require.NoError(t, repo.DirectWriteSession(ctx, env.RepositoryWriter, repo.WriteSessionOptions{}, func(ctx context.Context, dw repo.DirectRepositoryWriter) error { |
| 63 | return maintenance.SetParams(ctx, dw, &maintenance.Params{ |
| 64 | Owner: env.Repository.ClientOptions().UsernameAtHost(), |
| 65 | QuickCycle: maintenance.CycleParams{ |
| 66 | Enabled: true, |
| 67 | Interval: 5 * time.Second, |
| 68 | }, |
| 69 | FullCycle: maintenance.CycleParams{ |
| 70 | Enabled: true, |
| 71 | Interval: 10 * time.Second, |
| 72 | }, |
| 73 | }) |
| 74 | })) |
| 75 | |
| 76 | ts := &testServer{log: t.Logf} |
| 77 | |
| 78 | mm := maybeStartMaintenanceManager(ctx, env.RepositoryWriter, ts, time.Minute) |
| 79 | require.Equal(t, time.Time{}, mm.nextMaintenanceNoEarlierThan) |
| 80 | |
| 81 | defer mm.stop(ctx) |
| 82 | |
| 83 | // trigger and make sure it runs |
| 84 | mm.trigger() |
| 85 | require.Eventually(t, func() bool { |
| 86 | return ts.runCounter.Load() == 1 && ts.refreshSchedulerCount.Load() == 1 |
| 87 | }, 3*time.Second, 10*time.Millisecond) |
| 88 | |
| 89 | ts.mu.Lock() |
| 90 | ts.err = errors.New("some error") |
| 91 | ts.mu.Unlock() |
| 92 | |
| 93 | mm.trigger() |
| 94 | |
| 95 | require.Eventually(t, func() bool { |
| 96 | mm.mu.Lock() |
| 97 | defer mm.mu.Unlock() |
| 98 | |
| 99 | return ts.runCounter.Load() == 2 && !mm.nextMaintenanceNoEarlierThan.IsZero() |
| 100 | }, 3*time.Second, 10*time.Millisecond) |
| 101 | |
| 102 | // after a failure next maintenance time should be deferred by a minute. |
| 103 | require.Greater(t, mm.nextMaintenanceTime().Sub(clock.Now()), 50*time.Second) |
| 104 | } |
| 105 | |
| 106 | func TestServerMaintenanceReadOnlyRepoConnection(t *testing.T) { |
| 107 | ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant) |
nothing calls this directly
no test coverage detected