mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
test: apptest was accidently choosing ports in use (#12580)
Apptest requires a port without a listening server to test failure cases. This port was chosen and had a chance of actually being provisioned. To prevent this accident, a port <1k is chosen, since those will never be allocated.
This commit is contained in:
@ -309,15 +309,31 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
|
|||||||
},
|
},
|
||||||
}, workspaceMutators...)
|
}, workspaceMutators...)
|
||||||
|
|
||||||
|
// Intentionally going to choose a port that will never be chosen.
|
||||||
|
// Ports <1k will never be selected. 396 is for some old OS over IP.
|
||||||
|
// It will never likely be provisioned. Using quick timeout since
|
||||||
|
// it's all localhost
|
||||||
|
fakeAppURL := "http://127.1.0.1:396"
|
||||||
|
conn, err := net.DialTimeout("tcp", fakeAppURL, time.Millisecond*100)
|
||||||
|
if err == nil {
|
||||||
|
// In the absolute rare case someone hits this. Writing code to find a free port
|
||||||
|
// seems like a waste of time to program and run.
|
||||||
|
_ = conn.Close()
|
||||||
|
t.Errorf("an unused port is required for the fake app. "+
|
||||||
|
"The url %q happens to be an active port. If you hit this, then this test"+
|
||||||
|
"will need to be modified to run on your system. Or you can stop serving an"+
|
||||||
|
"app on that port.", fakeAppURL)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
appURL := fmt.Sprintf("%s://127.0.0.1:%d?%s", scheme, port, proxyTestAppQuery)
|
appURL := fmt.Sprintf("%s://127.0.0.1:%d?%s", scheme, port, proxyTestAppQuery)
|
||||||
protoApps := []*proto.App{
|
protoApps := []*proto.App{
|
||||||
{
|
{
|
||||||
Slug: proxyTestAppNameFake,
|
Slug: proxyTestAppNameFake,
|
||||||
DisplayName: proxyTestAppNameFake,
|
DisplayName: proxyTestAppNameFake,
|
||||||
SharingLevel: proto.AppSharingLevel_OWNER,
|
SharingLevel: proto.AppSharingLevel_OWNER,
|
||||||
// Hopefully this IP and port doesn't exist.
|
Url: fakeAppURL,
|
||||||
Url: "http://127.1.0.1:65535",
|
Subdomain: true,
|
||||||
Subdomain: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Slug: proxyTestAppNameOwner,
|
Slug: proxyTestAppNameOwner,
|
||||||
|
Reference in New Issue
Block a user