Skip to content

Commit

Permalink
chore: report file location of the integration test that failed (#2834)
Browse files Browse the repository at this point in the history
By adding a bunch of t.Helper() calls.

Before:

```
=== NAME  TestLeaseFailure/go
    /Users/alec/dev/ftl/internal/integration/harness.go:267: Timed out waiting for assertion to pass: Expected values to be equal:
        -error
        +executing
```

After:

```
=== NAME  TestLeaseFailure/go
    /Users/alec/dev/ftl/backend/controller/pubsub/integration_test.go:178: Timed out waiting for assertion to pass: Expected values to be equal:
        -error
        +executing
--- FAIL: TestLeaseFailure (22.26s)
    --- FAIL: TestLeaseFailure/go (18.18s)

```
  • Loading branch information
alecthomas authored Sep 26, 2024
1 parent efddff9 commit 83a26fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ integration-tests *test:
#!/bin/bash
set -euo pipefail
testName=${1:-}
for i in {1..3}; do go test -fullpath -count 1 -v -tags integration -run "$testName" -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l "$testName" | xargs grep -l '//go:build integration' | xargs -I {} dirname './{}') && break; done
for i in {1..3}; do go test -fullpath -count 1 -v -tags integration -run "$testName" -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l "$testName" | xargs grep -l '//go:build integration' | xargs -I {} dirname './{}') && break || true; done

# Run integration test(s)
infrastructure-tests *test:
#!/bin/bash
set -euo pipefail
testName=${1:-}
for i in {1..3}; do go test -fullpath -count 1 -v -tags infrastructure -run "$testName" -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l "$testName" | xargs grep -l '//go:build infrastructure' | xargs -I {} dirname './{}') && break; done
for i in {1..3}; do go test -fullpath -count 1 -v -tags infrastructure -run "$testName" -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l "$testName" | xargs grep -l '//go:build infrastructure' | xargs -I {} dirname './{}') && break || true; done

# Run README doc tests
test-readme *args:
Expand Down
3 changes: 2 additions & 1 deletion backend/controller/pubsub/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestExternalPublishRuntimeCheck(t *testing.T) {
}

func TestLeaseFailure(t *testing.T) {
t.Skip()
logFilePath := filepath.Join(t.TempDir(), "pubsub.log")
t.Setenv("FSM_LOG_FILE", logFilePath)

Expand All @@ -192,7 +193,7 @@ func TestLeaseFailure(t *testing.T) {
)
RETURNING *
)
SELECT COUNT(*) FROM deleted_rows;
SELECT COUNT(*) FROM deleted_rows;
`, 1),

in.Sleep(time.Second*7),
Expand Down
5 changes: 5 additions & 0 deletions internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ type options struct {

// Run an integration test.
func Run(t *testing.T, actionsOrOptions ...ActionOrOption) {
t.Helper()
run(t, actionsOrOptions...)
}

func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
t.Helper()
opts := options{
startController: true,
languages: []string{"go"},
Expand Down Expand Up @@ -215,6 +217,7 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
for _, language := range opts.languages {
ctx, done := context.WithCancel(ctx)
t.Run(language, func(t *testing.T) {
t.Helper()
tmpDir := initWorkDir(t, cwd, opts)

verbs := rpc.Dial(ftlv1connect.NewVerbServiceClient, "http://localhost:8892", log.Debug)
Expand Down Expand Up @@ -330,6 +333,7 @@ func (i TestContext) WorkingDir() string { return i.workDir }

// AssertWithRetry asserts that the given action passes within the timeout.
func (i TestContext) AssertWithRetry(t testing.TB, assertion Action) {
t.Helper()
waitCtx, done := context.WithTimeout(i, i.integrationTestTimeout())
defer done()
for {
Expand All @@ -348,6 +352,7 @@ func (i TestContext) AssertWithRetry(t testing.TB, assertion Action) {

// Run an assertion, wrapping testing.TB in an implementation that panics on failure, propagating the error.
func (i TestContext) runAssertionOnce(t testing.TB, assertion Action) (err error) {
t.Helper()
defer func() {
switch r := recover().(type) {
case TestingError:
Expand Down

0 comments on commit 83a26fd

Please sign in to comment.