Skip to content

Commit

Permalink
fix(spanner): check errors in tests (#10738)
Browse files Browse the repository at this point in the history
* fix(spanner): add missing error checks to tests

* fix(spanner): check error before using client in test

* chore(spanner): remove redundant return-s

---------

Co-authored-by: rahul2393 <[email protected]>
  • Loading branch information
egonelbre and rahul2393 authored Sep 25, 2024
1 parent 6fbd687 commit 971bfb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3144,7 +3144,6 @@ func TestClient_ReadWriteTransactionConcurrentQueries(t *testing.T) {
}
rowCount++
}
return
}
wg.Add(2)
go query(&firstTransactionID)
Expand Down Expand Up @@ -4720,10 +4719,10 @@ func TestClient_EmulatorWithCredentialsFile(t *testing.T) {
"localhost:1234",
opts...,
)
defer client.Close()
if err != nil {
t.Fatalf("Failed to create a client with credentials file when running against an emulator: %v", err)
}
defer client.Close()
}

func TestBatchReadOnlyTransaction_QueryOptions(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion spanner/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ func newSessionPool(sc *sessionClient, config SessionPoolConfig) (*sessionPool,
// wait for the session to be created
case <-pool.mayGetMultiplexedSession:
}
return
}()
}
pool.recordStat(context.Background(), MaxAllowedSessionsCount, int64(config.MaxOpened))
Expand Down
12 changes: 12 additions & 0 deletions spanner/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ func TestReadWriteStmtBasedTransactionWithOptions(t *testing.T) {
client,
TransactionOptions{CommitOptions: CommitOptions{ReturnCommitStats: true}},
)
if err != nil {
t.Fatalf("failed to create transaction: %v", err)
}

_, err = f(tx)
if err != nil && status.Code(err) != codes.Aborted {
tx.Rollback(ctx)
Expand Down Expand Up @@ -592,6 +596,10 @@ func TestBatchDML_StatementBased_WithMultipleDML(t *testing.T) {
defer teardown()

tx, err := NewReadWriteStmtBasedTransaction(ctx, client)
if err != nil {
t.Fatalf("failed to create transaction: %v", err)
}

if _, err = tx.Update(ctx, Statement{SQL: UpdateBarSetFoo}); err != nil {
tx.Rollback(ctx)
t.Fatal(err)
Expand Down Expand Up @@ -653,6 +661,10 @@ func TestPriorityInQueryOptions(t *testing.T) {
defer teardown()

tx, err := NewReadWriteStmtBasedTransaction(ctx, client)
if err != nil {
t.Fatalf("failed to create transaction: %v", err)
}

var iter *RowIterator
iter = tx.txReadOnly.Query(ctx, NewStatement("SELECT 1"))
err = iter.Do(func(r *Row) error { return nil })
Expand Down

0 comments on commit 971bfb8

Please sign in to comment.