Skip to content

Commit 35d019f

Browse files
committed
kvcoord: test that FoundKey is correctly populated on DeleteResponses
If there were a bug here, our logic tests would catch this, as evidenced by the CI failure on #144584. Nevertheless, add a more direct test. Epic: none Release note: None
1 parent a518c68 commit 35d019f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pkg/kv/kvclient/kvcoord/txn_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,42 @@ func TestTxnContinueAfterCputError(t *testing.T) {
10791079
})
10801080
}
10811081

1082+
// TestTxnDeleteResponse verifies that the Delete response correctly includes
1083+
// the keys that were deleted. Underneath the hood, this relies on
1084+
// DeleteResponse.FoundKeys to be set correctly.
1085+
func TestTxnDeleteResponse(t *testing.T) {
1086+
defer leaktest.AfterTest(t)()
1087+
defer log.Scope(t).Close(t)
1088+
1089+
testutils.RunTrueAndFalse(t, "bufferedWritesEnabled", func(t *testing.T, bufferedWritesEnabled bool) {
1090+
ctx := context.Background()
1091+
s := createTestDB(t)
1092+
defer s.Stop()
1093+
1094+
txn := s.DB.NewTxn(ctx, "test txn")
1095+
1096+
if bufferedWritesEnabled {
1097+
txn.SetBufferedWritesEnabled(true)
1098+
}
1099+
1100+
err := txn.Put(ctx, "a", "val")
1101+
require.NoError(t, err)
1102+
1103+
// Delete the key that we just wrote.
1104+
deleted, err := txn.Del(ctx, "a")
1105+
require.NoError(t, err)
1106+
require.Len(t, deleted, 1)
1107+
require.Equal(t, roachpb.Key("a"), deleted[0])
1108+
1109+
// Delete a virgin key.
1110+
deleted, err = txn.Del(ctx, "b")
1111+
require.NoError(t, err)
1112+
require.Empty(t, deleted)
1113+
1114+
require.NoError(t, txn.Commit(ctx))
1115+
})
1116+
}
1117+
10821118
// Test that a transaction can be used after a locking request returns a
10831119
// WriteIntentError. This is not generally allowed for other errors, but
10841120
// a WriteIntentError is special.

0 commit comments

Comments
 (0)