@@ -10,11 +10,12 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
- "github.com/form3tech-oss/pact-proxy/internal/app/configuration"
14
- "github.com/form3tech-oss/pact-proxy/pkg/pactproxy"
15
13
"github.com/pact-foundation/pact-go/dsl"
16
14
log "github.com/sirupsen/logrus"
17
15
"github.com/stretchr/testify/assert"
16
+
17
+ "github.com/form3tech-oss/pact-proxy/internal/app/configuration"
18
+ "github.com/form3tech-oss/pact-proxy/pkg/pactproxy"
18
19
)
19
20
20
21
const (
@@ -256,6 +257,26 @@ func (s *ConcurrentProxyStage) the_second_user_response_should_have_the_right_st
256
257
return s
257
258
}
258
259
260
+ func (s * ConcurrentProxyStage ) all_responses_should_have_the_expected_return_values () * ConcurrentProxyStage {
261
+ statuses := make (map [int ]int )
262
+ bodies := make (map [string ]int )
263
+ for _ , res := range s .userResponses {
264
+ statuses [res .StatusCode ] += 1
265
+ bd , err := io .ReadAll (res .Body )
266
+ s .assert .NoError (err )
267
+ res .Body .Close ()
268
+ bodies [strings .ReplaceAll (strings .TrimSpace (string (bd )), "\" " , "" )] += 1
269
+ }
270
+ s .assert .Len (statuses , 3 )
271
+ s .assert .Len (bodies , 2 )
272
+ s .assert .Equal (1 , statuses [http .StatusInternalServerError ])
273
+ s .assert .Equal (1 , statuses [http .StatusOK ])
274
+ s .assert .Equal (1 , statuses [http .StatusTeapot ])
275
+ s .assert .Equal (2 , bodies ["{name:any}" ])
276
+ s .assert .Equal (1 , bodies ["{name:Form3}" ])
277
+ return s
278
+ }
279
+
259
280
func (s * ConcurrentProxyStage ) all_the_address_responses_should_have_the_right_status_code () * ConcurrentProxyStage {
260
281
expectedLen := s .concurrentAddressRequestsPerSecond * int (s .concurrentAddressRequestsDuration / time .Second )
261
282
s .assert .Len (s .addressResponses , expectedLen , "number of address responses is not as expected" )
@@ -280,3 +301,40 @@ func (s *ConcurrentProxyStage) the_proxy_waits_for_all_address_responses() *Conc
280
301
281
302
return s
282
303
}
304
+
305
+ func (s * ConcurrentProxyStage ) the_concurrent_requests_are_sent_with_multiple_modifiers_for_same_interaction () {
306
+ err := s .pact .Verify (func () (err error ) {
307
+ attempt := 1
308
+ s .proxy .ForInteraction (postNamePactWithAnyName ).AddModifier ("$.status" , fmt .Sprintf ("%d" , http .StatusTeapot ), & attempt )
309
+ attempt = 2
310
+ s .proxy .ForInteraction (postNamePactWithAnyName ).AddModifier ("$.status" , fmt .Sprintf ("%d" , http .StatusInternalServerError ), & attempt )
311
+ attempt = 3
312
+ s .proxy .ForInteraction (postNamePactWithAnyName ).AddModifier ("$.body.name" , "Form3" , & attempt )
313
+
314
+ wg := sync.WaitGroup {}
315
+
316
+ wg .Add (1 )
317
+ go func () {
318
+ defer wg .Done ()
319
+ s .makeUserRequest ()
320
+ }()
321
+
322
+ wg .Add (1 )
323
+ go func () {
324
+ defer wg .Done ()
325
+ s .makeUserRequest ()
326
+ }()
327
+
328
+ wg .Add (1 )
329
+ go func () {
330
+ defer wg .Done ()
331
+ s .makeUserRequest ()
332
+ }()
333
+
334
+ wg .Wait ()
335
+
336
+ return nil
337
+ })
338
+
339
+ s .assert .NoError (err )
340
+ }
0 commit comments