#749·fx

test issue - example_test relies on port 8080 being available

Author: sywhangCreated Jun 22, 2021Updated Apr 3, 2025

Not a major issue, but example_test relies on port 8080 being available, so when 8080 is being used by another process, it fails without much info:

--- FAIL: Example (0.01s)
got:
Executing NewLogger.
Executing NewMux.
Executing NewHandler.
Starting HTTP server.
Stopping HTTP server.
want:
Executing NewLogger.
Executing NewMux.
Executing NewHandler.
Starting HTTP server.
Got a request.
Stopping HTTP server.
{"level":"info","ts":1624405878.099044,"msg":"providing","type":"fx_test.Username","constructor":"go.uber.org/fx_test.ExamplePopulate.func1()"}
{"level":"info","ts":1624405878.099235,"msg":"providing","type":"fx.Lifecycle","constructor":"go.uber.org/fx.New.func1()"}
{"level":"info","ts":1624405878.099299,"msg":"providing","type":"fx.Shutdowner","constructor":"go.uber.org/fx.(*App).shutdowner-fm()"}
{"level":"info","ts":1624405878.099367,"msg":"providing","type":"fx.DotGraph","constructor":"go.uber.org/fx.(*App).dotGraph-fm()"}
{"level":"info","ts":1624405878.0994182,"msg":"invoke","function":"reflect.makeFuncStub()"}
{"level":"info","ts":1624405878.099509,"msg":"running"}
FAIL
FAIL	go.uber.org/fx	1.802s
ok  	go.uber.org/fx/fxtest	(cached)
ok  	go.uber.org/fx/internal/fxlog	(cached)
?   	go.uber.org/fx/internal/fxlog/foovendor	[no test files]
?   	go.uber.org/fx/internal/fxlog/sample.git	[no test files]
ok  	go.uber.org/fx/internal/fxreflect	(cached)
ok  	go.uber.org/fx/internal/lifecycle	(cached)
ok  	go.uber.org/fx/internal/testutil	(cached)
FAIL

We should change the test to check if 8080 is available and pick a different port if it's not available.