tests: make test servers choose a random port to make more reliable

Tests have been randomly failing with messages like

    listen tcp 127.0.0.1:51778: bind: address already in use

Rework all the test servers so they choose a random free port on
startup and use that for the tests to avoid.
This commit is contained in:
Nick Craig-Wood
2019-05-01 11:16:22 +01:00
parent 8f89b03d7b
commit 9df322e889
5 changed files with 14 additions and 15 deletions

View File

@@ -18,8 +18,7 @@ import (
)
const (
testBindAddress = "localhost:51781"
testURL = "http://" + testBindAddress + "/"
testBindAddress = "localhost:0"
testFs = "testdata/files"
remoteURL = "[" + testFs + "]/" // initial URL path to fetch from that remote
)
@@ -39,6 +38,7 @@ func TestRcServer(t *testing.T) {
rcServer.Close()
rcServer.Wait()
}()
testURL := rcServer.Server.URL()
// Do the simplest possible test to check the server is alive
// Do it a few times to wait for the server to start