@@ -3,8 +3,11 @@ package models
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "math/rand"
6
7
"net/url"
8
+ "sync"
7
9
"testing"
10
+ "time"
8
11
9
12
"github.com/stretchr/testify/assert"
10
13
)
@@ -621,3 +624,35 @@ func Test_DeleteMessageBatchRequest_SetAttributesFromForm_stops_at_invalid_keys(
621
624
assert .Equal (t , "message-id-1" , dmbr .Entries [0 ].Id )
622
625
assert .Equal (t , "receipt-handle-1" , dmbr .Entries [0 ].ReceiptHandle )
623
626
}
627
+
628
+ func TestPublishRequest_SetAttributesFromForm_success_concurrent (t * testing.T ) {
629
+ form := url.Values {}
630
+ form .Add ("MessageAttributes.entry.1.Name" , "test1" )
631
+ form .Add ("MessageAttributes.entry.1.Value.DataType" , "String" )
632
+ form .Add ("MessageAttributes.entry.1.Value.StringValue" , "sample-string" )
633
+ form .Add ("MessageAttributes.entry.2.Name" , "test2" )
634
+ form .Add ("MessageAttributes.entry.2.Value.DataType" , "Binary" )
635
+ form .Add ("MessageAttributes.entry.2.Value.BinaryValue" , "YmluYXJ5LXZhbHVl" )
636
+
637
+ cqr := & PublishRequest {
638
+ MessageAttributes : make (map [string ]MessageAttribute ),
639
+ }
640
+ for r := 0 ; r < 10 ; r ++ {
641
+ var wg sync.WaitGroup
642
+ goroutineCount := 40
643
+ for g := 0 ; g < goroutineCount ; g ++ {
644
+ wg .Add (1 )
645
+ go func () {
646
+ defer wg .Done ()
647
+ // Introduce a random delay to encourage goroutine interleaving
648
+ time .Sleep (time .Duration (rand .Intn (5 )) * time .Millisecond )
649
+ cqr .SetAttributesFromForm (form )
650
+ // validate the expected DataType values
651
+ assert .Equal (t , "String" , cqr .MessageAttributes ["test1" ].DataType )
652
+ assert .Equal (t , "Binary" , cqr .MessageAttributes ["test2" ].DataType )
653
+
654
+ }()
655
+ }
656
+ wg .Wait ()
657
+ }
658
+ }
0 commit comments