diff --git a/internal/blockchain/ethereum/ethereum.go b/internal/blockchain/ethereum/ethereum.go index ced0be73b1..b249a937a4 100644 --- a/internal/blockchain/ethereum/ethereum.go +++ b/internal/blockchain/ethereum/ethereum.go @@ -302,6 +302,7 @@ func (e *Ethereum) handleMessageBatch(ctx context.Context, messages []interface{ } func (e *Ethereum) eventLoop() { + defer e.wsconn.Close() defer close(e.closed) l := log.L(e.ctx).WithField("role", "event-loop") ctx := log.WithLogger(e.ctx, l) diff --git a/internal/blockchain/ethereum/ethereum_test.go b/internal/blockchain/ethereum/ethereum_test.go index ea868e4f79..0915171c17 100644 --- a/internal/blockchain/ethereum/ethereum_test.go +++ b/internal/blockchain/ethereum/ethereum_test.go @@ -804,6 +804,7 @@ func TestEventLoopContextCancelled(t *testing.T) { r := make(<-chan []byte) wsm := e.wsconn.(*wsmocks.WSClient) wsm.On("Receive").Return(r) + wsm.On("Close").Return() e.closed = make(chan struct{}) e.eventLoop() // we're simply looking for it exiting } @@ -815,6 +816,7 @@ func TestEventLoopReceiveClosed(t *testing.T) { wsm := e.wsconn.(*wsmocks.WSClient) close(r) wsm.On("Receive").Return((<-chan []byte)(r)) + wsm.On("Close").Return() e.closed = make(chan struct{}) e.eventLoop() // we're simply looking for it exiting } @@ -827,6 +829,7 @@ func TestEventLoopSendClosed(t *testing.T) { close(r) wsm.On("Receive").Return((<-chan []byte)(r)) wsm.On("Send", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) + wsm.On("Close").Return() e.closed = make(chan struct{}) e.eventLoop() // we're simply looking for it exiting } @@ -887,6 +890,7 @@ func TestHandleBadPayloadsAndThenReceiptFailure(t *testing.T) { e.closed = make(chan struct{}) wsm.On("Receive").Return((<-chan []byte)(r)) + wsm.On("Close").Return() operationID := fftypes.NewUUID() data := []byte(`{ "_id": "6fb94fff-81d3-4094-567d-e031b1871694", diff --git a/internal/blockchain/fabric/fabric.go b/internal/blockchain/fabric/fabric.go index 0b4bc4f037..9450357eb8 100644 --- a/internal/blockchain/fabric/fabric.go +++ b/internal/blockchain/fabric/fabric.go @@ -342,6 +342,7 @@ func (f *Fabric) handleMessageBatch(ctx context.Context, messages []interface{}) } func (f *Fabric) eventLoop() { + defer f.wsconn.Close() defer close(f.closed) l := log.L(f.ctx).WithField("role", "event-loop") ctx := log.WithLogger(f.ctx, l) diff --git a/internal/blockchain/fabric/fabric_test.go b/internal/blockchain/fabric/fabric_test.go index efe749ed7a..2fcbcd9f6e 100644 --- a/internal/blockchain/fabric/fabric_test.go +++ b/internal/blockchain/fabric/fabric_test.go @@ -798,6 +798,7 @@ func TestEventLoopContextCancelled(t *testing.T) { r := make(<-chan []byte) wsm := e.wsconn.(*wsmocks.WSClient) wsm.On("Receive").Return(r) + wsm.On("Close").Return() e.closed = make(chan struct{}) e.eventLoop() // we're simply looking for it exiting } @@ -809,6 +810,7 @@ func TestEventLoopReceiveClosed(t *testing.T) { wsm := e.wsconn.(*wsmocks.WSClient) close(r) wsm.On("Receive").Return((<-chan []byte)(r)) + wsm.On("Close").Return() e.closed = make(chan struct{}) e.eventLoop() // we're simply looking for it exiting } @@ -820,6 +822,7 @@ func TestEventLoopSendClosed(t *testing.T) { wsm := e.wsconn.(*wsmocks.WSClient) close(r) wsm.On("Receive").Return((<-chan []byte)(r)) + wsm.On("Close").Return() wsm.On("Send", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) e.closed = make(chan struct{}) e.eventLoop() // we're simply looking for it exiting @@ -831,6 +834,7 @@ func TestEventLoopUnexpectedMessage(t *testing.T) { r := make(chan []byte) wsm := e.wsconn.(*wsmocks.WSClient) wsm.On("Receive").Return((<-chan []byte)(r)) + wsm.On("Close").Return() e.closed = make(chan struct{}) operationID := fftypes.NewUUID() data := []byte(`{ diff --git a/internal/config/config.go b/internal/config/config.go index 3be23a2451..089c7b83c6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -479,7 +479,7 @@ func (c *configPrefix) Array() PrefixArray { func (c *configPrefixArray) ArraySize() int { val := viper.Get(c.base) vt := reflect.TypeOf(val) - if vt != nil && vt.Kind() == reflect.Slice { + if vt != nil && (vt.Kind() == reflect.Slice || vt.Kind() == reflect.Map) { return reflect.ValueOf(val).Len() } return 0 diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 9e2c61ae43..240af2c8d5 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -146,6 +146,31 @@ tokens: assert.Equal(t, []string{"arr1", "arr2"}, sally.GetStringSlice("key2")) } +func TestMapOfAdminOverridePlugins(t *testing.T) { + defer Reset() + + tokPlugins := NewPluginConfig("tokens").Array() + tokPlugins.AddKnownKey("firstkey") + tokPlugins.AddKnownKey("secondkey") + viper.SetConfigType("json") + err := viper.ReadConfig(strings.NewReader(`{ + "tokens": { + "0": { + "firstkey": "firstitemfirstkeyvalue", + "secondkey": "firstitemsecondkeyvalue" + }, + "1": { + "firstkey": "seconditemfirstkeyvalue", + "secondkey": "seconditemsecondkeyvalue" + } + } + }`)) + assert.NoError(t, err) + assert.Equal(t, 2, tokPlugins.ArraySize()) + assert.Equal(t, "firstitemfirstkeyvalue", tokPlugins.ArrayEntry(0).Get("firstkey")) + assert.Equal(t, "seconditemsecondkeyvalue", tokPlugins.ArrayEntry(1).Get("secondkey")) +} + func TestGetKnownKeys(t *testing.T) { knownKeys := GetKnownKeys() assert.NotEmpty(t, knownKeys)