@@ -39,7 +39,7 @@ func Run(c smoothCfg.TesterCommand) {
3939
4040 var wg sync.WaitGroup
4141
42- var ch chan int
42+ ch := make ( chan int )
4343
4444 queueUrl := createQueue (sqsClient )
4545
@@ -71,6 +71,10 @@ func Run(c smoothCfg.TesterCommand) {
7171 pct = float64 (receivedMessages ) / float64 (sentMessages )
7272 }
7373 log .Info ().Msg (fmt .Sprintf ("sent: %d, received: %d, pct: %f" , sentMessages , receivedMessages , pct ))
74+ if (sentMessages > 0 && sentMessages == receivedMessages ) {
75+ close (ch )
76+ return
77+ }
7478 time .Sleep (1 * time .Second )
7579 }
7680 }()
@@ -79,12 +83,15 @@ func Run(c smoothCfg.TesterCommand) {
7983
8084 if c .Senders > 0 {
8185 log .Info ().Msg ("All messages sent" )
82- if c .Receivers == 0 {
83- os .Exit (0 )
84- }
8586 }
8687
8788 <- ch
89+
90+ // Test changing message visibility timeout
91+ queueUrl2 := createQueue (sqsClient )
92+ log .Info ().Msgf ("queue2: %s" , queueUrl )
93+ testChangeMessageVisibility (sqsClient , queueUrl2 )
94+ os .Exit (0 )
8895}
8996
9097func GenerateRandomString (n int ) string {
@@ -166,6 +173,47 @@ func sendMessage(client *sqs.Client, queueUrl string, goroutineID, requestID, ba
166173 // time.Sleep(100 * time.Millisecond)
167174}
168175
176+ func testChangeMessageVisibility (client * sqs.Client , queueUrl string ) {
177+ log .Info ().Msg ("Testing ChangeMessageVisibility" )
178+ // Send a message
179+ messageBody := "Test message for visibility timeout"
180+ sendMessageInput := & sqs.SendMessageInput {
181+ QueueUrl : & queueUrl ,
182+ MessageBody : & messageBody ,
183+ }
184+ sendMessageOutput , err := client .SendMessage (context .TODO (), sendMessageInput )
185+ if err != nil {
186+ log .Fatal ().Msgf ("failed to send message, %v" , err )
187+ }
188+
189+ for {
190+ recvMsg := & sqs.ReceiveMessageInput {
191+ QueueUrl : aws .String (queueUrl ),
192+ MaxNumberOfMessages : 1 ,
193+ }
194+ msgs , err := client .ReceiveMessage (context .TODO (), recvMsg )
195+ if err != nil {
196+ log .Error ().Err (err ).Send ()
197+ }
198+ if len (msgs .Messages ) == 1 {
199+ break
200+ }
201+ }
202+
203+ // Change the visibility timeout
204+ changeVisibilityInput := & sqs.ChangeMessageVisibilityInput {
205+ QueueUrl : & queueUrl ,
206+ ReceiptHandle : sendMessageOutput .MessageId ,
207+ VisibilityTimeout : 60 ,
208+ }
209+ _ , err = client .ChangeMessageVisibility (context .TODO (), changeVisibilityInput )
210+ if err != nil {
211+ log .Fatal ().Msgf ("failed to change message visibility timeout, %v" , err )
212+ }
213+
214+ log .Info ().Msg ("Successfully changed message visibility timeout" )
215+ }
216+
169217func receiveMessage (client * sqs.Client , queueUrl string , goroutineID int ) int {
170218 i := & sqs.ReceiveMessageInput {
171219 QueueUrl : aws .String (queueUrl ),
0 commit comments