@@ -32,6 +32,7 @@ import (
3232 "google.golang.org/api/iterator"
3333 "google.golang.org/genproto/googleapis/rpc/errdetails"
3434 "google.golang.org/grpc/codes"
35+ "google.golang.org/grpc/metadata"
3536 "google.golang.org/grpc/status"
3637 "google.golang.org/protobuf/proto"
3738 "google.golang.org/protobuf/types/known/durationpb"
@@ -806,7 +807,9 @@ func TestRsdNonblockingStates(t *testing.T) {
806807 }, opts ... )
807808 }
808809 }
809- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
810+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
811+ ctx := metadata .NewOutgoingContext (context .Background (), md )
812+ ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
810813 defer cancel ()
811814 mt := c .metricsTracerFactory .createBuiltinMetricsTracer (ctx )
812815 r := newResumableStreamDecoder (
@@ -1108,7 +1111,9 @@ func TestRsdBlockingStates(t *testing.T) {
11081111 }, opts ... )
11091112 }
11101113 }
1111- ctx , cancel := context .WithCancel (context .Background ())
1114+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1115+ ctx := metadata .NewOutgoingContext (context .Background (), md )
1116+ ctx , cancel := context .WithCancel (ctx )
11121117 defer cancel ()
11131118 mt := c .metricsTracerFactory .createBuiltinMetricsTracer (ctx )
11141119 r := newResumableStreamDecoder (
@@ -1276,7 +1281,9 @@ func TestQueueBytes(t *testing.T) {
12761281 sr := & sReceiver {
12771282 c : make (chan int , 1000 ), // will never block in this test
12781283 }
1279- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1284+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1285+ ctx := metadata .NewOutgoingContext (context .Background (), md )
1286+ ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
12801287 defer cancel ()
12811288 mt := c .metricsTracerFactory .createBuiltinMetricsTracer (ctx )
12821289 decoder := newResumableStreamDecoder (
@@ -1379,8 +1386,10 @@ func TestResumeToken(t *testing.T) {
13791386 }
13801387 rows := []* Row {}
13811388
1389+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1390+ ctx := metadata .NewOutgoingContext (context .Background (), md )
13821391 streaming := func () * RowIterator {
1383- return stream (context . Background () , nil ,
1392+ return stream (ctx , nil ,
13841393 c .metricsTracerFactory ,
13851394 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
13861395 r , err := mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
@@ -1523,10 +1532,12 @@ func TestGrpcReconnect(t *testing.T) {
15231532 },
15241533 )
15251534
1535+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1536+ ctx := metadata .NewOutgoingContext (context .Background (), md )
15261537 // The retry is counted from the second call.
15271538 r := - 1
15281539 // Establish a stream to mock cloud spanner server.
1529- iter := stream (context . Background () , nil , c .metricsTracerFactory ,
1540+ iter := stream (ctx , nil , c .metricsTracerFactory ,
15301541 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
15311542 r ++
15321543 return mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
@@ -1580,10 +1591,12 @@ func TestRetryResourceExhaustedWithoutRetryInfo(t *testing.T) {
15801591 },
15811592 )
15821593
1594+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1595+ ctx := metadata .NewOutgoingContext (context .Background (), md )
15831596 // The retry is counted from the second call.
15841597 r := - 1
15851598 // Establish a stream to mock cloud spanner server.
1586- iter := stream (context . Background () , nil , c .metricsTracerFactory ,
1599+ iter := stream (ctx , nil , c .metricsTracerFactory ,
15871600 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
15881601 r ++
15891602 return mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
@@ -1644,10 +1657,12 @@ func TestRetryResourceExhaustedWithRetryInfo(t *testing.T) {
16441657 },
16451658 )
16461659
1660+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1661+ ctx := metadata .NewOutgoingContext (context .Background (), md )
16471662 // The retry is counted from the second call.
16481663 r := - 1
16491664 // Establish a stream to mock cloud spanner server.
1650- iter := stream (context . Background () , nil , c .metricsTracerFactory ,
1665+ iter := stream (ctx , nil , c .metricsTracerFactory ,
16511666 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
16521667 r ++
16531668 return mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
@@ -1696,8 +1711,9 @@ func TestCancelTimeout(t *testing.T) {
16961711 }
16971712 done := make (chan int )
16981713
1714+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
16991715 // Test cancelling query.
1700- ctx , cancel := context .WithCancel (context .Background ())
1716+ ctx , cancel := context .WithCancel (metadata . NewOutgoingContext ( context .Background (), md ))
17011717 go func () {
17021718 // Establish a stream to mock cloud spanner server.
17031719 iter := stream (ctx , nil , c .metricsTracerFactory ,
@@ -1733,7 +1749,7 @@ func TestCancelTimeout(t *testing.T) {
17331749 }
17341750
17351751 // Test query timeout.
1736- ctx , cancel = context .WithTimeout (context .Background (), 100 * time .Millisecond )
1752+ ctx , cancel = context .WithTimeout (metadata . NewOutgoingContext ( context .Background (), md ), 100 * time .Millisecond )
17371753 defer cancel ()
17381754 go func () {
17391755 // Establish a stream to mock cloud spanner server.
@@ -1886,7 +1902,9 @@ func TestRowIteratorDo(t *testing.T) {
18861902 }
18871903
18881904 nRows := 0
1889- iter := stream (context .Background (), nil , c .metricsTracerFactory ,
1905+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1906+ ctx := metadata .NewOutgoingContext (context .Background (), md )
1907+ iter := stream (ctx , nil , c .metricsTracerFactory ,
18901908 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
18911909 return mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
18921910 Session : session .Name ,
@@ -1921,7 +1939,9 @@ func TestRowIteratorDoWithError(t *testing.T) {
19211939 t .Fatalf ("failed to create a session" )
19221940 }
19231941
1924- iter := stream (context .Background (), nil , c .metricsTracerFactory ,
1942+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1943+ ctx := metadata .NewOutgoingContext (context .Background (), md )
1944+ iter := stream (ctx , nil , c .metricsTracerFactory ,
19251945 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
19261946 return mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
19271947 Session : session .Name ,
@@ -1955,6 +1975,8 @@ func TestIteratorStopEarly(t *testing.T) {
19551975 t .Fatalf ("failed to create a session" )
19561976 }
19571977
1978+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
1979+ ctx = metadata .NewOutgoingContext (ctx , md )
19581980 iter := stream (ctx , nil , c .metricsTracerFactory ,
19591981 func (ct context.Context , resumeToken []byte , opts ... gax.CallOption ) (streamingReceiver , error ) {
19601982 return mc .ExecuteStreamingSql (ct , & sppb.ExecuteSqlRequest {
@@ -1996,5 +2018,8 @@ func createSession(client spannerClient) (*sppb.Session, error) {
19962018 Database : formattedDatabase ,
19972019 Session : & sppb.Session {},
19982020 }
1999- return client .CreateSession (context .Background (), request )
2021+ ctx := context .Background ()
2022+ md := metadata .Pairs (resourcePrefixHeader , "projects/p/instances/i/databases/d" )
2023+ ctx = metadata .NewOutgoingContext (ctx , md )
2024+ return client .CreateSession (ctx , request )
20002025}
0 commit comments