@@ -148,7 +148,7 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
148
148
return & errTimeout {}
149
149
}
150
150
151
- setUpWithError := func (customErr error , opts ... ably.ClientOption ) (visitedHosts []string ) {
151
+ initClientWithConnError := func (customErr error , opts ... ably.ClientOption ) (visitedHosts []string ) {
152
152
client , err := ably .NewRealtime (append (opts , ably .WithAutoConnect (false ), ably .WithKey ("fake:key" ),
153
153
ably .WithDial (func (protocol string , u * url.URL , timeout time.Duration ) (ably.Conn , error ) {
154
154
visitedHosts = append (visitedHosts , u .Hostname ())
@@ -160,15 +160,15 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
160
160
}
161
161
162
162
t .Run ("RTN17a: First attempt should be made on default primary host" , func (t * testing.T ) {
163
- visitedHosts := setUpWithError (errors .New ("host url is wrong" ))
163
+ visitedHosts := initClientWithConnError (errors .New ("host url is wrong" ))
164
164
assert .Equal (t , "realtime.ably.io" , visitedHosts [0 ])
165
165
})
166
166
167
167
t .Run ("RTN17b: Fallback behaviour" , func (t * testing.T ) {
168
168
t .Parallel ()
169
169
170
170
t .Run ("apply when default realtime endpoint is not overridden, port/tlsport not set" , func (t * testing.T ) {
171
- visitedHosts := setUpWithError (getTimeoutErr ())
171
+ visitedHosts := initClientWithConnError (getTimeoutErr ())
172
172
expectedPrimaryHost := "realtime.ably.io"
173
173
expectedFallbackHosts := ably .DefaultFallbackHosts ()
174
174
@@ -178,7 +178,7 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
178
178
})
179
179
180
180
t .Run ("does not apply when the custom realtime endpoint is used" , func (t * testing.T ) {
181
- visitedHosts := setUpWithError (getTimeoutErr (), ably .WithRealtimeHost ("custom-realtime.ably.io" ))
181
+ visitedHosts := initClientWithConnError (getTimeoutErr (), ably .WithRealtimeHost ("custom-realtime.ably.io" ))
182
182
expectedHost := "custom-realtime.ably.io"
183
183
184
184
require .Equal (t , 1 , len (visitedHosts ))
@@ -187,7 +187,7 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
187
187
188
188
t .Run ("apply when fallbacks are provided" , func (t * testing.T ) {
189
189
fallbacks := []string {"fallback0" , "fallback1" , "fallback2" }
190
- visitedHosts := setUpWithError (getTimeoutErr (), ably .WithFallbackHosts (fallbacks ))
190
+ visitedHosts := initClientWithConnError (getTimeoutErr (), ably .WithFallbackHosts (fallbacks ))
191
191
expectedPrimaryHost := "realtime.ably.io"
192
192
193
193
assert .Equal (t , 4 , len (visitedHosts ))
@@ -196,7 +196,7 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
196
196
})
197
197
198
198
t .Run ("apply when fallbackHostUseDefault is true, even if env. or host is set" , func (t * testing.T ) {
199
- visitedHosts := setUpWithError (
199
+ visitedHosts := initClientWithConnError (
200
200
getTimeoutErr (),
201
201
ably .WithFallbackHostsUseDefault (true ),
202
202
ably .WithEnvironment ("custom" ),
@@ -215,7 +215,7 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
215
215
t .Parallel ()
216
216
const internetCheckUrl = "https://internet-up.ably-realtime.com/is-the-internet-up.txt"
217
217
rec , optn := ablytest .NewHttpRecorder ()
218
- visitedHosts := setUpWithError (getDNSErr (), optn ... )
218
+ visitedHosts := initClientWithConnError (getDNSErr (), optn ... )
219
219
assert .Equal (t , 6 , len (visitedHosts )) // including primary host
220
220
assert .Equal (t , 5 , len (rec .Requests ()))
221
221
for _ , request := range rec .Requests () {
@@ -224,11 +224,11 @@ func TestRealtime_RTN17_HostFallback(t *testing.T) {
224
224
})
225
225
226
226
t .Run ("RTN17d: Check for compatible errors before attempting to reconnect to a fallback host" , func (t * testing.T ) {
227
- visitedHosts := setUpWithError (fmt .Errorf ("host url is wrong" )) // non-dns or non-timeout error
227
+ visitedHosts := initClientWithConnError (fmt .Errorf ("host url is wrong" )) // non-dns or non-timeout error
228
228
assert .Equal (t , 1 , len (visitedHosts ))
229
- visitedHosts = setUpWithError (getDNSErr ())
229
+ visitedHosts = initClientWithConnError (getDNSErr ())
230
230
assert .Equal (t , 6 , len (visitedHosts ))
231
- visitedHosts = setUpWithError (getTimeoutErr ())
231
+ visitedHosts = initClientWithConnError (getTimeoutErr ())
232
232
assert .Equal (t , 6 , len (visitedHosts ))
233
233
})
234
234
0 commit comments