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: use mock transport to avoid many hanging worker routines #698

Merged
merged 2 commits into from
Aug 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
pkgErrors "github.com/pkg/errors"
"github.com/stretchr/testify/require"
)

func TestNewClientAllowsEmptyDSN(t *testing.T) {
Expand Down Expand Up @@ -609,6 +610,7 @@ func TestSampleRate(t *testing.T) {
func BenchmarkProcessEvent(b *testing.B) {
c, err := NewClient(ClientOptions{
SampleRate: 0.25,
Transport: &TransportMock{},
})
if err != nil {
b.Fatal(err)
Expand Down Expand Up @@ -708,8 +710,17 @@ func TestCustomMaxSpansProperty(t *testing.T) {
assertEqual(t, client.Options().MaxSpans, 2000)

properClient, _ := NewClient(ClientOptions{
MaxSpans: 3000,
MaxSpans: 3000,
Transport: &TransportMock{},
})

assertEqual(t, properClient.Options().MaxSpans, 3000)
}

func TestClientSetsUpTransport(t *testing.T) {
client, _ := NewClient(ClientOptions{Dsn: testDsn})
require.IsType(t, &HTTPTransport{}, client.Transport)

client, _ = NewClient(ClientOptions{})
require.IsType(t, &noopTransport{}, client.Transport)
}
6 changes: 3 additions & 3 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const testDsn = "http://whatever@example.com/1337"

func setupHubTest() (*Hub, *Client, *Scope) {
client, _ := NewClient(ClientOptions{Dsn: testDsn})
client, _ := NewClient(ClientOptions{Dsn: testDsn, Transport: &TransportMock{}})
scope := NewScope()
hub := NewHub(client, scope)
return hub, client, scope
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestPopScopeCannotLeaveStackEmpty(t *testing.T) {
func TestBindClient(t *testing.T) {
hub, client, _ := setupHubTest()
hub.PushScope()
newClient, _ := NewClient(ClientOptions{Dsn: testDsn})
newClient, _ := NewClient(ClientOptions{Dsn: testDsn, Transport: &TransportMock{}})
hub.BindClient(newClient)

if (*hub.stack)[0].client == (*hub.stack)[1].client {
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestWithScopeBindClient(t *testing.T) {
hub, client, _ := setupHubTest()

hub.WithScope(func(scope *Scope) {
newClient, _ := NewClient(ClientOptions{Dsn: testDsn})
newClient, _ := NewClient(ClientOptions{Dsn: testDsn, Transport: &TransportMock{}})
hub.BindClient(newClient)
if hub.stackTop().client != newClient {
t.Error("should use newly bound client")
Expand Down
3 changes: 3 additions & 0 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ type testContextKey struct{}
type testContextValue struct{}

func NewTestContext(options ClientOptions) context.Context {
if options.Transport == nil {
options.Transport = &TransportMock{}
}
client, err := NewClient(options)
if err != nil {
panic(err)
Expand Down