Skip to content

Commit 572300e

Browse files
author
Andrew Baptist
committed
kvclient: simplify test
The test was previously using the index and getting the node id from that. This approach made it hard to avoid off-by-one errors. Using the node id directly makes the test easier to read. Epic: none Release note: None
1 parent b876c99 commit 572300e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

pkg/kv/kvclient/kvcoord/dist_sender_ambiguous_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
361361
Insecure: true,
362362
Knobs: base.TestingKnobs{
363363
KVClient: &kvcoord.ClientTestingKnobs{
364-
TransportFactory: getInterceptingTransportFactory(roachpb.NodeID(1)),
364+
TransportFactory: getInterceptingTransportFactory(1),
365365
},
366366
Store: &kvserver.StoreTestingKnobs{
367367
EvalKnobs: kvserverbase.BatchEvalTestingKnobs{
@@ -517,7 +517,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
517517
execLeaseMover := func(t *testing.T, name string) error {
518518
desc, err := tc.LookupRange(keyB)
519519
assert.NoError(t, err)
520-
t.Logf("Transferring r%d lease to n%d", desc.RangeID, tc.Target(0).NodeID)
520+
t.Logf("Transferring r%d lease to n%d", desc.RangeID, 1)
521521
assert.NoError(t, tc.TransferRangeLease(desc, tc.Target(0)))
522522
return nil
523523
}
@@ -585,7 +585,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
585585
// 3. txn1->n1: Put(a), EndTxn(parallel commit) -- Puts txn1 in STAGING.
586586
// 4. txn1->n2: Put(b) -- Send the request, but pause before returning
587587
// the response so we can inject network failure.
588-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
588+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
589589
// Once we have seen the write on txn1 to n2 that we will fail, txn2
590590
// can start.
591591
close(txn2Ready)
@@ -607,7 +607,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
607607
// <transfer b's lease to n1>
608608
// <inject a network failure and finally allow (4) txn1->n2: Put(b) to
609609
// return with error>
610-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
610+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
611611
// Hold the operation open until we are ready to retry on the new
612612
// replica, after which we will return the injected failure.
613613
req.pauseUntil(t, leaseMoveComplete, cp)
@@ -774,7 +774,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
774774
// 3. txn1->n1: Put(a), EndTxn(parallel commit) -- Puts txn1 in STAGING.
775775
// 4. txn1->n2: Put(b) -- Send the request, but pause before returning
776776
// the response so we can inject network failure.
777-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
777+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
778778
// Once we have seen the write on txn1 to n2 that we will fail, txn2
779779
// can start.
780780
close(txn2Ready)
@@ -796,7 +796,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
796796
// <transfer b's lease to n1>
797797
// <inject a network failure and finally allow (4) txn1->n2: Put(b) to
798798
// return with error>
799-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
799+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
800800
// Hold the operation open until we are ready to retry on the new
801801
// replica, after which we will return the injected failure.
802802
req.pauseUntil(t, leaseMoveComplete, cp)
@@ -937,7 +937,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
937937
// 3. txn1->n1: Put(a), EndTxn(parallel commit) -- Puts txn1 in STAGING.
938938
// 4. txn1->n2: Put(b) -- Send the request, but pause before returning
939939
// the response so we can inject network failure.
940-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
940+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
941941
// Once we have seen the write on txn1 to n2 that we will fail, we can
942942
// move the lease.
943943
close(txn2Ready)
@@ -958,7 +958,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
958958
// <transfer b's lease to n1>
959959
// <inject a network failure and finally allow (4) txn1->n2: Put(b) to
960960
// return with error>
961-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
961+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
962962
// Hold the operation open until we are ready to retry on the new
963963
// replica, after which we will return the injected failure.
964964
req.pauseUntil(t, leaseMoveComplete, cp)
@@ -1073,7 +1073,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
10731073
// 3. txn1->n1: Put(a), EndTxn(parallel commit) -- Puts txn1 in STAGING.
10741074
// 4. txn1->n2: Put(b) -- Send the request, but pause before returning the
10751075
// response so we can inject network failure.
1076-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
1076+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
10771077
// Once we have seen the write on txn1 to n2 that we will fail, txn2/txn3 can start.
10781078
close(otherTxnsReady)
10791079
}
@@ -1095,7 +1095,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
10951095
// <transfer b's lease to n1>
10961096
// <inject a network failure and finally allow (4) txn1->n2: Put(b) to
10971097
// return with error>
1098-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
1098+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
10991099
// Hold the operation open until we are ready to retry on the new
11001100
// replica, after which we will return the injected failure.
11011101
req.pauseUntil(t, leaseMoveComplete, cp)
@@ -1192,7 +1192,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
11921192
// 4. txn1->n2: Put(b) -- Send the request, but pause before returning the
11931193
// response so we can inject network failure.
11941194
// <transfer b's lease to n1>
1195-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
1195+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
11961196
close(leaseMoveReady)
11971197
req.pauseUntil(t, leaseMoveComplete, cp)
11981198
close(txn2Ready)
@@ -1210,7 +1210,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
12101210

12111211
// <inject a network failure and finally allow (4) txn1->n2: Put(b) to
12121212
// return with error>
1213-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
1213+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
12141214
// Hold the operation open until we are ready to retry on the new
12151215
// replica, after which we will return the injected failure.
12161216
req.pauseUntil(t, recoverComplete, cp)
@@ -1295,7 +1295,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
12951295
// 4. txn1->n2: Put(b) -- Send the request, but pause before returning the
12961296
// response so we can inject network failure.
12971297
// <transfer b's lease to n1>
1298-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
1298+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
12991299
close(leaseMoveReady)
13001300
req.pauseUntil(t, leaseMoveComplete, cp)
13011301
close(txn2Ready)
@@ -1317,7 +1317,7 @@ func TestTransactionUnexpectedlyCommitted(t *testing.T) {
13171317

13181318
// <inject a network failure and finally allow (4) txn1->n2: Put(b) to
13191319
// return with error>
1320-
if req.txnName == "txn1" && hasPut && req.toNodeID == tc.Server(1).NodeID() && cp == AfterSending {
1320+
if req.txnName == "txn1" && hasPut && req.toNodeID == 2 && cp == AfterSending {
13211321
// Hold the operation open until we are ready to retry on the new
13221322
// replica, after which we will return the injected failure.
13231323
req.pauseUntil(t, txn2ETReady, cp)

0 commit comments

Comments
 (0)