Skip to content

Commit

Permalink
Try to fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Dec 12, 2019
1 parent ec6d8f1 commit ebc1f84
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"os"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -234,10 +235,15 @@ func TestRouter_handleTransportPacket(t *testing.T) {
}
}

var wg sync.WaitGroup

wg.Add(1)
// TEST: Ensure handleTransportPacket does as expected.
// After setting a rule in r0, r0 should forward a packet to r1 (as specified in the given rule)
// when r0.handleTransportPacket() is called.
t.Run("handlePacket_fwdRule", func(t *testing.T) {
defer wg.Done()

defer clearRules(r0, r1)
defer clearRouteGroups(r0, r1)

Expand All @@ -262,7 +268,10 @@ func TestRouter_handleTransportPacket(t *testing.T) {
assert.Equal(t, routing.RouteID(1), recvPacket.RouteID())
})

wg.Add(1)
t.Run("handlePacket_intFwdRule", func(t *testing.T) {
defer wg.Done()

defer clearRules(r0, r1)
defer clearRouteGroups(r0, r1)

Expand All @@ -286,7 +295,10 @@ func TestRouter_handleTransportPacket(t *testing.T) {
assert.Equal(t, routing.RouteID(5), recvPacket.RouteID())
})

wg.Add(1)
t.Run("handlePacket_cnsmRule", func(t *testing.T) {
defer wg.Done()

defer clearRules(r0, r1)
defer clearRouteGroups(r0, r1)

Expand Down Expand Up @@ -338,7 +350,10 @@ func TestRouter_handleTransportPacket(t *testing.T) {
require.Equal(t, consumeMsg, data)
})

wg.Add(1)
t.Run("handlePacket_close", func(t *testing.T) {
defer wg.Done()

defer clearRules(r0, r1)
defer clearRouteGroups(r0, r1)

Expand All @@ -356,7 +371,10 @@ func TestRouter_handleTransportPacket(t *testing.T) {
require.Len(t, r0.rt.AllRules(), 0)
})

wg.Add(1)
t.Run("handlePacket_keepalive", func(t *testing.T) {
defer wg.Done()

defer clearRules(r0, r1)
defer clearRouteGroups(r0, r1)

Expand All @@ -382,6 +400,8 @@ func TestRouter_handleTransportPacket(t *testing.T) {
time.Sleep(100 * time.Millisecond)
require.Len(t, r0.rt.AllRules(), 0)
})

wg.Wait()
}

func TestRouter_Rules(t *testing.T) {
Expand Down

0 comments on commit ebc1f84

Please sign in to comment.