MCPcopy Create free account
hub / github.com/google/go-cloud / BenchmarkGcpPubSub

Function BenchmarkGcpPubSub

pubsub/gcppubsub/gcppubsub_test.go:152–197  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

150}
151
152func BenchmarkGcpPubSub(b *testing.B) {
153 ctx := context.Background()
154 creds, err := gcp.DefaultCredentials(ctx)
155 if err != nil {
156 b.Fatal(err)
157 }
158
159 // Connect.
160 conn, cleanup, err := Dial(ctx, gcp.CredentialsTokenSource(creds))
161 if err != nil {
162 b.Fatal(err)
163 }
164 defer cleanup()
165
166 // Make topic.
167 pc, err := PublisherClient(ctx, conn)
168 if err != nil {
169 b.Fatal(err)
170 }
171 topicName := fmt.Sprintf("%s-topic", b.Name())
172 topicPath := fmt.Sprintf("projects/%s/topics/%s", projectID, topicName)
173 dt, cleanup1, err := createTopic(ctx, pc, topicName, topicPath)
174 if err != nil {
175 b.Fatal(err)
176 }
177 defer cleanup1()
178 topic := pubsub.NewTopic(dt, nil)
179 defer topic.Shutdown(ctx)
180
181 // Make subscription.
182 sc, err := SubscriberClient(ctx, conn)
183 if err != nil {
184 b.Fatal(err)
185 }
186 subName := fmt.Sprintf("%s-subscription", b.Name())
187 subPath := fmt.Sprintf("projects/%s/subscriptions/%s", projectID, subName)
188 ds, cleanup2, err := createSubscription(ctx, sc, dt, subName, subPath)
189 if err != nil {
190 b.Fatal(err)
191 }
192 defer cleanup2()
193 sub := pubsub.NewSubscription(ds, defaultRecvBatcherOpts, ackBatcherOpts)
194 defer sub.Shutdown(ctx)
195
196 drivertest.RunBenchmarks(b, topic, sub)
197}
198
199type gcpAsTest struct{}
200

Callers

nothing calls this directly

Calls 11

ShutdownMethod · 0.95
ShutdownMethod · 0.95
DefaultCredentialsFunction · 0.92
CredentialsTokenSourceFunction · 0.92
RunBenchmarksFunction · 0.92
PublisherClientFunction · 0.85
SubscriberClientFunction · 0.85
DialFunction · 0.70
createTopicFunction · 0.70
createSubscriptionFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected