Skip to content

Commit

Permalink
test(all): run tests with -race (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Feb 21, 2024
1 parent 3e6037a commit 38ede14
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:

- name: test
if: steps.changes.outputs.go == 'true'
run: go test ./... -v -failfast
run: go test ./... -race -v -failfast
63 changes: 32 additions & 31 deletions .run/test all.run.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="test all" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="prisma-client-go"/>
<working_directory value="$PROJECT_DIR$/"/>
<envs>
<env name="PRISMA_CLIENT_GO_LOG" value="info"/>
<env name="PHOTON_GO_LOG" value="info"/>
<env name="LOG_QUERIES" value="y"/>
<env name="DBm" value="mysql://root:pw@localhost:3306/testing"/>
<env name="DB" value="postgresql://postgres:pw@localhost:5432/testing"/>
<env name="PRISMA_CLIENT_GO_WRITE_DMMF_FILE" value="yes"/>
<env name="PRISMA_CLIENT_GO_TEST_DEV" value="true"/>
<env name="PRISMA_CLIENT_GO_TEST_MIGRATE_LOGS" value="true"/>
</envs>
<EXTENSION ID="net.ashald.envfile">
<option name="IS_ENABLED" value="false"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
</ENTRIES>
</EXTENSION>
<kind value="DIRECTORY"/>
<package value="github.com/prisma/photongo"/>
<directory value="$PROJECT_DIR$/"/>
<filePath value="$PROJECT_DIR$/"/>
<framework value="gotest"/>
<pattern value="./..."/>
<method v="2"/>
</configuration>
<configuration default="false" name="test all" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="prisma-client-go" />
<working_directory value="$PROJECT_DIR$/" />
<go_parameters value="-race" />
<envs>
<env name="PRISMA_CLIENT_GO_LOG" value="info" />
<env name="PHOTON_GO_LOG" value="info" />
<env name="LOG_QUERIES" value="y" />
<env name="DBm" value="mysql://root:pw@localhost:3306/testing" />
<env name="DB" value="postgresql://postgres:pw@localhost:5432/testing" />
<env name="PRISMA_CLIENT_GO_WRITE_DMMF_FILE" value="yes" />
<env name="PRISMA_CLIENT_GO_TEST_DEV" value="true" />
<env name="PRISMA_CLIENT_GO_TEST_MIGRATE_LOGS" value="true" />
</envs>
<EXTENSION ID="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
</ENTRIES>
</EXTENSION>
<kind value="DIRECTORY" />
<package value="github.com/prisma/photongo" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<framework value="gotest" />
<pattern value="./..." />
<method v="2" />
</configuration>
</component>
3 changes: 3 additions & 0 deletions engine/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions engine/qe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package engine
import (
"net/http"
"os/exec"
"sync"
)

func NewQueryEngine(schema string, hasBinaryTargets bool, datasources string, datasourceURL string) *QueryEngine {
Expand Down Expand Up @@ -52,6 +53,8 @@ type QueryEngine struct {

// lastEngineError contains the last received error
lastEngineError string

mu sync.Mutex
}

func (e *QueryEngine) Name() string {
Expand Down
2 changes: 2 additions & 0 deletions engine/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (e *QueryEngine) streamStderr(cmd *exec.Cmd, onError chan<- string) error {
for {
select {
case v := <-e.onEngineError:
e.mu.Lock()
e.lastEngineError = v
e.mu.Unlock()
case <-e.closed:
logger.Debug.Printf("query engine closed")
break outer
Expand Down

0 comments on commit 38ede14

Please sign in to comment.