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

fix: Various issues found in testing Ruby client #166

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 24 additions & 18 deletions tests/mutaterows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,18 @@ func TestMutateRows_Retry_ExponentialBackoff(t *testing.T) {

// 4b. Log the retry delays
origReq := <-recorder
firstRetry := <-recorder
secondRetry := <-recorder
thirdRetry := <-recorder
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was hanging indefinitely when the client made fewer than three retries.


firstDelay := int(firstRetry.ts.UnixMilli() - origReq.ts.UnixMilli())
secondDelay := int(secondRetry.ts.UnixMilli() - firstRetry.ts.UnixMilli())
thirdDelay := int(thirdRetry.ts.UnixMilli() - secondRetry.ts.UnixMilli())

// Different clients may have different behaviors, we log the delays for informational purpose.
// Example: For the first retry delay, C++ client uses 100ms but Java client uses 10ms.
t.Logf("The three retry delays are: %dms, %dms, %dms", firstDelay, secondDelay, thirdDelay)
for n := 1; n < numRPCs; n += 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the end we should assert that n == 3? so it doesn't hang and we can verify the client retried 3 times?

Copy link
Contributor Author

@meagar meagar Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an assertion for this above,

	// 4a. Check the number of requests in the recorder
	assert.Equal(t, numRPCs, len(recorder))

This lines are not functionally part of the test, they just seem to output debugging information. There are no assertions here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true :) ok

select {
case retry := <- recorder:
delay := int(retry.ts.UnixMilli() - origReq.ts.UnixMilli())
// Different clients may have different behaviors, we log the delays for informational purpose.
// Example: For the first retry delay, C++ client uses 100ms but Java client uses 10ms.
t.Logf("Retry #%d delay: %dms", n, delay)
case <-time.After(500 * time.Millisecond):
t.Logf("Retry #%d: Timeout waiting for retry (expecting %d retries)", n, numRPCs - 1)
}
}
}

// TestMutateRows_Generic_MultiStreams tests that client can have multiple concurrent streams.
Expand Down Expand Up @@ -496,14 +497,19 @@ func TestMutateRows_Retry_WithRoutingCookie(t *testing.T) {
// 4b. Verify routing cookie is seen
// Ignore the first metadata which won't have the routing cookie
var _ = <-mdRecorder
// second metadata which comes from the retry attempt should have a routing cookie field
md1 := <-mdRecorder
val := md1["x-goog-cbt-cookie-test"]
assert.NotEmpty(t, val)
if len(val) == 0 {
return
}
assert.Equal(t, cookie, val[0])

select {
mutianf marked this conversation as resolved.
Show resolved Hide resolved
case md1 := <-mdRecorder:
// second metadata which comes from the retry attempt should have a routing cookie field
val := md1["x-goog-cbt-cookie-test"]
assert.NotEmpty(t, val)
if len(val) == 0 {
return
}
assert.Equal(t, cookie, val[0])
case <- time.After(100 * time.Millisecond):
t.Error("Timeout waiting for requests on recorder channel")
}
}

// TestMutateRows_Retry_WithRetryInfo tests that client is handling RetryInfo correctly.
Expand Down
4 changes: 3 additions & 1 deletion tests/readrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,7 @@ func TestReadRow_Retry_WithRetryInfo(t *testing.T) {
firstReqTs := firstReq.ts.Unix()
retryReqTs := retryReq.ts.Unix()

assert.True(t, retryReqTs-firstReqTs >= 2)
delta := retryReqTs - firstReqTs

assert.True(t, delta >= 2, fmt.Sprintf("Expected retry to happen after 2ms, got %dms", delta))
}
13 changes: 8 additions & 5 deletions tests/readrows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ func TestReadRows_ReverseScans_FeatureFlag_Enabled(t *testing.T) {
md := <-mdRecords

ff, err := getClientFeatureFlags(md)

assert.Nil(t, err, "failed to decode client feature flags")

assert.True(t, ff.ReverseScans, "client does must enable ReverseScans feature flag")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was segfaulting when ff was nil.

assert.True(t, ff != nil && ff.ReverseScans, "client must enable ReverseScans feature flag")
}

// TestReadRows_NoRetry_OutOfOrderError_Reverse tests that client will fail on receiving out of order row keys for reverse scans.
Expand Down Expand Up @@ -892,8 +890,13 @@ func TestReadRows_Retry_WithRoutingCookie_MultipleErrorResponses(t *testing.T) {
// 4a. Verify that the read succeeds
checkResultOkStatus(t, res)
assert.Equal(t, 2, len(res.GetRows()))
assert.Equal(t, "row-01", string(res.Rows[0].Key))
mutianf marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, "row-05", string(res.Rows[1].Key))
if len(res.GetRows()) > 0 {
assert.Equal(t, "row-01", string(res.Rows[0].Key))
}

if len(res.GetRows()) > 1 {
assert.Equal(t, "row-05", string(res.Rows[1].Key))
}

// 4b. Verify routing cookie is seen
// Ignore the first metadata which won't have the routing cookie
Expand Down
10 changes: 7 additions & 3 deletions tests/samplerowkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,13 @@ func TestSampleRowKeys_Retry_WithRetryInfo(t *testing.T) {

// 4b. Verify retry backoff time is correct
firstReq := <-recorder
retryReq := <-recorder
mutianf marked this conversation as resolved.
Show resolved Hide resolved
firstReqTs := firstReq.ts.Unix()
retryReqTs := retryReq.ts.Unix()

assert.True(t, retryReqTs-firstReqTs >= 2)
select {
case retryReq := <-recorder:
retryReqTs := retryReq.ts.Unix()
assert.True(t, retryReqTs-firstReqTs >= 2)
case <-time.After(2 * time.Second):
t.Error("Timeout waiting for retry request")
}
}