(b *testing.B)
| 150 | } |
| 151 | |
| 152 | func 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 | |
| 199 | type gcpAsTest struct{} |
| 200 |
nothing calls this directly
no test coverage detected