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

Function TestMultipleAcksCanGoIntoASingleBatch

pubsub/acks_test.go:88–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestMultipleAcksCanGoIntoASingleBatch(t *testing.T) {
89 ctx := context.Background()
90 var wg sync.WaitGroup
91 var mu sync.Mutex
92 sentAcks := make(map[driver.AckID]int)
93 ids := []int{1, 2}
94 ds := &ackingDriverSub{
95 q: []*driver.Message{{AckID: ids[0]}, {AckID: ids[1]}},
96 sendAcks: func(_ context.Context, ackIDs []driver.AckID) error {
97 mu.Lock()
98 defer mu.Unlock()
99 for _, id := range ackIDs {
100 sentAcks[id]++
101 wg.Done()
102 }
103 return nil
104 },
105 }
106 sub := pubsub.NewSubscription(ds, nil, nil)
107 defer sub.Shutdown(ctx)
108
109 // Receive and ack the messages concurrently.
110 for range 2 {
111 wg.Add(1)
112 go func() {
113 mr, err := sub.Receive(ctx)
114 if err != nil {
115 t.Error(err)
116 return
117 }
118 mr.Ack()
119 }()
120 }
121 wg.Wait()
122
123 if len(sentAcks) != 2 {
124 t.Errorf("len(sentAcks) = %d, want exactly 2", len(sentAcks))
125 }
126 for _, id := range ids {
127 if sentAcks[id] != 1 {
128 t.Errorf("sentAcks[%v] = %d, want 1", id, sentAcks[id])
129 }
130 }
131}
132
133func TestTooManyAcksForASingleBatchGoIntoMultipleBatches(t *testing.T) {
134 ctx := context.Background()

Callers

nothing calls this directly

Calls 7

ShutdownMethod · 0.95
ReceiveMethod · 0.95
DoneMethod · 0.80
WaitMethod · 0.80
AckMethod · 0.65
AddMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected