Skip to content

Commit

Permalink
cmd/smoothmq/tester: Create a new queue for each test run
Browse files Browse the repository at this point in the history
  • Loading branch information
sundbry committed Sep 21, 2024
1 parent 66f8eda commit 5f7a517
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cmd/smoothmq/tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
func Run(c smoothCfg.TesterCommand) {
var sentMessages, receivedMessages int

queueUrl := "https://sqs.us-east-1.amazonaws.com/123/test-queue"

// Load the AWS configuration with hardcoded credentials
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-east-1"),
Expand All @@ -43,6 +41,8 @@ func Run(c smoothCfg.TesterCommand) {

var ch chan int

queueUrl := createQueue(sqsClient)

for i := 0; i < c.Senders; i++ {
wg.Add(1)
go func(id int) {
Expand Down Expand Up @@ -96,6 +96,18 @@ func GenerateRandomString(n int) string {
return string(b)
}

func createQueue(client *sqs.Client) string {
queueName := fmt.Sprintf("test-queue-%d", rand.Int())
i := &sqs.CreateQueueInput{
QueueName: &queueName,
}
result, err := client.CreateQueue(context.TODO(), i)
if err != nil {
log.Error().Err(err).Send()
}
return *result.QueueUrl
}

func sendMessage(client *sqs.Client, queueUrl string, goroutineID, requestID, batchSize, delaySeconds int) {

if batchSize > 1 {
Expand Down

0 comments on commit 5f7a517

Please sign in to comment.