Skip to content

Commit

Permalink
Merge pull request #309 from wallyqs/rm-default-options-dialer
Browse files Browse the repository at this point in the history
[REMOVED] Dialer from DefaultOptions
  • Loading branch information
kozlovic authored Aug 8, 2017
2 parents 43abfaa + d6ee894 commit 29f9728
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
7 changes: 2 additions & 5 deletions nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ var (
ErrStaleConnection = errors.New("nats: " + STALE_CONNECTION)
)

// GetDefaultOptions returns default configuration options for the client.
func GetDefaultOptions() Options {
opts := Options{
return Options{
AllowReconnect: true,
MaxReconnect: DefaultMaxReconnect,
ReconnectWait: DefaultReconnectWait,
Expand All @@ -89,11 +90,7 @@ func GetDefaultOptions() Options {
MaxPingsOut: DefaultMaxPingOut,
SubChanLen: DefaultMaxChanLen,
ReconnectBufSize: DefaultReconnectBufSize,
Dialer: &net.Dialer{
Timeout: DefaultTimeout,
},
}
return opts
}

// DEPRECATED: Use GetDefaultOptions() instead.
Expand Down
24 changes: 24 additions & 0 deletions test/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,30 @@ func TestUseCustomDialer(t *testing.T) {
}
}

func TestDefaultOptionsDialer(t *testing.T) {
s := RunDefaultServer()
defer s.Shutdown()

opts1 := nats.DefaultOptions
opts2 := nats.DefaultOptions

nc1, err := opts1.Connect()
if err != nil {
t.Fatalf("Unexpected error on connect: %v", err)
}
defer nc1.Close()

nc2, err := opts2.Connect()
if err != nil {
t.Fatalf("Unexpected error on connect: %v", err)
}
defer nc2.Close()

if nc1.Opts.Dialer == nc2.Opts.Dialer {
t.Fatalf("Expected each connection to have its own dialer")
}
}

func TestCustomFlusherTimeout(t *testing.T) {
s := RunDefaultServer()
defer s.Shutdown()
Expand Down

0 comments on commit 29f9728

Please sign in to comment.