diff --git a/internal/expect.go b/internal/expect.go index 2711c5dd..ff782503 100644 --- a/internal/expect.go +++ b/internal/expect.go @@ -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{}) @@ -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) } } @@ -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 { @@ -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) } } @@ -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)