Fix the router test; get rid of time dependency (#964)

This commit is contained in:
Milos Gajdos 2019-11-20 14:53:12 +00:00 committed by Asim Aslam
parent c87a58db0a
commit 55252cbc32

View File

@ -75,12 +75,14 @@ func TestRouterAdvertise(t *testing.T) {
var advertErr error var advertErr error
createDone := make(chan bool)
errChan := make(chan error) errChan := make(chan error)
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
go func() { go func() {
wg.Done() wg.Done()
defer close(createDone)
for _, route := range routes { for _, route := range routes {
log.Debugf("Creating route %v", route) log.Debugf("Creating route %v", route)
if err := r.Table().Create(route); err != nil { if err := r.Table().Create(route); err != nil {
@ -92,13 +94,13 @@ func TestRouterAdvertise(t *testing.T) {
}() }()
var adverts int var adverts int
doneChan := make(chan bool) readDone := make(chan bool)
wg.Add(1) wg.Add(1)
go func() { go func() {
defer func() { defer func() {
wg.Done() wg.Done()
doneChan <- true readDone <- true
}() }()
for advert := range ch { for advert := range ch {
select { select {
@ -113,7 +115,10 @@ func TestRouterAdvertise(t *testing.T) {
} }
}() }()
<-doneChan // done adding routes to routing table
<-createDone
// done reading adverts from the routing table
<-readDone
if adverts != nrRoutes { if adverts != nrRoutes {
t.Errorf("Expected %d adverts, received: %d", nrRoutes, adverts) t.Errorf("Expected %d adverts, received: %d", nrRoutes, adverts)