Merged in feature/track-filesize (pull request #200)
track file sizes for all documents in system * feature complete needs dev testing
This commit is contained in:
+96
-72
@@ -1,7 +1,6 @@
|
||||
package endtoend_test
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -29,46 +29,54 @@ func TestProcess(t *testing.T) {
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var clientId queryapi.ClientID
|
||||
var jsonId queryapi.QueryID
|
||||
var textractExpectation test.MockExpectation
|
||||
textractBody := "Hello World"
|
||||
wg.Add(2)
|
||||
go func(t testing.TB) {
|
||||
|
||||
// Use errgroup to properly propagate errors and avoid indefinite hangs
|
||||
// If any goroutine fails, g.Wait() returns the error immediately
|
||||
g := new(errgroup.Group)
|
||||
|
||||
g.Go(func() error {
|
||||
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("setup phase 1 failed: %v", err)
|
||||
}
|
||||
|
||||
wg.Add(3)
|
||||
go func(t testing.TB) {
|
||||
g = new(errgroup.Group)
|
||||
|
||||
g.Go(func() error {
|
||||
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||
t,
|
||||
net.Dependencies.MockServer,
|
||||
textractBody,
|
||||
)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
queryapitest.CreateFile(t, net.Client, queryapitest.File{
|
||||
Filename: "helloworld.pdf",
|
||||
Content: []byte(pdfHelloWorld),
|
||||
ClientID: clientId,
|
||||
})
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("setup phase 2 failed: %v", err)
|
||||
}
|
||||
|
||||
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||
@@ -112,46 +120,52 @@ func TestProcess(t *testing.T) {
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var clientId queryapi.ClientID
|
||||
var jsonId queryapi.QueryID
|
||||
var textractExpectation test.MockExpectation
|
||||
textractBody := "Hello World"
|
||||
wg.Add(2)
|
||||
go func(t testing.TB) {
|
||||
|
||||
g := new(errgroup.Group)
|
||||
|
||||
g.Go(func() error {
|
||||
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("setup phase 1 failed: %v", err)
|
||||
}
|
||||
|
||||
wg.Add(3)
|
||||
go func(t testing.TB) {
|
||||
g = new(errgroup.Group)
|
||||
|
||||
g.Go(func() error {
|
||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
queryapitest.CreateFile(t, net.Client, queryapitest.File{
|
||||
Filename: "helloworld.pdf",
|
||||
Content: []byte(pdfHelloWorld),
|
||||
ClientID: clientId,
|
||||
})
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||
t,
|
||||
net.Dependencies.MockServer,
|
||||
textractBody,
|
||||
)
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("setup phase 2 failed: %v", err)
|
||||
}
|
||||
|
||||
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||
@@ -194,13 +208,14 @@ func TestProcess(t *testing.T) {
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var clientId queryapi.ClientID
|
||||
var jsonId queryapi.QueryID
|
||||
var textractExpectation test.MockExpectation
|
||||
textractBody := "Hello World"
|
||||
wg.Add(2)
|
||||
go func(t testing.TB) {
|
||||
|
||||
g := new(errgroup.Group)
|
||||
|
||||
g.Go(func() error {
|
||||
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||
|
||||
jcfg := `{"path":"keytwo"}`
|
||||
@@ -208,39 +223,43 @@ func TestProcess(t *testing.T) {
|
||||
Config: &jcfg,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("setup phase 1 failed: %v", err)
|
||||
}
|
||||
|
||||
wg.Add(3)
|
||||
go func(t testing.TB) {
|
||||
g = new(errgroup.Group)
|
||||
|
||||
g.Go(func() error {
|
||||
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||
t,
|
||||
net.Dependencies.MockServer,
|
||||
textractBody,
|
||||
)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
return nil
|
||||
})
|
||||
g.Go(func() error {
|
||||
queryapitest.CreateFile(t, net.Client, queryapitest.File{
|
||||
Filename: "helloworld.pdf",
|
||||
Content: []byte(pdfHelloWorld),
|
||||
ClientID: clientId,
|
||||
})
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("setup phase 2 failed: %v", err)
|
||||
}
|
||||
|
||||
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||
@@ -250,28 +269,33 @@ func TestProcess(t *testing.T) {
|
||||
assert.Len(t, *docs.JSON200, 1)
|
||||
doc := (*docs.JSON200)[0]
|
||||
|
||||
wg.Add(2)
|
||||
go func(t testing.TB) {
|
||||
g = new(errgroup.Group)
|
||||
|
||||
// Capture doc.Id to avoid closure issues
|
||||
docId := doc.Id
|
||||
g.Go(func() error {
|
||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||
QueryVersion: 1,
|
||||
DocumentId: doc.Id,
|
||||
DocumentId: docId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "valueone", testRes.JSON200.Value)
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
go func(t testing.TB) {
|
||||
g.Go(func() error {
|
||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||
QueryVersion: 2,
|
||||
DocumentId: doc.Id,
|
||||
DocumentId: docId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
|
||||
wg.Done()
|
||||
}(t)
|
||||
return nil
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatalf("test phase failed: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user