(t *testing.T)
| 145 | } |
| 146 | |
| 147 | func TestFormatUpgradeMultipleLocksRollback(t *testing.T) { |
| 148 | ctx, env := repotesting.NewEnvironment(t, format.FormatVersion1, repotesting.Options{OpenOptions: func(opts *repo.Options) { |
| 149 | opts.UpgradeOwnerID = "upgrade-owner" |
| 150 | }}) |
| 151 | formatBlockCacheDuration := env.Repository.ClientOptions().FormatBlobCacheDuration |
| 152 | |
| 153 | l := &format.UpgradeLockIntent{ |
| 154 | OwnerID: "upgrade-owner", |
| 155 | CreationTime: env.Repository.Time(), |
| 156 | AdvanceNoticeDuration: 0, |
| 157 | IODrainTimeout: formatBlockCacheDuration * 2, |
| 158 | StatusPollInterval: formatBlockCacheDuration, |
| 159 | Message: "upgrading from format version 2 -> 3", |
| 160 | MaxPermittedClockDrift: formatBlockCacheDuration / 3, |
| 161 | } |
| 162 | |
| 163 | secondWriter := env.MustOpenAnother(t, func(opts *repo.Options) { |
| 164 | opts.UpgradeOwnerID = "upgrade-owner" |
| 165 | }) |
| 166 | |
| 167 | // first lock by primary creator |
| 168 | _, err := env.RepositoryWriter.FormatManager().SetUpgradeLockIntent(ctx, *l) |
| 169 | require.NoError(t, err) |
| 170 | |
| 171 | // second lock from a random owner |
| 172 | secondL := l.Clone() |
| 173 | secondL.OwnerID = "another-upgrade-owner" |
| 174 | _, err = testutil.EnsureType[repo.DirectRepositoryWriter](t, secondWriter).FormatManager().SetUpgradeLockIntent(ctx, *secondL) |
| 175 | require.NoError(t, err) |
| 176 | |
| 177 | // verify that we have two repository backups, the second one will contain |
| 178 | // the first owner's lock |
| 179 | { |
| 180 | var backups []string |
| 181 | |
| 182 | require.NoError(t, env.RootStorage().ListBlobs(ctx, format.BackupBlobIDPrefix, func(bm blob.Metadata) error { |
| 183 | backups = append(backups, string(bm.BlobID)) |
| 184 | return nil |
| 185 | })) |
| 186 | sort.Strings(backups) |
| 187 | require.Equal(t, []string{string(format.BackupBlobID(*secondL)), string(format.BackupBlobID(*l))}, |
| 188 | backups, "invalid backups list") |
| 189 | } |
| 190 | |
| 191 | // verify that we have upgraded our format version |
| 192 | env.MustReopen(t, func(opts *repo.Options) { |
| 193 | opts.UpgradeOwnerID = "another-upgrade-owner" |
| 194 | }) |
| 195 | |
| 196 | mp, mperr := env.RepositoryWriter.ContentManager().ContentFormat().GetMutableParameters(ctx) |
| 197 | require.NoError(t, mperr) |
| 198 | require.Equal(t, format.FormatVersion3, mp.Version) |
| 199 | |
| 200 | require.NoError(t, env.RepositoryWriter.FormatManager().RollbackUpgrade(ctx)) |
| 201 | |
| 202 | // verify that we have no repository backups pending |
| 203 | require.NoError(t, env.RootStorage().ListBlobs(ctx, format.BackupBlobIDPrefix, func(bm blob.Metadata) error { |
| 204 | t.Fatalf("found unexpected backup: %s", bm.BlobID) |
nothing calls this directly
no test coverage detected