From af753c7bf8d842e1e29350bca2078b119e761858 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Feb 2024 13:07:56 +0700 Subject: [PATCH 1/3] test(all): run tests with -race --- .github/workflows/e2e-test.yml | 2 +- .github/workflows/test.yml | 2 +- .run/test all.run.xml | 63 +++++++++++++++++----------------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 89b80dc00..9f8b6d798 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -46,7 +46,7 @@ jobs: if: steps.changes.outputs.go == 'true' run: | cd test/e2e/ - go test ./... -run '^TestE2E.*$' -tags e2e -v + go test ./... -run '^TestE2E.*$' -tags e2e -race -v env: # DATA_PROXY_DATABASE_URL: ${{ secrets.DATA_PROXY_DATABASE_URL }} PRISMA_CLIENT_GO_LOG: info diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f7d7c710..4839e22bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,4 +41,4 @@ jobs: - name: test if: steps.changes.outputs.go == 'true' - run: go test ./... -v -failfast + run: go test ./... -race -v -failfast diff --git a/.run/test all.run.xml b/.run/test all.run.xml index 70c8da84a..e7adfa394 100644 --- a/.run/test all.run.xml +++ b/.run/test all.run.xml @@ -1,33 +1,34 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + From c57fe9c2dcbd1785eef50309b8b62bd9a259dba3 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Feb 2024 16:17:10 +0700 Subject: [PATCH 2/3] testing --- engine/stream.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engine/stream.go b/engine/stream.go index 6a58f3e05..5c1031738 100644 --- a/engine/stream.go +++ b/engine/stream.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "os/exec" + "sync" "github.com/steebchen/prisma-client-go/logger" ) @@ -21,12 +22,16 @@ func (e *QueryEngine) streamStderr(cmd *exec.Cmd, onError chan<- string) error { return fmt.Errorf("get stderr pipe: %w", err) } + mu := &sync.Mutex{} + go func() { outer: for { select { case v := <-e.onEngineError: + mu.Lock() e.lastEngineError = v + mu.Unlock() case <-e.closed: logger.Debug.Printf("query engine closed") break outer From d836f66d82453f21aae0a5edfc7882c4ad6eae61 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Feb 2024 16:28:09 +0700 Subject: [PATCH 3/3] testing --- engine/lifecycle.go | 3 +++ engine/qe.go | 3 +++ engine/stream.go | 7 ++----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/lifecycle.go b/engine/lifecycle.go index 013ac7b88..eeb1a8f36 100644 --- a/engine/lifecycle.go +++ b/engine/lifecycle.go @@ -286,10 +286,13 @@ func (e *QueryEngine) spawn(file string) error { // send a basic readiness healthcheck and retry if unsuccessful var connectErr error for i := 0; i < 100; i++ { + e.mu.Lock() // return an error early if an engine error already happened if e.lastEngineError != "" { + e.mu.Unlock() return fmt.Errorf("query engine errored: %w", fmt.Errorf(e.lastEngineError)) } + e.mu.Unlock() body, err := e.Request(context.Background(), "GET", "/status", map[string]interface{}{}, false) if err != nil { diff --git a/engine/qe.go b/engine/qe.go index b8259d14f..2f4eae13f 100644 --- a/engine/qe.go +++ b/engine/qe.go @@ -3,6 +3,7 @@ package engine import ( "net/http" "os/exec" + "sync" ) func NewQueryEngine(schema string, hasBinaryTargets bool, datasources string, datasourceURL string) *QueryEngine { @@ -52,6 +53,8 @@ type QueryEngine struct { // lastEngineError contains the last received error lastEngineError string + + mu sync.Mutex } func (e *QueryEngine) Name() string { diff --git a/engine/stream.go b/engine/stream.go index 5c1031738..1721f41f5 100644 --- a/engine/stream.go +++ b/engine/stream.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "os/exec" - "sync" "github.com/steebchen/prisma-client-go/logger" ) @@ -22,16 +21,14 @@ func (e *QueryEngine) streamStderr(cmd *exec.Cmd, onError chan<- string) error { return fmt.Errorf("get stderr pipe: %w", err) } - mu := &sync.Mutex{} - go func() { outer: for { select { case v := <-e.onEngineError: - mu.Lock() + e.mu.Lock() e.lastEngineError = v - mu.Unlock() + e.mu.Unlock() case <-e.closed: logger.Debug.Printf("query engine closed") break outer