summaryrefslogtreecommitdiffhomepage
path: root/server/fsm_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/fsm_test.go')
-rw-r--r--server/fsm_test.go51
1 files changed, 50 insertions, 1 deletions
diff --git a/server/fsm_test.go b/server/fsm_test.go
index 21659600..c0159d22 100644
--- a/server/fsm_test.go
+++ b/server/fsm_test.go
@@ -17,6 +17,7 @@ package server
import (
"fmt"
+ log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"github.com/stretchr/testify/assert"
@@ -39,7 +40,7 @@ type MockConnection struct {
func NewMockConnection() *MockConnection {
m := &MockConnection{
recvCh: make(chan chan byte, 128),
- sendBuf: make([][]byte, 128),
+ sendBuf: make([][]byte, 0),
isClosed: false,
}
return m
@@ -236,6 +237,54 @@ func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) {
assert.Equal(uint8(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED), sent.Body.(*bgp.BGPNotification).ErrorCode)
}
+func TestFSMHandlerOpenconfirm_HoldtimeZero(t *testing.T) {
+ log.SetLevel(log.DebugLevel)
+ assert := assert.New(t)
+ m := NewMockConnection()
+
+ p, h := makePeerAndHandler()
+
+ // push mock connection
+ p.fsm.passiveConn = m
+
+ // set up keepalive ticker
+ p.fsm.peerConfig.Timers.KeepaliveInterval = 1
+ // set holdtime
+ p.fsm.negotiatedHoldTime = 0
+ go h.openconfirm()
+
+ time.Sleep(100 * time.Millisecond)
+
+ assert.False(h.holdTimer.Stop())
+ assert.Equal(0, len(m.sendBuf))
+
+}
+
+func TestFSMHandlerEstablished_HoldtimeZero(t *testing.T) {
+ log.SetLevel(log.DebugLevel)
+ assert := assert.New(t)
+ m := NewMockConnection()
+
+ p, h := makePeerAndHandler()
+
+ // push mock connection
+ p.fsm.passiveConn = m
+
+ // set up keepalive ticker
+ sec := time.Second * 1
+ p.fsm.keepaliveTicker = time.NewTicker(sec)
+ p.fsm.keepaliveTicker.Stop()
+
+ // set holdtime
+ p.fsm.negotiatedHoldTime = 0
+ go h.established()
+
+ time.Sleep(100 * time.Millisecond)
+
+ assert.False(h.holdTimer.Stop())
+ assert.Equal(0, len(m.sendBuf))
+}
+
func makePeerAndHandler() (*Peer, *FSMHandler) {
globalConfig := config.GlobalType{}
neighborConfig := config.NeighborType{}