File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -634,23 +634,26 @@ func TestPublishRequest_SetAttributesFromForm_success_concurrent(t *testing.T) {
634
634
form .Add ("MessageAttributes.entry.2.Value.DataType" , "Binary" )
635
635
form .Add ("MessageAttributes.entry.2.Value.BinaryValue" , "YmluYXJ5LXZhbHVl" )
636
636
637
- cqr := & PublishRequest {
638
- MessageAttributes : make (map [string ]MessageAttribute ),
639
- }
637
+ // if the code is not thread-safe, repeated runs increase the chance of detecting a race.
640
638
for r := 0 ; r < 10 ; r ++ {
641
639
var wg sync.WaitGroup
642
640
goroutineCount := 40
641
+ // launch goroutines in parallel to simulate concurrent access.
643
642
for g := 0 ; g < goroutineCount ; g ++ {
644
643
wg .Add (1 )
645
644
go func () {
646
645
defer wg .Done ()
647
- // Introduce a random delay to encourage goroutine interleaving
646
+ // introduce a random delay to encourage goroutine interleaving
648
647
time .Sleep (time .Duration (rand .Intn (5 )) * time .Millisecond )
648
+ cqr := & PublishRequest {
649
+ MessageAttributes : make (map [string ]MessageAttribute ),
650
+ }
651
+
649
652
cqr .SetAttributesFromForm (form )
653
+
650
654
// validate the expected DataType values
651
655
assert .Equal (t , "String" , cqr .MessageAttributes ["test1" ].DataType )
652
656
assert .Equal (t , "Binary" , cqr .MessageAttributes ["test2" ].DataType )
653
-
654
657
}()
655
658
}
656
659
wg .Wait ()
You can’t perform that action at this time.
0 commit comments