From 9ac471571e20c9409a85bb78eb0ee4ce385eb795 Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Thu, 24 Aug 2023 16:43:05 -0700 Subject: [PATCH 1/6] test(datastore): View presubmit logs --- datastore/integration_test.go | 15 +++++++++------ internal/kokoro/presubmit.sh | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/datastore/integration_test.go b/datastore/integration_test.go index f698eee50383..f308bf501db4 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -725,6 +725,7 @@ func TestIntegration_AggregationQueries(t *testing.T) { // Create transaction with read before creating entities readTime := time.Now().Add(-59 * time.Minute).Truncate(time.Microsecond) + fmt.Printf("readTime before create: %v\n", readTime) txBeforeCreate, err := client.NewTransaction(ctx, []TransactionOption{ReadOnly, WithReadTime(readTime)}...) if err != nil { t.Fatalf("client.NewTransaction: %v", err) @@ -734,15 +735,17 @@ func TestIntegration_AggregationQueries(t *testing.T) { if err != nil { t.Fatalf("client.PutMulti: %v", err) } - defer func() { - err := client.DeleteMulti(ctx, keys) - if err != nil { - t.Errorf("client.DeleteMulti: %v", err) - } - }() + // defer func() { + // err := client.DeleteMulti(ctx, keys) + // if err != nil { + // t.Errorf("client.DeleteMulti: %v", err) + // } + // }() + time.Sleep(1000 * time.Millisecond) // Create transaction with read after creating entities readTime = time.Now().Truncate(time.Microsecond) + fmt.Printf("readTime after create: %v\n", readTime) txAfterCreate, err := client.NewTransaction(ctx, []TransactionOption{ReadOnly, WithReadTime(readTime)}...) if err != nil { t.Fatalf("client.NewTransaction: %v", err) diff --git a/internal/kokoro/presubmit.sh b/internal/kokoro/presubmit.sh index 5b15fec68421..463f1821394a 100755 --- a/internal/kokoro/presubmit.sh +++ b/internal/kokoro/presubmit.sh @@ -54,7 +54,7 @@ runPresubmitTests() { fi if [ -z ${RUN_INTEGRATION_TESTS} ]; then - go test -race -v -timeout 15m -short ./... 2>&1 | + go test -race -v -timeout 45m ./... 2>&1 | tee sponge_log.log else go test -race -v -timeout 45m ./... 2>&1 | From fc0a856241b6841372fd77ffc52f8aa4035019b1 Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Thu, 24 Aug 2023 16:47:25 -0700 Subject: [PATCH 2/6] test(datastore): Print entity parent --- datastore/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/datastore/integration_test.go b/datastore/integration_test.go index f308bf501db4..b545329c7c57 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -706,6 +706,7 @@ func TestIntegration_AggregationQueries(t *testing.T) { defer client.Close() parent := NameKey("SQParent", keyPrefix+"AggregationQueries"+suffix, nil) + fmt.Printf("Parent: %v\n", keyPrefix+"AggregationQueries"+suffix) now := timeNow.Truncate(time.Millisecond).Unix() children := []*SQChild{ {I: 0, T: now, U: now, V: 1.5, W: "str"}, From dfaf362ee3709c6da722f84a085b4c2a870f26af Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Fri, 25 Aug 2023 13:43:45 -0700 Subject: [PATCH 3/6] test(datastore): More logs --- datastore/integration_test.go | 2 +- datastore/transaction.go | 2 ++ internal/kokoro/presubmit.sh | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/datastore/integration_test.go b/datastore/integration_test.go index b545329c7c57..94e328adb6d3 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -743,7 +743,7 @@ func TestIntegration_AggregationQueries(t *testing.T) { // } // }() - time.Sleep(1000 * time.Millisecond) + time.Sleep(10000 * time.Millisecond) // Create transaction with read after creating entities readTime = time.Now().Truncate(time.Microsecond) fmt.Printf("readTime after create: %v\n", readTime) diff --git a/datastore/transaction.go b/datastore/transaction.go index 579ab56adcac..0a26af732e9f 100644 --- a/datastore/transaction.go +++ b/datastore/transaction.go @@ -17,6 +17,7 @@ package datastore import ( "context" "errors" + "fmt" "time" "cloud.google.com/go/internal/trace" @@ -134,6 +135,7 @@ func (c *Client) newTransaction(ctx context.Context, s *transactionSettings) (_ ProjectId: c.dataset, DatabaseId: c.databaseID, } + fmt.Printf("req: %v\n", req) if s.readOnly { ctx = trace.StartSpan(ctx, "cloud.google.com/go/datastore.Transaction.ReadOnlyTransaction") defer func() { trace.EndSpan(ctx, err) }() diff --git a/internal/kokoro/presubmit.sh b/internal/kokoro/presubmit.sh index 463f1821394a..5b15fec68421 100755 --- a/internal/kokoro/presubmit.sh +++ b/internal/kokoro/presubmit.sh @@ -54,7 +54,7 @@ runPresubmitTests() { fi if [ -z ${RUN_INTEGRATION_TESTS} ]; then - go test -race -v -timeout 45m ./... 2>&1 | + go test -race -v -timeout 15m -short ./... 2>&1 | tee sponge_log.log else go test -race -v -timeout 45m ./... 2>&1 | From fa4f3b7b6a274d8cc1a361573b8d275b480a8bbb Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Fri, 25 Aug 2023 19:35:23 -0700 Subject: [PATCH 4/6] test(datastore): Add explicit sleep before querying entities. --- datastore/integration_test.go | 17 +++++++---------- datastore/transaction.go | 2 -- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/datastore/integration_test.go b/datastore/integration_test.go index 94e328adb6d3..65c68e142284 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -706,7 +706,6 @@ func TestIntegration_AggregationQueries(t *testing.T) { defer client.Close() parent := NameKey("SQParent", keyPrefix+"AggregationQueries"+suffix, nil) - fmt.Printf("Parent: %v\n", keyPrefix+"AggregationQueries"+suffix) now := timeNow.Truncate(time.Millisecond).Unix() children := []*SQChild{ {I: 0, T: now, U: now, V: 1.5, W: "str"}, @@ -726,7 +725,6 @@ func TestIntegration_AggregationQueries(t *testing.T) { // Create transaction with read before creating entities readTime := time.Now().Add(-59 * time.Minute).Truncate(time.Microsecond) - fmt.Printf("readTime before create: %v\n", readTime) txBeforeCreate, err := client.NewTransaction(ctx, []TransactionOption{ReadOnly, WithReadTime(readTime)}...) if err != nil { t.Fatalf("client.NewTransaction: %v", err) @@ -736,17 +734,16 @@ func TestIntegration_AggregationQueries(t *testing.T) { if err != nil { t.Fatalf("client.PutMulti: %v", err) } - // defer func() { - // err := client.DeleteMulti(ctx, keys) - // if err != nil { - // t.Errorf("client.DeleteMulti: %v", err) - // } - // }() + defer func() { + err := client.DeleteMulti(ctx, keys) + if err != nil { + t.Errorf("client.DeleteMulti: %v", err) + } + }() - time.Sleep(10000 * time.Millisecond) + time.Sleep(10 * time.Second) // Create transaction with read after creating entities readTime = time.Now().Truncate(time.Microsecond) - fmt.Printf("readTime after create: %v\n", readTime) txAfterCreate, err := client.NewTransaction(ctx, []TransactionOption{ReadOnly, WithReadTime(readTime)}...) if err != nil { t.Fatalf("client.NewTransaction: %v", err) diff --git a/datastore/transaction.go b/datastore/transaction.go index 0a26af732e9f..579ab56adcac 100644 --- a/datastore/transaction.go +++ b/datastore/transaction.go @@ -17,7 +17,6 @@ package datastore import ( "context" "errors" - "fmt" "time" "cloud.google.com/go/internal/trace" @@ -135,7 +134,6 @@ func (c *Client) newTransaction(ctx context.Context, s *transactionSettings) (_ ProjectId: c.dataset, DatabaseId: c.databaseID, } - fmt.Printf("req: %v\n", req) if s.readOnly { ctx = trace.StartSpan(ctx, "cloud.google.com/go/datastore.Transaction.ReadOnlyTransaction") defer func() { trace.EndSpan(ctx, err) }() From 6962f935b3e0c59495d4a78e70bd020916f4817c Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Mon, 28 Aug 2023 13:02:55 -0700 Subject: [PATCH 5/6] test(datastore): Sleep only if test failed --- datastore/integration_test.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/datastore/integration_test.go b/datastore/integration_test.go index 65c68e142284..6dd4ab029cb1 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -875,18 +875,20 @@ func TestIntegration_AggregationQueries(t *testing.T) { } for _, testCase := range testCases { - gotAggResult, gotErr := client.RunAggregationQuery(ctx, testCase.aggQuery) - gotFailure := gotErr != nil + testutil.Retry(t, 10, time.Second, func(r *testutil.R) { + gotAggResult, gotErr := client.RunAggregationQuery(ctx, testCase.aggQuery) + gotFailure := gotErr != nil - if gotFailure != testCase.wantFailure || - (gotErr != nil && !strings.Contains(gotErr.Error(), testCase.wantErrMsg)) { - t.Errorf("%q: Mismatch in error got: %v, want: %q", testCase.desc, gotErr, testCase.wantErrMsg) - continue - } - if !reflect.DeepEqual(gotAggResult, testCase.wantAggResult) { - t.Errorf("%q: Mismatch in aggregation result got: %v, want: %v", testCase.desc, gotAggResult, testCase.wantAggResult) - continue - } + if gotFailure != testCase.wantFailure || + (gotErr != nil && !strings.Contains(gotErr.Error(), testCase.wantErrMsg)) { + r.Errorf("%q: Mismatch in error got: %v, want: %q", testCase.desc, gotErr, testCase.wantErrMsg) + return + } + if gotErr == nil && !reflect.DeepEqual(gotAggResult, testCase.wantAggResult) { + r.Errorf("%q: Mismatch in aggregation result got: %v, want: %v", testCase.desc, gotAggResult, testCase.wantAggResult) + return + } + }) } } From eb65c6b2bd1c10616d9c962ad6a0ae6f786bacae Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Mon, 28 Aug 2023 13:48:12 -0700 Subject: [PATCH 6/6] test(datastore): remove explicit sleep --- datastore/integration_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/datastore/integration_test.go b/datastore/integration_test.go index 6dd4ab029cb1..6149063c36d8 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -741,7 +741,6 @@ func TestIntegration_AggregationQueries(t *testing.T) { } }() - time.Sleep(10 * time.Second) // Create transaction with read after creating entities readTime = time.Now().Truncate(time.Microsecond) txAfterCreate, err := client.NewTransaction(ctx, []TransactionOption{ReadOnly, WithReadTime(readTime)}...)