Commit 01ae5cf9a0
Verified · cmc ci/build: success ci/test: success
Layout: unified · split
e2e/ssh_test.go +9 −5
| @@ -29,12 +29,16 @@ type instance struct { | ||
| 29 | 29 | stderr *tailBuffer // the end of the first serve's stderr |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | // nextPort hands out candidate ports. Seeded randomly so two test processes | |
| 33 | // on one machine — `go test ./...` runs packages concurrently — start in | |
| 34 | // different places. | |
| 32 | // nextPort hands out candidate ports below 32768, where Linux and macOS | |
| 33 | // start the ports they give outgoing connections: a git or SMTP client in | |
| 34 | // another test cannot take one between the bind test and gitbayd's bind. | |
| 35 | // Seeded randomly so two test processes on one machine — `go test ./...` | |
| 36 | // runs packages concurrently — start in different places. | |
| 37 | const lastPort = 32000 | |
| 38 | ||
| 35 | 39 | var nextPort = func() *atomic.Int32 { |
| 36 | 40 | var n atomic.Int32 |
| 37 | n.Store(int32(20000 + rand.IntN(20000))) | |
| 41 | n.Store(int32(10000 + rand.IntN(10000))) | |
| 38 | 42 | return &n |
| 39 | 43 | }() |
| 40 | 44 | |
| @@ -58,7 +62,7 @@ func freePorts(t *testing.T, n int) []int { | ||
| 58 | 62 | ports := make([]int, 0, n) |
| 59 | 63 | for len(ports) < n { |
| 60 | 64 | p := int(nextPort.Add(1)) |
| 61 | if p > 60000 { | |
| 65 | if p > lastPort { | |
| 62 | 66 | t.Fatal("ran out of ports") |
| 63 | 67 | } |
| 64 | 68 | ln, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", p)) |