Skip to content

Commit

Permalink
test: handle ping available during partial timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Bourne committed Nov 13, 2017
1 parent adca82e commit a8ea522
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ install:
- gem install --no-ri --no-rdoc fpm
script:
- sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
- go test -timeout 30s -short -v $(glide novendor)
- go test -timeout 60s -short -v $(glide novendor)
- CGO_ENABLED=0 gox -osarch "linux/386 linux/amd64 darwin/amd64 windows/386 windows/amd64" -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
-ldflags="-X github.com/racker/rackspace-monitoring-poller/version.Version=$(git
symbolic-ref -q --short HEAD || git describe --tags --exact-match)"
Expand Down
2 changes: 1 addition & 1 deletion check/check_ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ func TestPingCheck_PartialResponses(t *testing.T) {

assert.Equal(t, 1, crs.Length())
AssertMetrics(t, expected, crs.Get(0).Metrics)
assert.False(t, crs.Available)
assert.True(t, crs.Available)
}
19 changes: 13 additions & 6 deletions check/pinger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestPinger_Concurrent(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
}

const concurrency = 30
const concurrency = 75
const pings = 5
var wg sync.WaitGroup

Expand All @@ -100,19 +100,26 @@ func TestPinger_Concurrent(t *testing.T) {

responses := make([]*check.PingResponse, pings)

timeouts := 0

for p := 0; p < pings; p++ {
resp := pinger.Ping(p+1, 1*time.Second)
require.False(t, resp.Timeout, "not expecting timeout for seq=%d, checkId=%s", p+1, checkId)
if resp.Timeout {
timeouts++
require.True(t, timeouts < 3, "not expecting %d timeouts for seq=%d, checkId=%s", timeouts, p+1, checkId)
continue
}
require.True(t, resp.Seq > 0 && resp.Seq <= pings, "invalid seq from resp=%v", resp)
responses[resp.Seq-1] = &resp
time.Sleep(10 * time.Millisecond)
}

for p := 0; p < pings; p++ {
require.NotNil(t, responses[p], "Missing ping seq=%d,checkId=%s", p+1, checkId)
assert.True(t, responses[p].Rtt > 0, "Zero RTT seq=%d", p+1)
assert.NoError(t, responses[p].Err, "seq=%d", p+1)
assert.False(t, responses[p].Timeout, "seq=%d", p+1)
if responses[p] != nil {
assert.True(t, responses[p].Rtt > 0, "Zero RTT seq=%d", p+1)
assert.NoError(t, responses[p].Err, "seq=%d", p+1)
assert.False(t, responses[p].Timeout, "seq=%d", p+1)
}

}

Expand Down

0 comments on commit a8ea522

Please sign in to comment.