MCPcopy
hub / github.com/kopia/kopia / TestFormatUpgradeSetLock

Function TestFormatUpgradeSetLock

repo/format/upgrade_lock_test.go:30–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestFormatUpgradeSetLock(t *testing.T) {
31 ctx, env := repotesting.NewEnvironment(t, format.FormatVersion1, repotesting.Options{OpenOptions: func(opts *repo.Options) {
32 //nolint:goconst
33 opts.UpgradeOwnerID = "upgrade-owner"
34 }})
35 formatBlockCacheDuration := env.Repository.ClientOptions().FormatBlobCacheDuration
36
37 l := &format.UpgradeLockIntent{
38 CreationTime: env.Repository.Time(),
39 AdvanceNoticeDuration: 15 * time.Hour,
40 IODrainTimeout: formatBlockCacheDuration * 2,
41 StatusPollInterval: formatBlockCacheDuration,
42 Message: "upgrading from format version 2 -> 3",
43 MaxPermittedClockDrift: formatBlockCacheDuration / 3,
44 }
45
46 // set invalid lock
47 _, err := env.RepositoryWriter.FormatManager().SetUpgradeLockIntent(ctx, *l)
48 require.EqualError(t, err, "invalid upgrade lock intent: no owner-id set, it is required to set a unique owner-id")
49
50 l.OwnerID = "upgrade-owner"
51 l, err = env.RepositoryWriter.FormatManager().SetUpgradeLockIntent(ctx, *l)
52 require.NoError(t, err)
53
54 l.OwnerID = "new-upgrade-owner"
55
56 // verify that second owner cannot set / update the lock
57 _, err = env.RepositoryWriter.FormatManager().SetUpgradeLockIntent(ctx, *l)
58 require.EqualError(t, err,
59 "failed to update the existing lock: upgrade owner-id mismatch \"new-upgrade-owner\" != \"upgrade-owner\", you are not the owner of the upgrade lock")
60
61 l.OwnerID = "upgrade-owner"
62
63 // push the advance notice
64 l.AdvanceNoticeDuration *= 2
65
66 // update the lock
67 _, err = env.RepositoryWriter.FormatManager().SetUpgradeLockIntent(ctx, *l)
68 require.NoError(t, err)
69
70 require.NoError(t, env.RepositoryWriter.FormatManager().CommitUpgrade(ctx))
71}
72
73func TestFormatUpgradeAlreadyUpgraded(t *testing.T) {
74 ctx, env := repotesting.NewEnvironment(t, format.MaxFormatVersion)

Callers

nothing calls this directly

Calls 6

NewEnvironmentFunction · 0.92
SetUpgradeLockIntentMethod · 0.80
CommitUpgradeMethod · 0.80
ClientOptionsMethod · 0.65
TimeMethod · 0.65
FormatManagerMethod · 0.65

Tested by

no test coverage detected