Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: deduplicate Flush() timeout settings #702

Merged
merged 1 commit into from Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion fasthttp/sentryfasthttp_test.go
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/getsentry/sentry-go"
sentryfasthttp "github.com/getsentry/sentry-go/fasthttp"
"github.com/getsentry/sentry-go/internal/testutils"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/valyala/fasthttp"
Expand Down Expand Up @@ -194,7 +195,7 @@ func TestIntegration(t *testing.T) {
}
}

if ok := sentry.Flush(time.Second); !ok {
if ok := sentry.Flush(testutils.FlushTimeout()); !ok {
t.Fatal("sentry.Flush timed out")
}
close(eventsCh)
Expand Down
3 changes: 2 additions & 1 deletion gin/sentrygin_test.go
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/getsentry/sentry-go"
sentrygin "github.com/getsentry/sentry-go/gin"
"github.com/getsentry/sentry-go/internal/testutils"
"github.com/gin-gonic/gin"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -317,7 +318,7 @@ func TestIntegration(t *testing.T) {
res.Body.Close()
}

if ok := sentry.Flush(time.Second); !ok {
if ok := sentry.Flush(testutils.FlushTimeout()); !ok {
t.Fatal("sentry.Flush timed out")
}
close(eventsCh)
Expand Down
3 changes: 2 additions & 1 deletion http/sentryhttp_test.go
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http"
"github.com/getsentry/sentry-go/internal/testutils"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
Expand Down Expand Up @@ -197,7 +198,7 @@ func TestIntegration(t *testing.T) {
res.Body.Close()
}

if ok := sentry.Flush(time.Second); !ok {
if ok := sentry.Flush(testutils.FlushTimeout()); !ok {
t.Fatal("sentry.Flush timed out")
}
close(eventsCh)
Expand Down
19 changes: 19 additions & 0 deletions internal/testutils/consts.go
@@ -0,0 +1,19 @@
package testutils

import (
"os"
"time"
)

func IsCI() bool {
return os.Getenv("CI") != ""
}

func FlushTimeout() time.Duration {
if IsCI() {
// CI is very overloaded so we need to allow for a long wait time.
return 5 * time.Second
}

return time.Second

Check warning on line 18 in internal/testutils/consts.go

View check run for this annotation

Codecov / codecov/patch

internal/testutils/consts.go#L18

Added line #L18 was not covered by tests
}
5 changes: 3 additions & 2 deletions logrus/logrusentry_test.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/getsentry/sentry-go"
"github.com/getsentry/sentry-go/internal/testutils"
)

func TestNew(t *testing.T) {
Expand All @@ -36,7 +37,7 @@ func TestNew(t *testing.T) {
if id := h.hub.CaptureEvent(&sentry.Event{}); id == nil {
t.Error("CaptureEvent failed")
}
if !h.Flush(5 * time.Second) {
if !h.Flush(testutils.FlushTimeout()) {
t.Error("flush failed")
}
})
Expand All @@ -59,7 +60,7 @@ func TestFire(t *testing.T) {
t.Fatal(err)
}

if !hook.Flush(5 * time.Second) {
if !hook.Flush(testutils.FlushTimeout()) {
t.Error("flush failed")
}
}
Expand Down
14 changes: 5 additions & 9 deletions profiler_test.go
Expand Up @@ -2,14 +2,14 @@ package sentry

import (
"fmt"
"os"
"runtime"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"

"github.com/getsentry/sentry-go/internal/testutils"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ func TestProfilerCollection(t *testing.T) {

start := time.Now()
stopFn := startProfiling(start)
if isCI() {
if testutils.IsCI() {
doWorkFor(5 * time.Second)
} else {
doWorkFor(35 * time.Millisecond)
Expand Down Expand Up @@ -238,7 +238,7 @@ func validateProfile(t *testing.T, trace *profileTrace, duration time.Duration)
}

func TestProfilerSamplingRate(t *testing.T) {
if isCI() {
if testutils.IsCI() {
t.Skip("Skipping on CI because the machines are too overloaded to provide consistent ticker resolution.")
}
if testing.Short() {
Expand Down Expand Up @@ -303,13 +303,9 @@ func testTick(t *testing.T, count, i int, prevTick time.Time) time.Time {
return time.Now()
}

func isCI() bool {
return os.Getenv("CI") != ""
}

// This test measures the accuracy of time.NewTicker() on the current system.
func TestProfilerTimeTicker(t *testing.T) {
if isCI() {
if testutils.IsCI() {
t.Skip("Skipping on CI because the machines are too overloaded to provide consistent ticker resolution.")
}

Expand Down Expand Up @@ -426,7 +422,7 @@ func TestProfilerOverhead(t *testing.T) {
if testing.Short() {
t.Skip("Skipping overhead benchmark in short mode.")
}
if isCI() {
if testutils.IsCI() {
t.Skip("Skipping on CI because the machines are too overloaded to run the test properly - they show between 3 and 30 %% overhead....")
}

Expand Down
13 changes: 4 additions & 9 deletions transport_test.go
Expand Up @@ -14,6 +14,7 @@ import (
"testing"
"time"

"github.com/getsentry/sentry-go/internal/testutils"
"github.com/google/go-cmp/cmp"
)

Expand Down Expand Up @@ -432,13 +433,7 @@ func TestHTTPTransport(t *testing.T) {

transportMustFlush := func(t *testing.T, id string) {
t.Helper()

timeout := 100 * time.Millisecond
if isCI() {
// CI is very overloaded so we need to allow for a long wait time.
timeout = 5 * time.Second
}
ok := transport.Flush(timeout)
ok := transport.Flush(testutils.FlushTimeout())
if !ok {
t.Fatalf("[CLIENT] {%.4s} Flush() timed out", id)
}
Expand Down Expand Up @@ -552,7 +547,7 @@ func testKeepAlive(t *testing.T, tr Transport) {
checkLastConnReuse := func(reused bool) {
t.Helper()
reqCount++
if !tr.Flush(2 * time.Second) {
if !tr.Flush(testutils.FlushTimeout()) {
t.Fatal("Flush timed out")
}
if len(rt.reusedConn) != reqCount {
Expand Down Expand Up @@ -666,7 +661,7 @@ func testRateLimiting(t *testing.T, tr Transport) {
}()
wg.Wait()

if !tr.Flush(time.Second) {
if !tr.Flush(testutils.FlushTimeout()) {
t.Fatal("Flush timed out")
}

Expand Down