Block ports in range 0 to 10000 when running tests (#666)
This commit is contained in:
parent
4a82c47427
commit
5bcb6fa4fe
@ -39,6 +39,7 @@ matrix:
|
|||||||
- popd
|
- popd
|
||||||
- go install -race ./...
|
- go install -race ./...
|
||||||
script:
|
script:
|
||||||
|
- go run scripts/use-ports.go -from 1024 -to 10000 &
|
||||||
- go test -race -cover -coverprofile=.coverprofile -json ./... | tparse -all
|
- go test -race -cover -coverprofile=.coverprofile -json ./... | tparse -all
|
||||||
- goveralls -coverprofile=.coverprofile -service=travis-ci
|
- goveralls -coverprofile=.coverprofile -service=travis-ci
|
||||||
- rm .coverprofile
|
- rm .coverprofile
|
||||||
|
49
scripts/use-ports.go
Normal file
49
scripts/use-ports.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (C) 2018 Storj Labs, Inc.
|
||||||
|
// See LICENSE for copying information.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fromPort = flag.Int("from", 0, "first port")
|
||||||
|
toPort = flag.Int("to", 10000, "last port")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var listeners []net.Listener
|
||||||
|
var unableToStart []int
|
||||||
|
for port := *fromPort; port < *toPort; port++ {
|
||||||
|
listener, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(port)))
|
||||||
|
if err != nil {
|
||||||
|
unableToStart = append(unableToStart, port)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
listeners = append(listeners, listener)
|
||||||
|
}
|
||||||
|
fmt.Printf("use-ports: unable to start on %v\n", unableToStart)
|
||||||
|
fmt.Printf("use-ports: listening on ports %v to %v\n", *fromPort, *toPort)
|
||||||
|
|
||||||
|
sigs := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigs, syscall.SIGQUIT)
|
||||||
|
<-sigs
|
||||||
|
|
||||||
|
for _, listener := range listeners {
|
||||||
|
err := listener.Close()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("unable to close: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user