Skip to content

Commit 78d2844

Browse files
feat: run tests on different port
This should stop tests from interferring with ftl dev fixes #2577
1 parent c633e59 commit 78d2844

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

bin/hermit.hcl

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
env = {
22
"DBMATE_MIGRATIONS_DIR": "${HERMIT_ENV}/backend/controller/sql/schema",
3-
"FTL_ENDPOINT": "http://localhost:8892",
43
"FTL_INIT_GO_REPLACE": "github.com/TBD54566975/ftl=${HERMIT_ENV}",
54
"FTL_SOURCE": "${HERMIT_ENV}",
65
"OTEL_GRPC_PORT": "4317",

internal/exec/exec.go

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package exec
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"os"
78
"os/exec" //nolint:depguard
89
"syscall"
@@ -22,6 +23,18 @@ func LookPath(exe string) (string, error) {
2223
return path, err
2324
}
2425

26+
func CaptureWithEnv(ctx context.Context, dir, exe string, env []string, args ...string) ([]byte, error) {
27+
cmd := Command(ctx, log.Debug, dir, exe, args...)
28+
cmd.Env = append(cmd.Env, env...)
29+
cmd.Stdout = nil
30+
cmd.Stderr = nil
31+
out, err := cmd.CombinedOutput()
32+
if err != nil {
33+
return out, fmt.Errorf("process failed: %w", err)
34+
}
35+
return out, nil
36+
}
37+
2538
func Capture(ctx context.Context, dir, exe string, args ...string) ([]byte, error) {
2639
cmd := Command(ctx, log.Debug, dir, exe, args...)
2740
cmd.Stdout = nil

internal/integration/actions.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ func DebugShell() Action {
160160
func Exec(cmd string, args ...string) Action {
161161
return func(t testing.TB, ic TestContext) {
162162
Infof("Executing (in %s): %s %s", ic.workDir, cmd, shellquote.Join(args...))
163-
err := ftlexec.Command(ic, log.Debug, ic.workDir, cmd, args...).RunStderrError(ic)
163+
command := ftlexec.Command(ic, log.Debug, ic.workDir, cmd, args...)
164+
command.Env = append(command.Env, "FTL_ENDPOINT=http://127.0.0.1:"+TestPort)
165+
err := command.RunStderrError(ic)
164166
assert.NoError(t, err)
165167
}
166168
}
@@ -170,7 +172,7 @@ func Exec(cmd string, args ...string) Action {
170172
func ExecWithExpectedOutput(want string, cmd string, args ...string) Action {
171173
return func(t testing.TB, ic TestContext) {
172174
Infof("Executing: %s %s", cmd, shellquote.Join(args...))
173-
output, err := ftlexec.Capture(ic, ic.workDir, cmd, args...)
175+
output, err := ftlexec.CaptureWithEnv(ic, ic.workDir, cmd, []string{"FTL_ENDPOINT=http://127.0.0.1:" + TestPort}, args...)
174176
assert.NoError(t, err)
175177
assert.Equal(t, output, []byte(want))
176178
}
@@ -181,7 +183,7 @@ func ExecWithExpectedOutput(want string, cmd string, args ...string) Action {
181183
func ExecWithExpectedError(want string, cmd string, args ...string) Action {
182184
return func(t testing.TB, ic TestContext) {
183185
Infof("Executing: %s %s", cmd, shellquote.Join(args...))
184-
output, err := ftlexec.Capture(ic, ic.workDir, cmd, args...)
186+
output, err := ftlexec.CaptureWithEnv(ic, ic.workDir, cmd, []string{"FTL_ENDPOINT=http://127.0.0.1:" + TestPort}, args...)
185187
assert.Error(t, err)
186188
assert.Contains(t, string(output), want)
187189
}
@@ -193,7 +195,7 @@ func ExecWithExpectedError(want string, cmd string, args ...string) Action {
193195
func ExecWithOutput(cmd string, args []string, capture func(output string)) Action {
194196
return func(t testing.TB, ic TestContext) {
195197
Infof("Executing: %s %s", cmd, shellquote.Join(args...))
196-
output, err := ftlexec.Capture(ic, ic.workDir, cmd, args...)
198+
output, err := ftlexec.CaptureWithEnv(ic, ic.workDir, cmd, []string{"FTL_ENDPOINT=http://127.0.0.1:" + TestPort}, args...)
197199
assert.NoError(t, err, "%s", string(output))
198200
capture(string(output))
199201
}
@@ -220,7 +222,7 @@ func ExpectError(action Action, expectedErrorMsg ...string) Action {
220222
// Deploy a module from the working directory and wait for it to become available.
221223
func Deploy(module string) Action {
222224
return Chain(
223-
Exec("ftl", "deploy", module),
225+
Exec("ftl", "deploy", "--endpoint", "http://127.0.0.1:"+TestPort, module),
224226
Wait(module),
225227
)
226228
}
@@ -521,7 +523,7 @@ func JsonData(t testing.TB, body interface{}) []byte {
521523
func HttpCall(method string, path string, headers map[string][]string, body []byte, onResponse func(t testing.TB, resp *HTTPResponse)) Action {
522524
return func(t testing.TB, ic TestContext) {
523525
Infof("HTTP %s %s", method, path)
524-
baseURL, err := url.Parse(fmt.Sprintf("http://localhost:8891"))
526+
baseURL, err := url.Parse(fmt.Sprintf("http://localhost:" + TestIngressPort))
525527
assert.NoError(t, err)
526528

527529
u, err := baseURL.Parse(path)

internal/integration/harness.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import (
2929
"github.com/TBD54566975/ftl/internal/rpc"
3030
)
3131

32+
const TestPort = "9892"
33+
const TestIngressPort = "9891"
34+
3235
func integrationTestTimeout() time.Duration {
3336
timeout := optional.Zero(os.Getenv("FTL_INTEGRATION_TEST_TIMEOUT")).Default("5s")
3437
d, err := time.ParseDuration(timeout)
@@ -174,16 +177,16 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
174177
t.Run(language, func(t *testing.T) {
175178
tmpDir := initWorkDir(t, cwd, opts)
176179

177-
verbs := rpc.Dial(ftlv1connect.NewVerbServiceClient, "http://localhost:8892", log.Debug)
180+
verbs := rpc.Dial(ftlv1connect.NewVerbServiceClient, "http://localhost:"+TestPort, log.Debug)
178181

179182
var controller ftlv1connect.ControllerServiceClient
180183
var console pbconsoleconnect.ConsoleServiceClient
181184
if opts.startController {
182-
controller = rpc.Dial(ftlv1connect.NewControllerServiceClient, "http://localhost:8892", log.Debug)
183-
console = rpc.Dial(pbconsoleconnect.NewConsoleServiceClient, "http://localhost:8892", log.Debug)
185+
controller = rpc.Dial(ftlv1connect.NewControllerServiceClient, "http://localhost:"+TestPort, log.Debug)
186+
console = rpc.Dial(pbconsoleconnect.NewConsoleServiceClient, "http://localhost:"+TestPort, log.Debug)
184187

185188
Infof("Starting ftl cluster")
186-
ctx = startProcess(ctx, t, filepath.Join(binDir, "ftl"), "serve", "--recreate")
189+
ctx = startProcess(ctx, t, filepath.Join(binDir, "ftl"), "serve", "--recreate", "--bind", "http://127.0.0.1:"+TestIngressPort)
187190
}
188191

189192
testData := filepath.Join(cwd, "testdata", language)

0 commit comments

Comments
 (0)