diff --git a/protocols/bgp/server/fsm_connect_test.go b/protocols/bgp/server/fsm_connect_test.go deleted file mode 100644 index abf2a66251d819a1c3574f2ae14575b1401652b0..0000000000000000000000000000000000000000 --- a/protocols/bgp/server/fsm_connect_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package server - -import ( - "sync" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestConnectStateManualStop(t *testing.T) { - fsm := &FSM2{ - eventCh: make(chan int), - connectRetryCounter: 100, - connectRetryTimer: time.NewTimer(time.Second * 120), - } - fsm.startConnectRetryTimer() - fsm.state = newConnectState(fsm) - - var wg sync.WaitGroup - var nextState state - var reason string - wg.Add(1) - go func() { - nextState, reason = fsm.state.run() - wg.Done() - }() - - fsm.eventCh <- ManualStop - wg.Wait() - - assert.IsType(t, &idleState{}, nextState, "Unexpected state returned") - assert.Equalf(t, 0, fsm.connectRetryCounter, "Unexpected resetConnectRetryCounter: %d", fsm.connectRetryCounter) -} - -func TestConnectStateConnectRetryTimer(t *testing.T) { - fsm := &FSM2{ - eventCh: make(chan int), - connectRetryTimer: time.NewTimer(time.Second * 120), - } - fsm.startConnectRetryTimer() - fsm.state = newConnectState(fsm) - - var wg sync.WaitGroup - var nextState state - var reason string - wg.Add(1) - go func() { - fsm.connectRetryTimer = time.NewTimer(time.Duration(0)) - nextState, reason = fsm.state.run() - wg.Done() - }() - - wg.Wait() - - assert.IsType(t, &connectState{}, nextState, "Unexpected state returned") -} - -func TestConnectStateConEstablished(t *testing.T) { - fsm := &FSM2{ - eventCh: make(chan int), - connectRetryTimer: time.NewTimer(time.Second * 120), - } - fsm.startConnectRetryTimer() - fsm.state = newConnectState(fsm) - - var wg sync.WaitGroup - var nextState state - var reason string - wg.Add(1) - go func() { - fsm.connectRetryTimer = time.NewTimer(time.Duration(0)) - nextState, reason = fsm.state.run() - wg.Done() - }() - - wg.Wait() - - assert.IsType(t, &connectState{}, nextState, "Unexpected state returned") -} diff --git a/protocols/bgp/server/fsm_idle_test.go b/protocols/bgp/server/fsm_idle_test.go deleted file mode 100644 index 4cb1dff09ae556207fd41616d61e10fccd6ba428..0000000000000000000000000000000000000000 --- a/protocols/bgp/server/fsm_idle_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package server - -import ( - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestNewIdleState(t *testing.T) { - tests := []struct { - name string - fsm *FSM2 - expected *idleState - }{ - { - name: "Test #1", - fsm: &FSM2{}, - expected: &idleState{ - fsm: &FSM2{}, - }, - }, - } - - for _, test := range tests { - res := newIdleState(test.fsm) - assert.Equalf(t, test.expected, res, "Test: %s", test.name) - } -} - -func TestStart(t *testing.T) { - tests := []struct { - name string - state *idleState - expected *idleState - }{ - { - name: "Test #1", - state: &idleState{ - fsm: &FSM2{ - connectRetryCounter: 5, - connectRetryTimer: time.NewTimer(time.Second * 20), - }, - newStateReason: "Foo Bar", - }, - expected: &idleState{ - fsm: &FSM2{ - connectRetryCounter: 0, - connectRetryTimer: time.NewTimer(time.Second * 20), - }, - newStateReason: "Foo Bar", - }, - }, - } - - for _, test := range tests { - if !test.expected.fsm.connectRetryTimer.Stop() { - <-test.expected.fsm.connectRetryTimer.C - } - test.state.start() - assert.Equalf(t, test.expected, test.state, "Test: %s", test.name) - } -}