Skip to content

Commit

Permalink
pathmgr: fix flaky unit test (#2159)
Browse files Browse the repository at this point in the history
Also make test run faster by deleting deprecated sleeps.
  • Loading branch information
scrye authored Nov 27, 2018
1 parent a340442 commit 24c1989
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions go/lib/pathmgr/pathmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,22 @@ import (
func TestQuery(t *testing.T) {
Convey("Query, we have 0 paths and SCIOND is asked again, receive 1 path", t, func() {
g := graph.NewDefaultGraph()
pm := NewPR(t, g, 250, 250, 100)
pm := NewPR(t, g, 0, 0)
srcIA := xtest.MustParseIA("1-ff00:0:133")
dstIA := xtest.MustParseIA("1-ff00:0:131")

aps := pm.Query(context.Background(), srcIA, dstIA)
SoMsg("aps len", len(aps), ShouldEqual, 1)
Convey("Query immediately, same path is read from cache", func() {
Convey("Query immediately, get paths", func() {
aps := pm.Query(context.Background(), srcIA, dstIA)
SoMsg("aps len", len(aps), ShouldEqual, 1)
SoMsg("path", getPathStrings(aps), ShouldContain,
"[1-ff00:0:133#1019 1-ff00:0:132#1910 "+
"1-ff00:0:132#1916 1-ff00:0:131#1619]")
})
Convey("Wait 200ms for paths to expire, then query and get new paths", func() {
Convey("Then query again and get new paths", func() {
// Add new path between 1-ff00:0:133 and 1-ff00:0:131
g.AddLink("1-ff00:0:133", 101902, "1-ff00:0:132", 191002, false)
// Wait for two seconds to guarantee that the pathmgr refreshes the paths
<-time.After(200 * time.Millisecond)
aps := pm.Query(context.Background(), srcIA, dstIA)
SoMsg("aps len", len(aps), ShouldEqual, 2)
SoMsg("path #1", getPathStrings(aps), ShouldContain,
Expand All @@ -73,7 +71,7 @@ var denyEntry = &pathpol.ACLEntry{Action: pathpol.Deny, Rule: pathpol.NewHopPred

func TestQueryFilter(t *testing.T) {
g := graph.NewDefaultGraph()
pm := NewPR(t, g, 0, 0, 0)
pm := NewPR(t, g, 0, 0)
srcIA := xtest.MustParseIA("1-ff00:0:133")
dstIA := xtest.MustParseIA("1-ff00:0:131")
Convey("Query with policy filter, only one path should remain, default deny", t, func() {
Expand Down Expand Up @@ -117,7 +115,7 @@ func TestQueryFilter(t *testing.T) {
func TestACLPolicyFilter(t *testing.T) {
Convey("Query with ACL policy filter", t, func() {
g := graph.NewDefaultGraph()
pm := NewPR(t, g, 0, 0, 0)
pm := NewPR(t, g, 0, 0)
srcIA := xtest.MustParseIA("2-ff00:0:222")
dstIA := xtest.MustParseIA("1-ff00:0:131")
pp, _ := pathpol.HopPredicateFromString("1-ff00:0:121#0")
Expand All @@ -133,7 +131,7 @@ func TestACLPolicyFilter(t *testing.T) {
})
Convey("Query with longer ACL policy filter", t, func() {
g := graph.NewDefaultGraph()
pm := NewPR(t, g, 0, 0, 0)
pm := NewPR(t, g, 0, 0)
srcIA := xtest.MustParseIA("2-ff00:0:222")
dstIA := xtest.MustParseIA("1-ff00:0:131")
pp, _ := pathpol.HopPredicateFromString("1-ff00:0:121#0")
Expand Down Expand Up @@ -204,8 +202,8 @@ func TestWatchPolling(t *testing.T) {
xtest.FailOnErr(t, err)
Convey("there are 0 paths currently available", func() {
So(len(sp.Load().APS), ShouldEqual, 0)
Convey("and waiting for 10ms grabs new paths", func() {
time.Sleep(10 * time.Millisecond)
Convey("and after waiting, we get new paths.", func() {
time.Sleep(20 * time.Millisecond)
So(len(sp.Load().APS), ShouldEqual, 1)
})
})
Expand Down Expand Up @@ -244,8 +242,8 @@ func TestWatchFilter(t *testing.T) {
xtest.FailOnErr(t, err)
Convey("there are 0 paths due to filtering", func() {
So(len(sp.Load().APS), ShouldEqual, 0)
Convey("and waiting for 10ms grabs 1 path that is not filtered", func() {
time.Sleep(10 * time.Millisecond)
Convey("and after waiting, we get 1 path that is not filtered.", func() {
time.Sleep(20 * time.Millisecond)
So(len(sp.Load().APS), ShouldEqual, 1)
})
})
Expand Down Expand Up @@ -357,7 +355,8 @@ func newTestRev(t *testing.T, rev string) *path_mgmt.SignedRevInfo {
return signedRevInfo
}

func NewPR(t *testing.T, g *graph.Graph, normalRefire, errorRefire, maxAge int) Resolver {
func NewPR(t *testing.T, g *graph.Graph, normalRefire, errorRefire time.Duration) Resolver {

t.Helper()

mockConn, err := sciond.NewMockService(g).Connect()
Expand All @@ -366,8 +365,8 @@ func NewPR(t *testing.T, g *graph.Graph, normalRefire, errorRefire, maxAge int)
return New(
mockConn,
Timers{
NormalRefire: time.Duration(normalRefire) * time.Millisecond,
ErrorRefire: time.Duration(errorRefire) * time.Millisecond,
NormalRefire: normalRefire,
ErrorRefire: errorRefire,
},
log.Root(),
)
Expand Down

0 comments on commit 24c1989

Please sign in to comment.