Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vttablet: Improve Hot Row protection unit test coverage. #3121

Merged
merged 1 commit into from
Aug 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions go/vt/vttablet/tabletserver/txserializer/tx_serializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ import (
)

func resetVariables() {
waits.Reset()
waitsDryRun.Reset()
queueExceeded.Reset()
queueExceededDryRun.Reset()
globalQueueExceeded.Set(0)
globalQueueExceededDryRun.Set(0)
}

Expand All @@ -47,7 +50,7 @@ func TestTxSerializer(t *testing.T) {
t.Fatal(err1)
}
if waited1 {
t.Fatalf("first transaction must never wait: %v", waited1)
t.Fatalf("tx1 must never wait: %v", waited1)
}

// tx2 (gets queued and must wait).
Expand All @@ -61,7 +64,7 @@ func TestTxSerializer(t *testing.T) {
t.Fatal(err2)
}
if !waited2 {
t.Fatalf("second transaction must wait: %v", waited2)
t.Fatalf("tx2 must wait: %v", waited2)
}
if got, want := waits.Counts()["t1"], int64(1); got != want {
t.Fatalf("variable not incremented: got = %v, want = %v", got, want)
Expand Down Expand Up @@ -91,9 +94,18 @@ func TestTxSerializer(t *testing.T) {
t.Fatal("queue object was not deleted after last transaction")
}

// 2 transactions were recorded.
if err := testHTTPHandler(txs, 2); err != nil {
t.Fatal(err)
}
// 1 of them had to wait.
if got, want := waits.Counts()["t1"], int64(1); got != want {
t.Fatalf("variable not incremented: got = %v, want = %v", got, want)
}
// 1 (the third one) was rejected because the queue was exceeded.
if got, want := queueExceeded.Counts()["t1"], int64(1); got != want {
t.Fatalf("variable not incremented: got = %v, want = %v", got, want)
}
}

func waitForPending(txs *TxSerializer, key string, i int) error {
Expand Down Expand Up @@ -147,7 +159,7 @@ func TestTxSerializerCancel(t *testing.T) {
t.Fatal(err1)
}
if waited1 {
t.Fatalf("first transaction must never wait: %v", waited1)
t.Fatalf("tx1 must never wait: %v", waited1)
}

// tx2 (gets queued and must wait).
Expand Down Expand Up @@ -179,7 +191,7 @@ func TestTxSerializerCancel(t *testing.T) {
t.Fatal(err3)
}
if !waited3 {
t.Fatalf("third transaction must wait: %v", waited3)
t.Fatalf("tx3 must have waited: %v", waited3)
}

txDone <- 3
Expand Down Expand Up @@ -209,9 +221,14 @@ func TestTxSerializerCancel(t *testing.T) {
t.Fatal("queue object was not deleted after last transaction")
}

// 3 total transactions get recorded.
if err := testHTTPHandler(txs, 3); err != nil {
t.Fatal(err)
}
// 2 of them had to wait.
if got, want := waits.Counts()["t1"], int64(2); got != want {
t.Fatalf("variable not incremented: got = %v, want = %v", got, want)
}
}

// TestTxSerializerDryRun verifies that the dry-run mode does not serialize
Expand Down Expand Up @@ -311,6 +328,9 @@ func TestTxSerializerGlobalQueueOverflow(t *testing.T) {
if got, want := err3.Error(), "hot row protection: too many queued transactions (2 >= 1)"; got != want {
t.Fatalf("transaction rejected with wrong error: got = %v, want = %v", got, want)
}
if got, want := globalQueueExceeded.Get(), int64(1); got != want {
t.Fatalf("variable not incremented: got = %v, want = %v", got, want)
}

done1()
done2()
Expand Down