From 83eeec51e85ec84c326d4517fd9696079da5e60b Mon Sep 17 00:00:00 2001 From: tenntenn Date: Sat, 12 Sep 2020 00:10:06 +0900 Subject: [PATCH] Add tests for issue32 --- passes/unclosetx/testdata/src/a/a.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/passes/unclosetx/testdata/src/a/a.go b/passes/unclosetx/testdata/src/a/a.go index ece2870..bd4d2a8 100644 --- a/passes/unclosetx/testdata/src/a/a.go +++ b/passes/unclosetx/testdata/src/a/a.go @@ -4,6 +4,7 @@ import ( "context" "cloud.google.com/go/spanner" + "golang.org/x/sync/errgroup" ) func f1(ctx context.Context, client *spanner.Client) { @@ -54,3 +55,21 @@ func f5(ctx context.Context, client *spanner.Client) { tx, _ := client.BatchReadOnlyTransaction(ctx, spanner.StrongRead()) // want "transaction must be closed" _ = tx } + +// see https://github.com/gcpug/zagane/issues/32 +func f6(ctx context.Context, client *spanner.Client) error { + tx := client.ReadOnlyTransaction() // OK + defer tx.Close() + + var eg errgroup.Group + + eg.Go(func() error { + _ = tx // use tx + return nil + }) + + if err := eg.Wait(); err != nil { + return err + } + return nil +}