-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chore(datastore): fix for flaky integration tests #6979
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7930230
chore(datastore): fix for flaky integration tests
telpirion 0273b88
Unique key name for test
telpirion e0e4504
more attempts at fixes
telpirion a43cb37
Merge branch 'main' into datastore-more-fix
telpirion 090e1e5
Merge branch 'main' into datastore-more-fix
telpirion 3386227
iter
telpirion 11b8416
clarifying comments
telpirion 88dd258
per reviewer
telpirion 97e15cf
Merge branch 'main' into datastore-more-fix
telpirion 25570a1
Merge branch 'main' into datastore-more-fix
telpirion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"flag" | ||
"fmt" | ||
"log" | ||
"math" | ||
"os" | ||
"reflect" | ||
"sort" | ||
|
@@ -199,29 +200,49 @@ func TestIntegration_Basics(t *testing.T) { | |
} | ||
|
||
func TestIntegration_GetWithReadTime(t *testing.T) { | ||
ctx, _ := context.WithTimeout(context.Background(), time.Second*20) | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20) | ||
client := newTestClient(ctx, t) | ||
defer cancel() | ||
defer client.Close() | ||
|
||
type X struct { | ||
I int | ||
S string | ||
T time.Time | ||
U interface{} | ||
type RT struct { | ||
TimeCreated time.Time | ||
} | ||
|
||
x0 := X{66, "99", timeNow.Truncate(time.Millisecond), "X"} | ||
k, err := client.Put(ctx, IncompleteKey("BasicsX", nil), &x0) | ||
rt1 := RT{time.Now()} | ||
k := NameKey("RT", "ReadTime", nil) | ||
|
||
tx, err := client.NewTransaction(ctx) | ||
if err != nil { | ||
t.Fatalf("client.Put: %v", err) | ||
t.Fatal(err) | ||
} | ||
x1 := X{} | ||
client.WithReadOptions(ReadTime(time.Now())) | ||
err = client.Get(ctx, k, &x1) | ||
if err != nil { | ||
t.Errorf("client.Get: %v", err) | ||
|
||
if _, err := tx.Put(k, &rt1); err != nil { | ||
t.Fatalf("Transaction.Put: %v\n", err) | ||
} | ||
|
||
if _, err := tx.Commit(); err != nil { | ||
t.Fatalf("Transaction.Commit: %v\n", err) | ||
} | ||
|
||
// Wait a little bit for eventual consistency to catch up. | ||
time.Sleep(time.Duration(10 * math.Pow(10, 9))) | ||
|
||
testutil.Retry(t, 5, time.Duration(10*math.Pow(10, 9)), func(r *testutil.R) { | ||
got := RT{} | ||
tm := ReadTime(time.Now()) | ||
|
||
client.WithReadOptions(tm) | ||
|
||
// If the Entity isn't available at the requested read time, we get | ||
// a "datastore: no such entity" error. The ReadTime is otherwise not | ||
// exposed in anyway in the response. | ||
err = client.Get(ctx, k, &got) | ||
if err != nil { | ||
t.Errorf("client.Get: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be Btw, have you observed the retries working? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Nice catch! |
||
} | ||
}) | ||
|
||
// Cleanup | ||
_ = client.Delete(ctx, k) | ||
} | ||
|
@@ -321,7 +342,7 @@ func TestIntegration_GetMulti(t *testing.T) { | |
t.Error(err) | ||
} | ||
|
||
err := client.WithReadOptions(ReadTime(time.Now())).GetMulti(ctx, dstKeys, dst) | ||
err := client.GetMulti(ctx, dstKeys, dst) | ||
if err == nil { | ||
t.Errorf("client.GetMulti got %v, expected error", err) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really worth waiting 10s every time? I think this is only worth it if it's guaranteed to take that long, otherwise might as well try right away, or after a shorter wait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried several different time lengths from 1-10 seconds to ensure consistent test success. 10s was the lowest value that seemed to work every time (locally).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what, it looks like the issue was that I didn't hook into the retries correctly :). Nice catch!