cmd/swarm: solve rare cases of using the same random port in tests (#17352)

This commit is contained in:
Janoš Guljaš
2018-08-09 16:15:59 +02:00
committed by Balint Gabor
parent 3bcb501c8f
commit 45eaef2431
2 changed files with 132 additions and 20 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
"testing"
@ -559,3 +560,16 @@ func TestValidateConfig(t *testing.T) {
}
}
}
func assignTCPPort() (string, error) {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return "", err
}
l.Close()
_, port, err := net.SplitHostPort(l.Addr().String())
if err != nil {
return "", err
}
return port, nil
}