Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Skip non-zero duration tests on Windows
  • Loading branch information
will@newrelic.com committed Nov 16, 2016
1 parent 8fbe881 commit b088893
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions internal/expect.go
Expand Up @@ -2,9 +2,18 @@ package internal

import (
"fmt"
"runtime"
"time"
)

var (
// Unfortunately, the resolution of time.Now() on Windows is coarse: Two
// sequential calls to time.Now() may return the same value, and tests
// which expect non-zero durations may fail. To avoid adding sleep
// statements or mocking time.Now(), those tests are skipped on Windows.
doDurationTests = runtime.GOOS != `windows`
)

// Validator is used for testing.
type Validator interface {
Error(...interface{})
Expand Down Expand Up @@ -227,13 +236,13 @@ func expectErrorEvent(v Validator, err *ErrorEvent, expect WantErrorEvent) {
if expect.ExternalCallCount != err.externalCallCount {
v.Error("external call count", expect.ExternalCallCount, err.externalCallCount)
}
if (0 == expect.ExternalCallCount) != (err.externalDuration == 0) {
if doDurationTests && (0 == expect.ExternalCallCount) != (err.externalDuration == 0) {
v.Error("external duration", err.externalDuration)
}
if expect.DatastoreCallCount != err.datastoreCallCount {
v.Error("datastore call count", expect.DatastoreCallCount, err.datastoreCallCount)
}
if (0 == expect.DatastoreCallCount) != (err.datastoreDuration == 0) {
if doDurationTests && (0 == expect.DatastoreCallCount) != (err.datastoreDuration == 0) {
v.Error("datastore duration", err.datastoreDuration)
}
}
Expand All @@ -258,7 +267,7 @@ func ExpectErrorEvents(v Validator, events *errorEvents, expect []WantErrorEvent
func expectTxnEvent(v Validator, e *TxnEvent, expect WantTxnEvent) {
validateStringField(v, "apdex zone", expect.Zone, e.Zone.label())
validateStringField(v, "name", expect.Name, e.Name)
if 0 == e.Duration {
if doDurationTests && 0 == e.Duration {
v.Error("zero duration", e.Duration)
}
if (0 != e.Queuing) != expect.Queuing {
Expand All @@ -273,13 +282,13 @@ func expectTxnEvent(v Validator, e *TxnEvent, expect WantTxnEvent) {
if expect.ExternalCallCount != e.externalCallCount {
v.Error("external call count", expect.ExternalCallCount, e.externalCallCount)
}
if (0 == expect.ExternalCallCount) != (e.externalDuration == 0) {
if doDurationTests && (0 == expect.ExternalCallCount) != (e.externalDuration == 0) {
v.Error("external duration", e.externalDuration)
}
if expect.DatastoreCallCount != e.datastoreCallCount {
v.Error("datastore call count", expect.DatastoreCallCount, e.datastoreCallCount)
}
if (0 == expect.DatastoreCallCount) != (e.datastoreDuration == 0) {
if doDurationTests && (0 == expect.DatastoreCallCount) != (e.datastoreDuration == 0) {
v.Error("datastore duration", e.datastoreDuration)
}
}
Expand Down Expand Up @@ -328,7 +337,7 @@ func ExpectErrors(v Validator, errors *harvestErrors, expect []WantError) {
}

func expectTxnTrace(v Validator, trace *HarvestTrace, expect WantTxnTrace) {
if 0 == trace.Duration {
if doDurationTests && 0 == trace.Duration {
v.Error("zero trace duration")
}
validateStringField(v, "metric name", expect.MetricName, trace.MetricName)
Expand Down

0 comments on commit b088893

Please sign in to comment.