Skip to content

Commit

Permalink
fix(integration): create a new test dir per language
Browse files Browse the repository at this point in the history
Fixes #2412
  • Loading branch information
alecthomas committed Aug 17, 2024
1 parent a7bc9b3 commit 8c04531
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: docker compose up -d --wait
- name: Test
run: |
go-test-annotate ${{ (github.event_name == 'pull_request' && github.event.action != 'enqueued') && '-short' || '' }}
go-test-annotate ${{ (github.event_name == 'pull_request' && github.event.action != 'enqueued' && !contains( github.event.pull_request.labels.*.name, 'run-all')) && '-short' || '' }}
test-readme:
name: Test README
runs-on: ubuntu-latest
Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
run: just build-extension
build-all:
name: Rebuild All
if: github.event_name != 'pull_request' || github.event.action == 'enqueued'
if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -188,7 +188,7 @@ jobs:
- run: cd docs && zola build
integration-shard:
name: Shard Integration Tests
if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-integration')
if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.extract-tests.outputs.matrix }}
Expand All @@ -204,7 +204,7 @@ jobs:
echo "matrix={\"test\":$(jq -c -n '$ARGS.positional' --args $(git grep -l '^//go:build integration' | xargs grep '^func Test' | awk '{print $2}' | cut -d'(' -f1))}" >> "$GITHUB_OUTPUT"
integration-run:
name: Integration Test
if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-integration')
if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
needs: integration-shard
runs-on: ubuntu-latest
strategy:
Expand Down
57 changes: 31 additions & 26 deletions internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,38 +138,12 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
t.Setenv(key, value)
}

tmpDir := t.TempDir()

cwd, err := os.Getwd()
assert.NoError(t, err)

rootDir, ok := internal.GitRoot("").Get()
assert.True(t, ok)

if opts.ftlConfigPath != "" {
// TODO: We shouldn't be copying the shared config from the "go" testdata...
opts.ftlConfigPath = filepath.Join(cwd, "testdata", "go", opts.ftlConfigPath)
projectPath := filepath.Join(tmpDir, "ftl-project.toml")

// Copy the specified FTL config to the temporary directory.
err = copy.Copy(opts.ftlConfigPath, projectPath)
if err == nil {
t.Setenv("FTL_CONFIG", projectPath)
} else {
// Use a path into the testdata directory instead of one relative to
// tmpDir. Otherwise we have a chicken and egg situation where the config
// can't be loaded until the module is copied over, and the config itself
// is used by FTL during startup.
// Some tests still rely on this behavior, so we can't remove it entirely.
t.Logf("Failed to copy %s to %s: %s", opts.ftlConfigPath, projectPath, err)
t.Setenv("FTL_CONFIG", opts.ftlConfigPath)
}

} else {
err = os.WriteFile(filepath.Join(tmpDir, "ftl-project.toml"), []byte(`name = "integration"`), 0644)
assert.NoError(t, err)
}

// Build FTL binary
logger := log.Configure(&logWriter{logger: t}, log.Config{Level: log.Debug})
ctx := log.ContextWithLogger(context.Background(), logger)
Expand All @@ -188,6 +162,8 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
for _, language := range opts.languages {
ctx, done := context.WithCancel(ctx)
t.Run(language, func(t *testing.T) {
tmpDir := initWorkDir(t, cwd, opts)

verbs := rpc.Dial(ftlv1connect.NewVerbServiceClient, "http://localhost:8892", log.Debug)

var controller ftlv1connect.ControllerServiceClient
Expand Down Expand Up @@ -232,6 +208,35 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
}
}

func initWorkDir(t testing.TB, cwd string, opts options) string {
tmpDir := t.TempDir()

if opts.ftlConfigPath != "" {
// TODO: We shouldn't be copying the shared config from the "go" testdata...
opts.ftlConfigPath = filepath.Join(cwd, "testdata", "go", opts.ftlConfigPath)
projectPath := filepath.Join(tmpDir, "ftl-project.toml")

// Copy the specified FTL config to the temporary directory.
err := copy.Copy(opts.ftlConfigPath, projectPath)
if err == nil {
t.Setenv("FTL_CONFIG", projectPath)
} else {
// Use a path into the testdata directory instead of one relative to
// tmpDir. Otherwise we have a chicken and egg situation where the config
// can't be loaded until the module is copied over, and the config itself
// is used by FTL during startup.
// Some tests still rely on this behavior, so we can't remove it entirely.
t.Logf("Failed to copy %s to %s: %s", opts.ftlConfigPath, projectPath, err)
t.Setenv("FTL_CONFIG", opts.ftlConfigPath)
}

} else {
err := os.WriteFile(filepath.Join(tmpDir, "ftl-project.toml"), []byte(`name = "integration"`), 0644)
assert.NoError(t, err)
}
return tmpDir
}

type TestContext struct {
context.Context
// Temporary directory the test is executing in.
Expand Down
3 changes: 3 additions & 0 deletions jvm-runtime/java/scaffolding/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ignore

go 1.22.6
1 change: 0 additions & 1 deletion jvm-runtime/jvm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestLifecycle(t *testing.T) {
in.WithLanguages("java", "kotlin"),
in.GitInit(),
in.Exec("rm", "ftl-project.toml"),
in.IfLanguage("kotlin", in.Exec("rm", "-r", "echo")), //horrible, but we need to do cleanup, I wonder if we should be running each test in a separate directory
in.Exec("ftl", "init", "test", "."),
in.IfLanguage("java", in.Exec("ftl", "new", "java", ".", "echo")),
in.IfLanguage("kotlin", in.Exec("ftl", "new", "kotlin", ".", "echo")),
Expand Down
3 changes: 3 additions & 0 deletions jvm-runtime/kotlin/scaffolding/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ignore

go 1.22.6

0 comments on commit 8c04531

Please sign in to comment.