server: add unit test to check NumGoroutine with Neighbor configuration

Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
FUJITA Tomonori
2016-11-24 14:29:50 +09:00
parent daca3cf3bc
commit 8c7772f5d5
+38
View File
@@ -21,6 +21,7 @@ import (
"github.com/osrg/gobgp/packet/bgp"
"github.com/osrg/gobgp/table"
"github.com/stretchr/testify/assert"
"runtime"
"testing"
"time"
)
@@ -144,3 +145,40 @@ func TestMonitor(test *testing.T) {
//stop the watcher still having an item.
w.Stop()
}
func TestNumGoroutineWithAddDeleteNeighbor(t *testing.T) {
assert := assert.New(t)
s := NewBgpServer()
go s.Serve()
err := s.Start(&config.Global{
Config: config.GlobalConfig{
As: 1,
RouterId: "1.1.1.1",
Port: -1,
},
})
assert.Nil(err)
num := runtime.NumGoroutine()
n := &config.Neighbor{
Config: config.NeighborConfig{
NeighborAddress: "127.0.0.1",
PeerAs: 2,
},
Transport: config.Transport{
Config: config.TransportConfig{
PassiveMode: true,
},
},
}
err = s.AddNeighbor(n)
assert.Nil(err)
err = s.DeleteNeighbor(n)
assert.Nil(err)
// wait goroutines to finish (e.g. internal goroutine for
// InfiniteChannel)
time.Sleep(time.Second * 5)
assert.Equal(num, runtime.NumGoroutine())
}