Skip to content

Commit 1e0ccb1

Browse files
craig[bot]yuzefovich
andcommitted
Merge #147508
147508: tests: harden TestDeadlockDetection for buffered writes r=yuzefovich a=yuzefovich We've seen a couple of failures under race where we lost the unreplicated lock on a split due to metamorphically disabled corresponding lock reliability setting. Fixes: #147217. Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]>
2 parents 2023035 + a7caa0b commit 1e0ccb1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/sql/tests/deadlock_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func TestDeadlockDetection(t *testing.T) {
5050
defer srv.Stopper().Stop(ctx)
5151
sqlr := sqlutils.MakeSQLRunner(db)
5252

53+
hostRunner := sqlutils.MakeSQLRunner(srv.SystemLayer().SQLConn(t))
54+
// If we happen to enable buffered writes metamorphically, we must have the
55+
// split lock reliability enabled (which can be tweaked metamorphically too,
56+
// #147217).
57+
hostRunner.Exec(t, "SET CLUSTER SETTING kv.lock_table.unreplicated_lock_reliability.split.enabled = true")
58+
5359
sqlr.Exec(t, "CREATE TABLE test1 (id int, age int)")
5460
sqlr.Exec(t, "CREATE TABLE test2 (id int, age int)")
5561
sqlr.Exec(t, "INSERT INTO test1 (id, age) VALUES (1, 0)")
@@ -116,7 +122,7 @@ func TestDeadlockDetection(t *testing.T) {
116122
wg.Done()
117123
}()
118124

119-
// After executing the next operation, a deadlock is created. Measure the
125+
// After executing the next operation, a deadlock is created. Measure the
120126
// time it takes for the deadlock condition to be broken.
121127
_, tx1Err := tx1.Exec("UPDATE test2 SET age = 1 WHERE id = 1")
122128
wg.Wait()
@@ -127,9 +133,11 @@ func TestDeadlockDetection(t *testing.T) {
127133
if tx1Err != nil {
128134
require.NoError(t, tx2Err)
129135
require.Contains(t, tx1Err.Error(), "TransactionRetryWithProtoRefreshError")
130-
} else {
136+
} else if tx2Err != nil {
131137
require.NoError(t, tx1Err)
132138
require.Contains(t, tx2Err.Error(), "TransactionRetryWithProtoRefreshError")
139+
} else {
140+
t.Fatal("neither txn encountered an error")
133141
}
134142

135143
require.NoError(t, tx1.Rollback())

0 commit comments

Comments
 (0)