MCPcopy
hub / github.com/kopia/kopia / TestServerMaintenance

Function TestServerMaintenance

internal/server/server_maintenance_test.go:59–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func 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
106func TestServerMaintenanceReadOnlyRepoConnection(t *testing.T) {
107 ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant)

Callers

nothing calls this directly

Calls 15

NewEnvironmentFunction · 0.92
DirectWriteSessionFunction · 0.92
SetParamsFunction · 0.92
NowFunction · 0.92
UsernameAtHostMethod · 0.80
EqualMethod · 0.80
triggerMethod · 0.80
SubMethod · 0.80
nextMaintenanceTimeMethod · 0.80
ClientOptionsMethod · 0.65
LoadMethod · 0.65

Tested by

no test coverage detected