Merged in feature/testclean (pull request #126)

Bit of test clean up

* fixes
This commit is contained in:
Michael McGuinness
2025-04-29 17:13:09 +00:00
parent d3d89bf1d3
commit af361b4a67
11 changed files with 107 additions and 99 deletions
+40
View File
@@ -1065,3 +1065,43 @@ func createDocumentWithCollectorAndResults(t testing.TB, ctx context.Context, qu
return documentID, cleanId, textId
}
func BenchmarkIsClientSynced(b *testing.B) {
ctx := context.Background()
cfg := &serviceconfig.BaseConfig{}
net := test.DepNetwork.Get(b, ctx)
_ = test.CreateDB(b, ctx, cfg, net, &test.CreateDatabaseConfig{})
queries := cfg.GetDBQueries()
contextQueryID, jsonQueryID := createDependentQueries(b, ctx, queries)
clientId := createClientWithCollector(b, ctx, queries)
_, _, _ = createDocumentWithCollectorAndResults(b, ctx, queries, clientId, contextQueryID, jsonQueryID)
b.ResetTimer()
for b.Loop() {
_, _ = queries.IsClientSynced(ctx, &clientId)
}
}
func BenchmarkGetDocumentExternal(b *testing.B) {
ctx := context.Background()
cfg := &serviceconfig.BaseConfig{}
net := test.DepNetwork.Get(b, ctx)
_ = test.CreateDB(b, ctx, cfg, net, &test.CreateDatabaseConfig{})
queries := cfg.GetDBQueries()
contextQueryID, jsonQueryID := createDependentQueries(b, ctx, queries)
clientId := createClientWithCollector(b, ctx, queries)
documentID, _, _ := createDocumentWithCollectorAndResults(b, ctx, queries, clientId, contextQueryID, jsonQueryID)
b.ResetTimer()
for b.Loop() {
_, _ = queries.GetDocumentExternal(ctx, documentID)
}
}
+1 -1
View File
@@ -76,7 +76,7 @@ func (b *DBConfig) SetDBPool(ctx context.Context) error {
func (b *DBConfig) DBPing(ctx context.Context) error {
timeout := time.After(30 * time.Second)
tick := time.NewTicker(2 * time.Second)
tick := time.NewTicker(500 * time.Millisecond)
defer tick.Stop()
for {
+1 -1
View File
@@ -75,7 +75,7 @@ func (c *ObjectStoreConfig) GetStoreClient() S3Client {
func (c *ObjectStoreConfig) PingStoreByName(ctx context.Context, name string) error {
timeout := time.After(30 * time.Second)
tick := time.NewTicker(2 * time.Second)
tick := time.NewTicker(500 * time.Millisecond)
defer tick.Stop()
input := &s3.HeadBucketInput{
+1 -1
View File
@@ -42,7 +42,7 @@ func (c *QueueConfig) GetSQSEndpoint() string {
func (c *QueueConfig) PingQueueByURL(ctx context.Context, url string) error {
timeout := time.After(30 * time.Second)
tick := time.NewTicker(2 * time.Second)
tick := time.NewTicker(500 * time.Millisecond)
defer tick.Stop()
input := &sqs.GetQueueAttributesInput{
+3 -2
View File
@@ -310,12 +310,13 @@ func WaitForMockEndpoint(t testing.TB, server MockServer, request MockRequest) M
verifyURL := fmt.Sprintf("%s/mockserver/verify", server.External)
clientTimeout := 500 * time.Millisecond
client := &http.Client{
Timeout: 5 * time.Second,
Timeout: clientTimeout,
}
timeout := time.After(60 * time.Second)
ticker := time.NewTicker(500 * time.Millisecond)
ticker := time.NewTicker(clientTimeout)
defer ticker.Stop()
slog.Info("Attempting to process request", "body", jsonData)
-90
View File
@@ -8,100 +8,10 @@ import (
"strings"
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/aws"
"queryorchestration/internal/serviceconfig/objectstore"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateAPINetwork(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
cfg := &FullDepsConfig{}
conn, cleanup := CreateAPINetwork(t, ctx, cfg, QueryAPI)
assert.NotNil(t, conn)
assert.NotNil(t, cleanup)
cleanup()
}
type FullDepsConfig struct {
aws.AWSConfig
serviceconfig.BaseConfig
objectstore.ObjectStoreConfig
}
func TestCreateFullDependencies(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
cfg := &FullDepsConfig{}
conn, cleanup := CreateFullDependencies(t, ctx, cfg)
assert.NotNil(t, conn)
assert.NotNil(t, cleanup)
cleanup()
}
func TestCreateFullNetwork(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
cfg := &FullDepsConfig{}
conn, cleanup := CreateFullNetwork(t, ctx, cfg)
assert.NotNil(t, conn)
assert.NotNil(t, cleanup)
cleanup()
}
func TestCreateMockServer(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
net := DepNetwork.Get(t, ctx)
server, cleanup := CreateMockServer(t, ctx, net)
assert.NotNil(t, server)
assert.NotNil(t, cleanup)
cleanup()
}
func TestCreateMockExpectation(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
defer ts.Close()
server := MockServer{
Client: ts.Client(),
External: Address(ts.URL),
}
expectation := MockExpectation{}
CreateMockExpectation(t, server, expectation)
}
func TestCreateDetectDocumentTextExpectation(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
+1 -1
View File
@@ -68,7 +68,7 @@ func CreateQueue(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProv
func AssertMessage(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvider, params *queue.ReceiveParams) types.Message {
t.Helper()
timeout := time.After(30 * time.Second)
tick := time.NewTicker(2 * time.Second)
tick := time.NewTicker(500 * time.Millisecond)
defer tick.Stop()
for {