Subsfailure case internal delete and retry in duplicate cause case
Remove deadcode

Change-Id: I1dec5ff890174e3bbb246ad1d9a2f391c3bda97e
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go
index c0d76e2..a9339c2 100644
--- a/pkg/control/ut_messaging_test.go
+++ b/pkg/control/ut_messaging_test.go
@@ -672,6 +672,12 @@
 //     |              |      SubFail |
 //     |              |<-------------|
 //     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |              |              |
 //     |      SubFail |              |
 //     |<-------------|              |
 //     |              |              |
@@ -685,11 +691,173 @@
 	// Xapp: Send SubsReq
 	cretrans := xappConn1.SendSubsReq(t, nil, nil)
 
-	// E2t: Receive SubsReq and send SubsFail
-	crereq, cremsg := e2termConn1.RecvSubsReq(t)
-	fparams := &teststube2ap.E2StubSubsFailParams{}
-	fparams.Set(crereq)
-	e2termConn1.SendSubsFail(t, fparams, cremsg)
+	// E2t: Receive SubsReq and send SubsFail (first)
+	crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
+	fparams1 := &teststube2ap.E2StubSubsFailParams{}
+	fparams1.Set(crereq1)
+	e2termConn1.SendSubsFail(t, fparams1, cremsg1)
+
+	// E2t: Receive SubsDelReq and send SubsDelResp (internal first)
+	delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t)
+	e2termConn1.SendSubsDelResp(t, delreq1, delmsg1)
+
+	// Xapp: Receive SubsFail
+	e2SubsId := xappConn1.RecvSubsFail(t, cretrans)
+
+	// Wait that subs is cleaned
+	mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+	xappConn1.TestMsgChanEmpty(t)
+	xappConn2.TestMsgChanEmpty(t)
+	e2termConn1.TestMsgChanEmpty(t)
+	mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestSubReqSubFailRespInSubmgrWithDuplicate
+//
+//   stub                          stub
+// +-------+     +---------+    +---------+
+// | xapp  |     | submgr  |    | e2term  |
+// +-------+     +---------+    +---------+
+//     |              |              |
+//     |  SubReq      |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubReq       |
+//     |              |------------->|
+//     |              |              |
+//     |              |      SubFail |
+//     |              |<-------------|
+//     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |              |              |
+//     |              | SubReq       |
+//     |              |------------->|
+//     |              |              |
+//     |              |      SubResp |
+//     |              |<-------------|
+//     |              |              |
+//     |      SubResp |              |
+//     |<-------------|              |
+//     |              |              |
+//     |         [SUBS DELETE]       |
+//     |              |              |
+//
+//-----------------------------------------------------------------------------
+
+func TestSubReqSubFailRespInSubmgrWithDuplicate(t *testing.T) {
+
+	CaseBegin("TestSubReqSubFailRespInSubmgrWithDuplicate start")
+
+	// Xapp: Send SubsReq
+	cretrans := xappConn1.SendSubsReq(t, nil, nil)
+
+	// E2t: Receive SubsReq and send SubsFail (first)
+	crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
+	fparams1 := &teststube2ap.E2StubSubsFailParams{}
+	fparams1.Set(crereq1)
+	fparams1.SetCauseVal(-1, 5, 3)
+	e2termConn1.SendSubsFail(t, fparams1, cremsg1)
+
+	// E2t: Receive SubsDelReq and send SubsDelResp (internal)
+	delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t)
+	e2termConn1.SendSubsDelResp(t, delreq1, delmsg1)
+
+	// E2t: Receive SubsReq and send SubsResp (second)
+	crereq2, cremsg2 := e2termConn1.RecvSubsReq(t)
+	e2termConn1.SendSubsResp(t, crereq2, cremsg2)
+
+	// XAPP: Receive SubsResp
+	e2SubsId := xappConn1.RecvSubsResp(t, cretrans)
+
+	// Delete
+	deltrans2 := xappConn1.SendSubsDelReq(t, nil, e2SubsId)
+	delreq2, delmsg2 := e2termConn1.RecvSubsDelReq(t)
+	e2termConn1.SendSubsDelResp(t, delreq2, delmsg2)
+	xappConn1.RecvSubsDelResp(t, deltrans2)
+
+	// Wait that subs is cleaned
+	mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+	xappConn1.TestMsgChanEmpty(t)
+	xappConn2.TestMsgChanEmpty(t)
+	e2termConn1.TestMsgChanEmpty(t)
+	mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestSubReqSubFailRespInSubmgrWithDuplicateFail
+//
+//   stub                          stub
+// +-------+     +---------+    +---------+
+// | xapp  |     | submgr  |    | e2term  |
+// +-------+     +---------+    +---------+
+//     |              |              |
+//     |  SubReq      |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubReq       |
+//     |              |------------->|
+//     |              |              |
+//     |              |      SubFail |
+//     |              |<-------------|
+//     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |              |              |
+//     |              | SubReq       |
+//     |              |------------->|
+//     |              |              |
+//     |              |      SubFail |
+//     |              |<-------------|
+//     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |      SubFail |              |
+//     |<-------------|              |
+//     |              |              |
+//
+//-----------------------------------------------------------------------------
+
+func TestSubReqSubFailRespInSubmgrWithDuplicateFail(t *testing.T) {
+
+	CaseBegin("TestSubReqSubFailRespInSubmgrWithDuplicateFail start")
+
+	// Xapp: Send SubsReq
+	cretrans := xappConn1.SendSubsReq(t, nil, nil)
+
+	// E2t: Receive SubsReq and send SubsFail (first)
+	crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
+	fparams1 := &teststube2ap.E2StubSubsFailParams{}
+	fparams1.Set(crereq1)
+	fparams1.SetCauseVal(-1, 5, 3)
+	e2termConn1.SendSubsFail(t, fparams1, cremsg1)
+
+	// E2t: Receive SubsDelReq and send SubsDelResp (internal first)
+	delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t)
+	e2termConn1.SendSubsDelResp(t, delreq1, delmsg1)
+
+	// E2t: Receive SubsReq and send SubsFail (second)
+	crereq2, cremsg2 := e2termConn1.RecvSubsReq(t)
+	fparams2 := &teststube2ap.E2StubSubsFailParams{}
+	fparams2.Set(crereq2)
+	fparams2.SetCauseVal(-1, 5, 3)
+	e2termConn1.SendSubsFail(t, fparams2, cremsg2)
+
+	// E2t: Receive SubsDelReq and send SubsDelResp (internal second)
+	delreq2, delmsg2 := e2termConn1.RecvSubsDelReq(t)
+	e2termConn1.SendSubsDelResp(t, delreq2, delmsg2)
 
 	// Xapp: Receive SubsFail
 	e2SubsId := xappConn1.RecvSubsFail(t, cretrans)
