Debian Codegraph @

pubsub/mempubsub/conformance_test.go

raw
1 // Copyright 2018 The Go Cloud Development Kit Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package mempubsub
16
17 import (
18 "context"
19 "testing"
20 "time"
21
22 "gocloud.dev/pubsub/driver"
23 "gocloud.dev/pubsub/drivertest"
24 )
25
26 type harness struct{}
27
28 func newHarness(ctx context.Context, t *testing.T) (drivertest.Harness, error) {
29 t.Helper()
30
31 return &harness{}, nil
32 }
33
34 func (h *harness) CreateTopic(ctx context.Context, testName string) (dt driver.Topic, cleanup func(), err error) {
35 cleanup = func() {}
36 return &topic{}, cleanup, nil
37 }
38
39 func (h *harness) MakeNonexistentTopic(ctx context.Context) (driver.Topic, error) {
40 // A nil *topic behaves like a nonexistent topic.
41 return (*topic)(nil), nil
42 }
43
44 func (h *harness) CreateSubscription(ctx context.Context, dt driver.Topic, testName string) (ds driver.Subscription, cleanup func(), err error) {
45 ds = newSubscription(dt.(*topic), time.Second)
46 cleanup = func() {}
47 return ds, cleanup, nil
48 }
49
50 func (h *harness) MakeNonexistentSubscription(ctx context.Context) (driver.Subscription, func(), error) {
51 return newSubscription(nil, time.Second), func() {}, nil
52 }
53
54 func (h *harness) Close() {}
55
56 func (h *harness) MaxBatchSizes() (int, int) { return 0, 0 }
57
58 func (*harness) SupportsMultipleSubscriptions() bool { return true }
59
60 func TestConformance(t *testing.T) {
61 drivertest.RunConformanceTests(t, newHarness, nil)
62 }
63
64 func BenchmarkMemPubSub(b *testing.B) {
65 ctx := context.Background()
66 topic := NewTopic()
67 defer topic.Shutdown(ctx)
68 sub := NewSubscription(topic, time.Second)
69 defer sub.Shutdown(ctx)
70
71 drivertest.RunBenchmarks(b, topic, sub)
72 }