Skip to content

Commit

Permalink
Skip TestNetDialTimeout if network is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Feb 1, 2016
1 parent ff4ade4 commit e6ef4b7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion connection_test.go
Expand Up @@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"runtime"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -529,13 +530,25 @@ func TestNetDialTimeout(t *testing.T) {
// timeoutHostPort uses a blackholed address (RFC 6890) with a port
// reserved for documentation. This address should always cause a timeout.
const timeoutHostPort = "192.18.0.254:44444"
timeoutPeriod := testutils.Timeout(50 * time.Millisecond)

client := testutils.NewClient(t, nil)
defer client.Close()

ctx, cancel := NewContext(50 * time.Millisecond)
started := time.Now()
ctx, cancel := NewContext(timeoutPeriod)
defer cancel()

err := client.Ping(ctx, timeoutHostPort)
if !assert.Error(t, err, "Ping to blackhole address should fail") {
return
}

if strings.Contains(err.Error(), "network is unreachable") {
t.Skipf("Skipping test, as network interface may not be available")
}

d := time.Since(started)
assert.Equal(t, ErrTimeout, err, "Ping expected to fail with timeout")
assert.True(t, d >= timeoutPeriod, "Timeout should take more than %v, took %v", timeoutPeriod, d)
}

0 comments on commit e6ef4b7

Please sign in to comment.