Fix Go routine race condition in DB notification map
[ric-plt/sdlgo.git] / sdl_test.go
index 832e8eb..b216e57 100644 (file)
    limitations under the License.
 */
 
+/*
+ * This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ * platform project (RICP).
+ */
+
 package sdlgo_test
 
 import (
@@ -24,7 +29,6 @@ import (
        "time"
 
        "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
-       "gerrit.o-ran-sc.org/r/ric-plt/sdlgo/internal/sdlgoredis"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/mock"
 )
@@ -33,7 +37,7 @@ type mockDB struct {
        mock.Mock
 }
 
-func (m *mockDB) SubscribeChannelDB(cb sdlgoredis.ChannelNotificationCb, channelPrefix, eventSeparator string, channels ...string) {
+func (m *mockDB) SubscribeChannelDB(cb func(string, ...string), channelPrefix, eventSeparator string, channels ...string) {
        m.Called(cb, channelPrefix, eventSeparator, channels)
 }
 
@@ -142,7 +146,7 @@ func (m *mockDB) PExpireIE(key string, data interface{}, expiration time.Duratio
 
 func setup() (*mockDB, *sdlgo.SdlInstance) {
        m := new(mockDB)
-       i := sdlgo.NewSdlInstance("namespace", m)
+       i := sdlgo.NewSdlInstanceForTest("namespace", m)
        return m, i
 }
 
@@ -171,7 +175,7 @@ func TestSubscribeChannel(t *testing.T) {
        expectedCB := func(channel string, events ...string) {}
        expectedChannels := []string{"{namespace},channel1", "{namespace},channel2"}
 
-       m.On("SubscribeChannelDB", mock.AnythingOfType("sdlgoredis.ChannelNotificationCb"), "{namespace},", "___", expectedChannels).Return()
+       m.On("SubscribeChannelDB", mock.AnythingOfType("func(string, ...string)"), "{namespace},", "___", expectedChannels).Return()
        i.SubscribeChannel(expectedCB, "channel1", "channel2")
        m.AssertExpectations(t)
 }