Skip to content

Commit afd8805

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

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
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/integration/actions.go

+8-4
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,6 +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...))
175+
t.Setenv("FTL_ENDPOINT", "http://127.0.0.1:"+TestPort)
173176
output, err := ftlexec.Capture(ic, ic.workDir, cmd, args...)
174177
assert.NoError(t, err)
175178
assert.Equal(t, output, []byte(want))
@@ -181,6 +184,7 @@ func ExecWithExpectedOutput(want string, cmd string, args ...string) Action {
181184
func ExecWithExpectedError(want string, cmd string, args ...string) Action {
182185
return func(t testing.TB, ic TestContext) {
183186
Infof("Executing: %s %s", cmd, shellquote.Join(args...))
187+
t.Setenv("FTL_ENDPOINT", "http://127.0.0.1:"+TestPort)
184188
output, err := ftlexec.Capture(ic, ic.workDir, cmd, args...)
185189
assert.Error(t, err)
186190
assert.Contains(t, string(output), want)
@@ -193,7 +197,7 @@ func ExecWithExpectedError(want string, cmd string, args ...string) Action {
193197
func ExecWithOutput(cmd string, args []string, capture func(output string)) Action {
194198
return func(t testing.TB, ic TestContext) {
195199
Infof("Executing: %s %s", cmd, shellquote.Join(args...))
196-
output, err := ftlexec.Capture(ic, ic.workDir, cmd, args...)
200+
output, err := ftlexec.CaptureWithEnv(ic, ic.workDir, cmd, []string{"FTL_ENDPOINT=http://127.0.0.1:" + TestPort}, args...)
197201
assert.NoError(t, err, "%s", string(output))
198202
capture(string(output))
199203
}
@@ -220,7 +224,7 @@ func ExpectError(action Action, expectedErrorMsg ...string) Action {
220224
// Deploy a module from the working directory and wait for it to become available.
221225
func Deploy(module string) Action {
222226
return Chain(
223-
Exec("ftl", "deploy", module),
227+
Exec("ftl", "deploy", "--endpoint", "http://127.0.0.1:"+TestPort, module),
224228
Wait(module),
225229
)
226230
}
@@ -521,7 +525,7 @@ func JsonData(t testing.TB, body interface{}) []byte {
521525
func HttpCall(method string, path string, headers map[string][]string, body []byte, onResponse func(t testing.TB, resp *HTTPResponse)) Action {
522526
return func(t testing.TB, ic TestContext) {
523527
Infof("HTTP %s %s", method, path)
524-
baseURL, err := url.Parse(fmt.Sprintf("http://localhost:8891"))
528+
baseURL, err := url.Parse(fmt.Sprintf("http://localhost:" + TestIngressPort))
525529
assert.NoError(t, err)
526530

527531
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)