2025-01-10 11:12:03 +00:00
|
|
|
package queue_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-01-17 12:00:32 +00:00
|
|
|
"queryorchestration/internal/server/queue"
|
2025-01-10 19:17:20 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-01-10 11:12:03 +00:00
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MockController struct{}
|
|
|
|
|
|
|
|
|
|
func (s MockController) Process(ctx context.Context, config *queue.Config, msg *types.Message) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPollMessages(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
ctx := context.Background()
|
2025-01-10 19:17:20 +00:00
|
|
|
queueConfig, cleanup := test.CreateQueue(t, ctx, &test.CreateQueueConfig{})
|
2025-01-10 11:12:03 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
controller := MockController{}
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
2025-01-10 19:17:20 +00:00
|
|
|
cfg := &queue.Config{
|
|
|
|
|
URL: queueConfig.URL,
|
|
|
|
|
Client: queueConfig.Client,
|
|
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
queue.PollMessages(ctx, &queue.PollConfig{
|
2025-01-10 19:17:20 +00:00
|
|
|
Config: cfg,
|
2025-01-10 11:12:03 +00:00
|
|
|
Controller: controller,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPollMessage(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
ctx := context.Background()
|
2025-01-10 19:17:20 +00:00
|
|
|
queueConfig, cleanup := test.CreateQueue(t, ctx, &test.CreateQueueConfig{})
|
2025-01-10 11:12:03 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
controller := MockController{}
|
|
|
|
|
|
2025-01-10 19:17:20 +00:00
|
|
|
cfg := &queue.Config{
|
|
|
|
|
URL: queueConfig.URL,
|
|
|
|
|
Client: queueConfig.Client,
|
|
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
err := queue.PollMessage(ctx, &queue.PollConfig{
|
2025-01-10 19:17:20 +00:00
|
|
|
Config: cfg,
|
2025-01-10 11:12:03 +00:00
|
|
|
Controller: controller,
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
}
|