@@ -29,47 +29,51 @@ func TestClient_Topic(t *testing.T) {
29
29
require .NoError (t , err )
30
30
defer teardown ()
31
31
32
- sensor := instana .NewSensorWithTracer (
33
- instana .NewTracerWithEverything (
34
- instana .DefaultOptions (),
35
- instana .NewTestRecorder (),
36
- ),
37
- )
32
+ recorder := instana .NewTestRecorder ()
33
+ tracer := instana .NewTracerWithEverything (& instana.Options {AgentClient : alwaysReadyClient {}}, recorder )
34
+
35
+ sensor := instana .NewSensorWithTracer (tracer )
38
36
defer instana .ShutdownSensor ()
39
37
40
- _ , err = srv .GServer .CreateTopic (context .Background (), & pb.Topic {
38
+ pSpan := tracer .StartSpan ("parent-span" )
39
+ ctx := context .Background ()
40
+ if pSpan != nil {
41
+ ctx = instana .ContextWithSpan (ctx , pSpan )
42
+ }
43
+
44
+ _ , err = srv .GServer .CreateTopic (ctx , & pb.Topic {
41
45
Name : "projects/test-project/topics/test-topic" ,
42
46
})
43
47
require .NoError (t , err )
44
48
45
49
examples := map [string ]func (* testing.T , * pubsub.Message ) * pubsub.PublishResult {
46
50
"ClientProject" : func (t * testing.T , msg * pubsub.Message ) * pubsub.PublishResult {
47
- client , err := pubsub .NewClient (context . Background () , "test-project" , sensor , option .WithGRPCConn (conn ))
51
+ client , err := pubsub .NewClient (ctx , "test-project" , sensor , option .WithGRPCConn (conn ))
48
52
require .NoError (t , err )
49
53
50
54
top := client .Topic ("test-topic" )
51
55
52
- return top .Publish (context . Background () , msg )
56
+ return top .Publish (ctx , msg )
53
57
},
54
58
"OtherProject" : func (t * testing.T , msg * pubsub.Message ) * pubsub.PublishResult {
55
- client , err := pubsub .NewClient (context . Background () , "other-project" , sensor , option .WithGRPCConn (conn ))
59
+ client , err := pubsub .NewClient (ctx , "other-project" , sensor , option .WithGRPCConn (conn ))
56
60
require .NoError (t , err )
57
61
58
62
top := client .TopicInProject ("test-topic" , "test-project" )
59
63
60
- return top .Publish (context . Background () , msg )
64
+ return top .Publish (ctx , msg )
61
65
},
62
66
"CreateTopic" : func (t * testing.T , msg * pubsub.Message ) * pubsub.PublishResult {
63
- client , err := pubsub .NewClient (context . Background () , "test-project" , sensor , option .WithGRPCConn (conn ))
67
+ client , err := pubsub .NewClient (ctx , "test-project" , sensor , option .WithGRPCConn (conn ))
64
68
require .NoError (t , err )
65
69
66
- top , err := client .CreateTopic (context . Background () , "new-test-topic" )
70
+ top , err := client .CreateTopic (ctx , "new-test-topic" )
67
71
require .NoError (t , err )
68
72
69
- return top .Publish (context . Background () , msg )
73
+ return top .Publish (ctx , msg )
70
74
},
71
75
"CreateTopicWithConfig" : func (t * testing.T , msg * pubsub.Message ) * pubsub.PublishResult {
72
- client , err := pubsub .NewClient (context . Background () , "test-project" , sensor , option .WithGRPCConn (conn ))
76
+ client , err := pubsub .NewClient (ctx , "test-project" , sensor , option .WithGRPCConn (conn ))
73
77
require .NoError (t , err )
74
78
75
79
conf := & gpubsub.TopicConfig {
@@ -78,10 +82,10 @@ func TestClient_Topic(t *testing.T) {
78
82
},
79
83
}
80
84
81
- top , err := client .CreateTopicWithConfig (context . Background () , "new-test-topic-with-config" , conf )
85
+ top , err := client .CreateTopicWithConfig (ctx , "new-test-topic-with-config" , conf )
82
86
require .NoError (t , err )
83
87
84
- createdConf , err := top .Config (context . Background () )
88
+ createdConf , err := top .Config (ctx )
85
89
require .NoError (t , err )
86
90
assert .Equal (t , conf .Labels , createdConf .Labels )
87
91
assert .Equal (t , conf .MessageStoragePolicy , createdConf .MessageStoragePolicy )
@@ -91,7 +95,7 @@ func TestClient_Topic(t *testing.T) {
91
95
// name cannot be tested because in new versions of pubsub this new name attribute is not replicated to the original conf. only top.Config() has it
92
96
// assert.Equal(t, conf.name, createdConf.name)
93
97
94
- return top .Publish (context . Background () , msg )
98
+ return top .Publish (ctx , msg )
95
99
},
96
100
}
97
101
@@ -106,7 +110,15 @@ func TestClient_Topic(t *testing.T) {
106
110
},
107
111
})
108
112
109
- ctx , cancel := context .WithTimeout (context .Background (), time .Second )
113
+ require .Eventually (t , func () bool {
114
+ return recorder .QueuedSpansCount () == 1
115
+ }, 250 * time .Millisecond , 25 * time .Millisecond )
116
+
117
+ spans := recorder .GetQueuedSpans ()
118
+ require .Len (t , spans , 1 )
119
+ span := spans [0 ]
120
+
121
+ ctx , cancel := context .WithTimeout (ctx , time .Second )
110
122
defer cancel ()
111
123
112
124
msgID , err := res .Get (ctx )
@@ -117,7 +129,10 @@ func TestClient_Topic(t *testing.T) {
117
129
118
130
assert .Equal (t , []byte ("message data" ), msg .Data )
119
131
assert .Equal (t , map [string ]string {
120
- "key1" : "value1" ,
132
+ "x-instana-t" : instana .FormatID (span .TraceID ),
133
+ "x-instana-s" : instana .FormatID (span .SpanID ),
134
+ "x-instana-l" : "1" ,
135
+ "key1" : "value1" ,
121
136
}, msg .Attributes )
122
137
})
123
138
}
0 commit comments