Skip to content

Commit 29f9728

Browse files
authored
Merge pull request #309 from wallyqs/rm-default-options-dialer
[REMOVED] Dialer from DefaultOptions
2 parents 43abfaa + d6ee894 commit 29f9728

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

nats.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ var (
7979
ErrStaleConnection = errors.New("nats: " + STALE_CONNECTION)
8080
)
8181

82+
// GetDefaultOptions returns default configuration options for the client.
8283
func GetDefaultOptions() Options {
83-
opts := Options{
84+
return Options{
8485
AllowReconnect: true,
8586
MaxReconnect: DefaultMaxReconnect,
8687
ReconnectWait: DefaultReconnectWait,
@@ -89,11 +90,7 @@ func GetDefaultOptions() Options {
8990
MaxPingsOut: DefaultMaxPingOut,
9091
SubChanLen: DefaultMaxChanLen,
9192
ReconnectBufSize: DefaultReconnectBufSize,
92-
Dialer: &net.Dialer{
93-
Timeout: DefaultTimeout,
94-
},
9593
}
96-
return opts
9794
}
9895

9996
// DEPRECATED: Use GetDefaultOptions() instead.

test/conn_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,30 @@ func TestUseCustomDialer(t *testing.T) {
13121312
}
13131313
}
13141314

1315+
func TestDefaultOptionsDialer(t *testing.T) {
1316+
s := RunDefaultServer()
1317+
defer s.Shutdown()
1318+
1319+
opts1 := nats.DefaultOptions
1320+
opts2 := nats.DefaultOptions
1321+
1322+
nc1, err := opts1.Connect()
1323+
if err != nil {
1324+
t.Fatalf("Unexpected error on connect: %v", err)
1325+
}
1326+
defer nc1.Close()
1327+
1328+
nc2, err := opts2.Connect()
1329+
if err != nil {
1330+
t.Fatalf("Unexpected error on connect: %v", err)
1331+
}
1332+
defer nc2.Close()
1333+
1334+
if nc1.Opts.Dialer == nc2.Opts.Dialer {
1335+
t.Fatalf("Expected each connection to have its own dialer")
1336+
}
1337+
}
1338+
13151339
func TestCustomFlusherTimeout(t *testing.T) {
13161340
s := RunDefaultServer()
13171341
defer s.Shutdown()

0 commit comments

Comments
 (0)