diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-02-17 18:03:49 +0900 |
---|---|---|
committer | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-02-17 18:32:39 +0900 |
commit | d78c81be224e30ef21ec183e6c97000219683b48 (patch) | |
tree | 03adb5e382fcd21420e21c802184df8602d13161 /server/fsm_test.go | |
parent | 43038c2e96e8ef7bcf2da145446fcd88c3007338 (diff) |
peer: support hold time 0
Diffstat (limited to 'server/fsm_test.go')
-rw-r--r-- | server/fsm_test.go | 51 |
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{} |