Use 10.255.255.1:80 as an always-timeout address

Since 10.0.0.0:1 causes ErrConnect(permission denied) instead of ErrTimeout in Travis CI's macOS environment.
This commit is contained in:
Tevin Zhang 2019-02-13 10:55:52 +08:00
parent 6868d911df
commit 0d34068678
2 changed files with 8 additions and 8 deletions

View File

@ -58,11 +58,6 @@ func TestStopNStartChecker(t *testing.T) {
_testChecker(t, c)
}
const (
AddrDead = "127.0.0.1:1"
AddrTimeout = "10.0.0.0:1"
)
func _startTestServer() (string, context.CancelFunc) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
addr := ts.Listener.Addr().String()

View File

@ -11,6 +11,11 @@ import (
"time"
)
const (
AddrDead = "127.0.0.1:1"
AddrTimeout = "10.255.255.1:80"
)
// assert calls t.Fatal if the result is false
func assert(t *testing.T, result bool) {
if !result {
@ -59,7 +64,7 @@ func TestCheckAddr(t *testing.T) {
timeout := time.Second * 2
// Check dead server
err = c.CheckAddr("127.0.0.1:1", timeout)
err = c.CheckAddr(AddrDead, timeout)
if runtime.GOOS == "linux" {
_, ok := err.(*ErrConnect)
assert(t, ok)
@ -73,7 +78,7 @@ func TestCheckAddr(t *testing.T) {
assert(t, err == nil)
ts.Close()
// Check non-routable address, thus timeout
err = c.CheckAddr("10.0.0.0:1", timeout)
err = c.CheckAddr(AddrTimeout, timeout)
if err != ErrTimeout {
t.Log("expected ErrTimeout, got ", err)
t.FailNow()
@ -90,7 +95,7 @@ func TestCheckAddrConcurrently(t *testing.T) {
var wg sync.WaitGroup
check := func() {
if err := c.CheckAddr("10.0.0.0:1", time.Millisecond*50); err == nil {
if err := c.CheckAddr(AddrTimeout, time.Millisecond*50); err == nil {
t.Fatal("Concurrent testing failed")
}
wg.Done()