X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fmanagers%2Fran_reconnection_manager_test.go;h=cd3dc58257ac4ba83df9729649402ffb487adb6e;hb=0e58b60a82f5912f815be9292fe0c072a80b79a7;hp=68c31cead75738142857df5b54b4f5f5350b5925;hpb=2151d81e25b521d1d7f76fee0f286723e9b00913;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/managers/ran_reconnection_manager_test.go b/E2Manager/managers/ran_reconnection_manager_test.go index 68c31ce..cd3dc58 100644 --- a/E2Manager/managers/ran_reconnection_manager_test.go +++ b/E2Manager/managers/ran_reconnection_manager_test.go @@ -32,16 +32,18 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" "github.com/pkg/errors" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "testing" ) -func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) { +func initRanLostConnectionTest(t *testing.T) (*logger.Logger,*mocks.RmrMessengerMock, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) { logger, err := logger.InitLogger(logger.DebugLevel) if err != nil { t.Errorf("#... - failed to initialize logger, error: %s", err) } - rmrService := getRmrService(&mocks.RmrMessengerMock{}, logger) + rmrMessengerMock := &mocks.RmrMessengerMock{} + rmrService := getRmrService(rmrMessengerMock, logger) readerMock := &mocks.RnibReaderMock{} rnibReaderProvider := func() reader.RNibReader { @@ -53,65 +55,109 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderM } ranReconnectionManager := NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibReaderProvider, rnibWriterProvider, rmrService) - return logger, readerMock, writerMock, ranReconnectionManager + return logger,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager } -func TestLostConnectionFetchingNodebFailure(t *testing.T) { - _, readerMock, _, ranReconnectionManager := initRanLostConnectionTest(t) +func TestRanReconnectionGetNodebFailure(t *testing.T) { + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" var nodebInfo *entities.NodebInfo readerMock.On("GetNodeb", ranName).Return(nodebInfo, common.NewInternalError(errors.New("Error"))) err := ranReconnectionManager.ReconnectRan(ranName) assert.NotNil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNotCalled(t, "UpdateNodebInfo") } -func TestLostConnectionUpdatingNodebForUnconnectableRanFailure(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) +func TestShutdownRanReconnection(t *testing.T) { + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) + ranName := "test" + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN} + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + err := ranReconnectionManager.ReconnectRan(ranName) + assert.Nil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNotCalled(t, "UpdateNodebInfo") +} + +func TestShuttingdownRanReconnection(t *testing.T) { + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN - writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error"))) + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr) err := ranReconnectionManager.ReconnectRan(ranName) - assert.NotNil(t, err) + assert.Nil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) } -func TestLostConnectionOfConnectedRanWithMaxAttempts(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) +func TestConnectingRanWithMaxAttemptsReconnection(t *testing.T) { + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED, ConnectionAttempts: 20} - var rnibErr common.IRNibError + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20} + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr) err := ranReconnectionManager.ReconnectRan(ranName) assert.Nil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) } -func TestLostConnectionOfShutdownRan(t *testing.T) { - _, readerMock, _, ranReconnectionManager := initRanLostConnectionTest(t) +func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) { + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN} - var rnibErr common.IRNibError + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo := *origNodebInfo + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error"))) err := ranReconnectionManager.ReconnectRan(ranName) - assert.Nil(t, err) + assert.NotNil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) } -func TestLostConnectionOfShuttingdownRan(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) +func TestConnectedRanExecuteSetupSuccess(t *testing.T) { + _,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} - var rnibErr common.IRNibError + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol:entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST} + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo - updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN - writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr) + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING + updatedNodebInfo.ConnectionAttempts++ + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(nil) + rmrMessengerMock.On("SendMsg",mock.Anything, mock.AnythingOfType("int")).Return(&rmrCgo.MBuf{},nil) err := ranReconnectionManager.ReconnectRan(ranName) assert.Nil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) + rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 1) +} + +func TestConnectedRanExecuteSetupFailure(t *testing.T) { + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) + ranName := "test" + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED} + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo := *origNodebInfo + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING + updatedNodebInfo.ConnectionAttempts++ + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error"))) + err := ranReconnectionManager.ReconnectRan(ranName) + assert.NotNil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) } // TODO: should extract to test_utils