test(kvstore): call Delete again when it gives up under contention
TestDeleteRacingWithWrites failed on the Delete of the race itself (conflict after deleteTries listings), also on main. Delete leaves the repository in place then, so the caller calls it again.
- commit
- eca604188bef98f81d67c4eb607cdbe9bfa0527e
- author
- brice · · 2026-10-12 20:28 UTC
- parent
- b4c1e2a
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +11 -2
M internal/adapters/kvstore/mergerequests_test.go +11 -2
| @@ -360,7 +360,8 @@ func assertNoMergeRequestKeys(t *testing.T, mrs *kvstore.MergeRequests, n domain | |||
| 360 | 360 | // TestDeleteRacingWithWrites: writes racing with Delete either land before it | |
| 361 | 361 | // and are deleted, or are refused (not found after it, or a conflict when the | |
| 362 | 362 | // retries run out under this contention); nothing is left for a repository | |
| 363 | - | // created again under the name. | |
| 363 | + | // created again under the name. Delete itself may report a conflict under the | |
| 364 | + | // same contention and is then called again. | |
| 364 | 365 | func TestDeleteRacingWithWrites(t *testing.T) { | |
| 365 | 366 | ctx := context.Background() | |
| 366 | 367 | for round := range 20 { | |
| @@ -394,7 +395,15 @@ func TestDeleteRacingWithWrites(t *testing.T) { | |||
| 394 | 395 | } | |
| 395 | 396 | }() | |
| 396 | 397 | } | |
| 397 | - | delErr := s.Delete(ctx, n) | |
| 398 | + | // Delete gives up with a conflict when the writers keep rewriting the | |
| 399 | + | // repository key for deleteTries listings in a row; it is documented as | |
| 400 | + | // safe to call again, as a caller does. | |
| 401 | + | var delErr error | |
| 402 | + | for range 20 { | |
| 403 | + | if delErr = s.Delete(ctx, n); !errors.Is(delErr, domain.ErrConflict) { | |
| 404 | + | break | |
| 405 | + | } | |
| 406 | + | } | |
| 398 | 407 | wg.Wait() | |
| 399 | 408 | require.NoError(t, delErr) | |
| 400 | 409 | ||
| @@ -360,7 +360,8 @@ func assertNoMergeRequestKeys(t *testing.T, mrs *kvstore.MergeRequests, n domain | |||||
| 360 | // TestDeleteRacingWithWrites: writes racing with Delete either land before it | 360 | // TestDeleteRacingWithWrites: writes racing with Delete either land before it | ||
| 361 | // and are deleted, or are refused (not found after it, or a conflict when the | 361 | // and are deleted, or are refused (not found after it, or a conflict when the | ||
| 362 | // retries run out under this contention); nothing is left for a repository | 362 | // retries run out under this contention); nothing is left for a repository | ||
| 363 | - | // created again under the name. | 363 | + | // created again under the name. Delete itself may report a conflict under the |
| 364 | + | // same contention and is then called again. | |||
| 364 | func TestDeleteRacingWithWrites(t *testing.T) { | 365 | func TestDeleteRacingWithWrites(t *testing.T) { | ||
| 365 | ctx := context.Background() | 366 | ctx := context.Background() | ||
| 366 | for round := range 20 { | 367 | for round := range 20 { | ||
| @@ -394,7 +395,15 @@ func TestDeleteRacingWithWrites(t *testing.T) { | |||||
| 394 | } | 395 | } | ||
| 395 | }() | 396 | }() | ||
| 396 | } | 397 | } | ||
| 397 | - | delErr := s.Delete(ctx, n) | 398 | + | // Delete gives up with a conflict when the writers keep rewriting the |
| 399 | + | // repository key for deleteTries listings in a row; it is documented as | |||
| 400 | + | // safe to call again, as a caller does. | |||
| 401 | + | var delErr error | |||
| 402 | + | for range 20 { | |||
| 403 | + | if delErr = s.Delete(ctx, n); !errors.Is(delErr, domain.ErrConflict) { | |||
| 404 | + | break | |||
| 405 | + | } | |||
| 406 | + | } | |||
| 398 | wg.Wait() | 407 | wg.Wait() | ||
| 399 | require.NoError(t, delErr) | 408 | require.NoError(t, delErr) | ||
| 400 | 409 | ||||