1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-06 10:33:34 +00:00

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

@@ -20,11 +20,11 @@ import (
var (
dlnaServer *server
testURL string
)
const (
testBindAddress = "localhost:51777"
testURL = "http://" + testBindAddress + "/"
testBindAddress = "localhost:0"
)
func startServer(t *testing.T, f fs.Fs) {
@@ -32,6 +32,7 @@ func startServer(t *testing.T, f fs.Fs) {
opt.ListenAddr = testBindAddress
dlnaServer = newServer(f, &opt)
assert.NoError(t, dlnaServer.Serve())
testURL = "http://" + dlnaServer.HTTPConn.Addr().String() + "/"
}
func TestInit(t *testing.T) {