@@ -75,7 +75,7 @@ var _ = Describe("E2E", Serial, Label("e2e"), func() {
75
75
for {
76
76
select {
77
77
case <- ctx .Done ():
78
- Fail (fmt .Sprintf ("context timed out: expected to receive 1_000_000 confirmations: received %d" , len (confirmedIds )))
78
+ Fail (fmt .Sprintf ("context timed out: expected to receive 100_000 confirmations: received %d" , len (confirmedIds )))
79
79
case confirm , ok := <- c :
80
80
if ! ok {
81
81
return
@@ -113,7 +113,98 @@ var _ = Describe("E2E", Serial, Label("e2e"), func() {
113
113
114
114
By ("closing the connection" )
115
115
Expect (streamClient .Close (itCtx )).To (Succeed ())
116
+
116
117
}, SpecTimeout (120 * time .Second ))
118
+
119
+ // Send and Recveive Messages, assert messages received are valid.
120
+ It ("sends, and receives messages" , Label ("behaviour" ), func (ctx SpecContext ) {
121
+ h := slog.HandlerOptions {Level : slog .LevelDebug }.NewTextHandler (GinkgoWriter )
122
+ debugLogger := slog .New (h )
123
+ itCtx := raw .NewContextWithLogger (ctx , * debugLogger )
124
+ streamClientConfiguration , err := raw .NewClientConfiguration ("rabbitmq-stream://guest:guest@localhost/%2F" )
125
+ Expect (err ).ToNot (HaveOccurred ())
126
+
127
+ By ("preparing the environment" )
128
+ streamClient , err := raw .DialConfig (itCtx , streamClientConfiguration )
129
+ Expect (err ).ToNot (HaveOccurred ())
130
+
131
+ const stream = "e2e-consume-test"
132
+ // Ensure we don't leak open connection on test failures
133
+ DeferCleanup (func (ctx SpecContext ) error {
134
+ if streamClient .IsOpen () {
135
+ _ = streamClient .DeleteStream (ctx , stream )
136
+ return streamClient .Close (ctx )
137
+ }
138
+ return nil
139
+ })
140
+
141
+ Expect (streamClient .IsOpen ()).To (BeTrue (), "expected stream client to be open" )
142
+ Expect (streamClient .ExchangeCommandVersions (ctx )).To (Succeed ())
143
+
144
+ Expect (streamClient .DeclareStream (itCtx , stream , constants.StreamConfiguration {})).To (Succeed ())
145
+
146
+ const publisherId = 2
147
+ Expect (
148
+ streamClient .DeclarePublisher (itCtx , publisherId , "e2e-send-and-receive" , stream ),
149
+ ).To (Succeed ())
150
+
151
+ c := streamClient .NotifyPublish (make (chan * raw.PublishConfirm , 100 ))
152
+
153
+ const numMessages = 100
154
+ for i := 0 ; i < numMessages ; i ++ {
155
+ Expect (
156
+ streamClient .Send (itCtx , publisherId , wrap [common.PublishingMessager ](raw .NewPublishingMessage (uint64 (i ), & plainTextMessage {messageBody }))),
157
+ ).To (Succeed ())
158
+ }
159
+
160
+ var countOfPublishingIds int
161
+ for confirm := range c {
162
+ Expect (confirm .PublisherID ()).To (BeNumerically ("==" , publisherId ))
163
+ countOfPublishingIds += len (confirm .PublishingIds ())
164
+ if countOfPublishingIds >= numMessages {
165
+ break
166
+ }
167
+ }
168
+
169
+ // Assert number of PublishConfirms matches the number of messages sent
170
+ Expect (countOfPublishingIds ).To (Equal (numMessages ))
171
+
172
+ By ("receiving the expected number of messages" )
173
+ chunks := streamClient .NotifyChunk (make (chan * raw.Chunk , 10 ))
174
+ var subscriptionId uint8 = 2
175
+ Expect (
176
+ streamClient .Subscribe (itCtx , stream , constants .OffsetTypeFirst , subscriptionId , 10 , nil , 0 ),
177
+ ).To (Succeed ())
178
+
179
+ var numOfEntries uint16 = 0
180
+ for chunk := range chunks {
181
+ numOfEntries += chunk .NumEntries
182
+ debugLogger .Info ("chunk received" , "chunk" , chunk )
183
+
184
+ m := & plainTextMessage {}
185
+ for i := uint16 (0 ); i < chunk .NumEntries ; i ++ {
186
+ x , z := i * 104 , (i + 1 )* 104
187
+ Expect (m .UnmarshalBinary (chunk .Messages [x :z ])).To (Succeed ())
188
+ Expect (m .body ).To (Equal (messageBody ))
189
+ }
190
+
191
+ if numOfEntries >= numMessages {
192
+ break
193
+ }
194
+
195
+ Expect (streamClient .Credit (ctx , subscriptionId , 10 )).To (Succeed ())
196
+ }
197
+
198
+ By ("unsubscribing" )
199
+ Expect (streamClient .Unsubscribe (ctx , subscriptionId )).To (Succeed ())
200
+ //Expect(chunks).To(BeClosed())
201
+
202
+ By ("cleaning up" )
203
+ Expect (streamClient .DeletePublisher (ctx , publisherId )).To (Succeed ())
204
+ Expect (streamClient .DeleteStream (itCtx , stream )).To (Succeed ())
205
+ Expect (streamClient .Close (itCtx )).To (Succeed ())
206
+ }, SpecTimeout (15 * time .Second ))
207
+
117
208
})
118
209
119
210
func wrap [T any ](v T ) []T {
0 commit comments