github.com/SaurabhDubey-Groww/go-cloud@v0.0.0-20221124105541-b26c29285fd8/pubsub/mempubsub/conformance_test.go (about)

     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  	return &harness{}, nil
    30  }
    31  
    32  func (h *harness) CreateTopic(ctx context.Context, testName string) (dt driver.Topic, cleanup func(), err error) {
    33  	cleanup = func() {}
    34  	return &topic{}, cleanup, nil
    35  }
    36  
    37  func (h *harness) MakeNonexistentTopic(ctx context.Context) (driver.Topic, error) {
    38  	// A nil *topic behaves like a nonexistent topic.
    39  	return (*topic)(nil), nil
    40  }
    41  
    42  func (h *harness) CreateSubscription(ctx context.Context, dt driver.Topic, testName string) (ds driver.Subscription, cleanup func(), err error) {
    43  	ds = newSubscription(dt.(*topic), time.Second)
    44  	cleanup = func() {}
    45  	return ds, cleanup, nil
    46  }
    47  
    48  func (h *harness) MakeNonexistentSubscription(ctx context.Context) (driver.Subscription, func(), error) {
    49  	return newSubscription(nil, time.Second), func() {}, nil
    50  }
    51  
    52  func (h *harness) Close() {}
    53  
    54  func (h *harness) MaxBatchSizes() (int, int) { return 0, 0 }
    55  
    56  func (*harness) SupportsMultipleSubscriptions() bool { return true }
    57  
    58  func TestConformance(t *testing.T) {
    59  	drivertest.RunConformanceTests(t, newHarness, nil)
    60  }
    61  
    62  func BenchmarkMemPubSub(b *testing.B) {
    63  	ctx := context.Background()
    64  	topic := NewTopic()
    65  	defer topic.Shutdown(ctx)
    66  	sub := NewSubscription(topic, time.Second)
    67  	defer sub.Shutdown(ctx)
    68  
    69  	drivertest.RunBenchmarks(b, topic, sub)
    70  }