Skip to content

Commit 34ce12e

Browse files
authored
test: use mock transport to avoid many hanging worker routines (#698)
1 parent 41f45b5 commit 34ce12e

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

client_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/google/go-cmp/cmp"
1414
"github.com/google/go-cmp/cmp/cmpopts"
1515
pkgErrors "github.com/pkg/errors"
16+
"github.com/stretchr/testify/require"
1617
)
1718

1819
func TestNewClientAllowsEmptyDSN(t *testing.T) {
@@ -609,6 +610,7 @@ func TestSampleRate(t *testing.T) {
609610
func BenchmarkProcessEvent(b *testing.B) {
610611
c, err := NewClient(ClientOptions{
611612
SampleRate: 0.25,
613+
Transport: &TransportMock{},
612614
})
613615
if err != nil {
614616
b.Fatal(err)
@@ -708,8 +710,17 @@ func TestCustomMaxSpansProperty(t *testing.T) {
708710
assertEqual(t, client.Options().MaxSpans, 2000)
709711

710712
properClient, _ := NewClient(ClientOptions{
711-
MaxSpans: 3000,
713+
MaxSpans: 3000,
714+
Transport: &TransportMock{},
712715
})
713716

714717
assertEqual(t, properClient.Options().MaxSpans, 3000)
715718
}
719+
720+
func TestClientSetsUpTransport(t *testing.T) {
721+
client, _ := NewClient(ClientOptions{Dsn: testDsn})
722+
require.IsType(t, &HTTPTransport{}, client.Transport)
723+
724+
client, _ = NewClient(ClientOptions{})
725+
require.IsType(t, &noopTransport{}, client.Transport)
726+
}

hub_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
const testDsn = "http://[email protected]/1337"
1414

1515
func setupHubTest() (*Hub, *Client, *Scope) {
16-
client, _ := NewClient(ClientOptions{Dsn: testDsn})
16+
client, _ := NewClient(ClientOptions{Dsn: testDsn, Transport: &TransportMock{}})
1717
scope := NewScope()
1818
hub := NewHub(client, scope)
1919
return hub, client, scope
@@ -95,7 +95,7 @@ func TestPopScopeCannotLeaveStackEmpty(t *testing.T) {
9595
func TestBindClient(t *testing.T) {
9696
hub, client, _ := setupHubTest()
9797
hub.PushScope()
98-
newClient, _ := NewClient(ClientOptions{Dsn: testDsn})
98+
newClient, _ := NewClient(ClientOptions{Dsn: testDsn, Transport: &TransportMock{}})
9999
hub.BindClient(newClient)
100100

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

125125
hub.WithScope(func(scope *Scope) {
126-
newClient, _ := NewClient(ClientOptions{Dsn: testDsn})
126+
newClient, _ := NewClient(ClientOptions{Dsn: testDsn, Transport: &TransportMock{}})
127127
hub.BindClient(newClient)
128128
if hub.stackTop().client != newClient {
129129
t.Error("should use newly bound client")

tracing_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ type testContextKey struct{}
362362
type testContextValue struct{}
363363

364364
func NewTestContext(options ClientOptions) context.Context {
365+
if options.Transport == nil {
366+
options.Transport = &TransportMock{}
367+
}
365368
client, err := NewClient(options)
366369
if err != nil {
367370
panic(err)

0 commit comments

Comments
 (0)