Skip to content

Commit 8b0ff37

Browse files
Merge branch 'bg-connect' of https://github.com/hyperledger/firefly-common into bg-connect
2 parents 88b1ccd + 1a217bc commit 8b0ff37

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/wsclient/wsconfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func GenerateConfig(ctx context.Context, conf config.Section) (*WSConfig, error)
9494
MaximumDelay: conf.GetDuration(ffresty.HTTPConfigRetryMaxDelay),
9595
DelayFactor: conf.GetFloat64(WSConfigDelayFactor),
9696
InitialConnectAttempts: conf.GetInt(WSConfigKeyInitialConnectAttempts),
97+
BackgroundConnect: conf.GetBool(WSConfigKeyBackgroundConnect),
9798
HTTPHeaders: conf.GetObject(ffresty.HTTPConfigHeaders),
9899
AuthUsername: conf.GetString(ffresty.HTTPConfigAuthUsername),
99100
AuthPassword: conf.GetString(ffresty.HTTPConfigAuthPassword),

pkg/wsclient/wsconfig_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func TestWSConfigGeneration(t *testing.T) {
3333
utConf.Set(WSConfigKeyWriteBufferSize, 1024)
3434
utConf.Set(WSConfigKeyInitialConnectAttempts, 1)
3535
utConf.Set(WSConfigKeyPath, "/websocket")
36+
utConf.Set(WSConfigKeyBackgroundConnect, true)
37+
utConf.Set(WSConfigKeyHeartbeatInterval, "42ms")
3638

3739
ctx := context.Background()
3840
wsConfig, err := GenerateConfig(ctx, utConf)
@@ -48,6 +50,20 @@ func TestWSConfigGeneration(t *testing.T) {
4850
assert.Equal(t, "custom value", wsConfig.HTTPHeaders.GetString("custom-header"))
4951
assert.Equal(t, 1024, wsConfig.ReadBufferSize)
5052
assert.Equal(t, 1024, wsConfig.WriteBufferSize)
53+
assert.True(t, wsConfig.BackgroundConnect)
54+
assert.Equal(t, 42*time.Millisecond, wsConfig.HeartbeatInterval)
55+
}
56+
57+
func TestWSConfigGenerationDefaults(t *testing.T) {
58+
resetConf()
59+
60+
ctx := context.Background()
61+
wsConfig, err := GenerateConfig(ctx, utConf)
62+
assert.NoError(t, err)
63+
64+
assert.Equal(t, defaultInitialConnectAttempts, wsConfig.InitialConnectAttempts)
65+
assert.False(t, wsConfig.BackgroundConnect)
66+
assert.Equal(t, 30*time.Second, wsConfig.HeartbeatInterval)
5167
}
5268

5369
func TestWSConfigTLSGenerationFail(t *testing.T) {

0 commit comments

Comments
 (0)