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

Function TestSendReceive

pubsub/pubsub_test.go:110–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108func (*driverSub) Close() error { return nil }
109
110func TestSendReceive(t *testing.T) {
111 ctx := context.Background()
112 ds := NewDriverSub()
113 dt := &driverTopic{
114 subs: []*driverSub{ds},
115 }
116 topic := NewTopic(dt, nil)
117 defer topic.Shutdown(ctx)
118 m := &Message{LoggableID: "foo", Body: []byte("user signed up")}
119 if err := topic.Send(ctx, m); err == nil {
120 t.Fatalf("expected a Send with a non-empty LoggableID to fail")
121 }
122 m.LoggableID = ""
123 if err := topic.Send(ctx, m); err != nil {
124 t.Fatal(err)
125 }
126
127 sub := NewSubscription(ds, nil, nil)
128 defer sub.Shutdown(ctx)
129 m2, err := sub.Receive(ctx)
130 if err != nil {
131 t.Fatal(err)
132 }
133 if string(m2.Body) != string(m.Body) {
134 t.Fatalf("received message has body %q, want %q", m2.Body, m.Body)
135 }
136 m2.Ack()
137}
138
139func TestConcurrentReceivesGetAllTheMessages(t *testing.T) {
140 howManyToSend := int(1e3)

Callers

nothing calls this directly

Calls 8

ShutdownMethod · 0.95
SendMethod · 0.95
ShutdownMethod · 0.95
ReceiveMethod · 0.95
NewDriverSubFunction · 0.85
NewTopicFunction · 0.85
NewSubscriptionFunction · 0.85
AckMethod · 0.65

Tested by

no test coverage detected