From 8c7772f5d5a55d52cca2d4e8593f5884cdb6ea2a Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Thu, 24 Nov 2016 14:29:50 +0900 Subject: server: add unit test to check NumGoroutine with Neighbor configuration Signed-off-by: FUJITA Tomonori --- server/server_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'server') diff --git a/server/server_test.go b/server/server_test.go index c9f142f1..73eadb0a 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -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()) +} -- cgit v1.2.3