@@ -1071,6 +1239,12 @@
 //     |--------------------------->|              |
 //     |             |              |    SubFail1  |
 //     |             |              |<-------------|
+//     |             |              |              |
+//     |             |              | SubDelReq    |
+//     |             |              |------------->|
+//     |             |              |   SubDelResp |
+//     |             |              |<-------------|
+//     |             |              |              |
 //     |             |    SubFail1  |              |
 //     |             |<-------------|              |
 //     |             |              |              |
@@ -1085,6 +1259,8 @@
 	rparams1 := &teststube2ap.E2StubSubsReqParams{}
 	rparams1.Init()
 	cretrans1 := xappConn1.SendSubsReq(t, rparams1, nil)
+
+	// E2t: Receive SubsReq (first)
 	crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
 
 	//Req2
@@ -1094,10 +1270,14 @@
 	cretrans2 := xappConn2.SendSubsReq(t, rparams2, nil)
 	mainCtrl.wait_msgcounter_change(t, seqBef2, 10)
 
-	//E2T Fail
-	fparams := &teststube2ap.E2StubSubsFailParams{}
-	fparams.Set(crereq1)
-	e2termConn1.SendSubsFail(t, fparams, cremsg1)
+	// E2t: send SubsFail (first)
+	fparams1 := &teststube2ap.E2StubSubsFailParams{}
+	fparams1.Set(crereq1)
+	e2termConn1.SendSubsFail(t, fparams1, cremsg1)
+
+	// E2t: internal delete
+	delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+	e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
 	//Fail1
 	e2SubsId1 := xappConn1.RecvSubsFail(t, cretrans1)