Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add benchmark tests for LSP rendering call #2

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions lsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/binary"
"encoding/hex"
"math"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -867,15 +868,15 @@ func TestISISBytesToLSP(t *testing.T) {
}
}

func TestRenderLSP(t *testing.T) {
tests := []struct {
name string
inLSP *oc.NetworkInstance_Protocol_Isis_Level_Lsp
inArgs ISISRenderArgs
wantNotifications []*gnmipb.Notification
wantErrSubstring string
}{{
name: "simple example",
type renderLSPTest struct {
inLSP *oc.NetworkInstance_Protocol_Isis_Level_Lsp
inArgs ISISRenderArgs
wantNotifications []*gnmipb.Notification
wantErrSubstring string
}

var renderLSPTests = map[string]*renderLSPTest{
"simple example": {
inLSP: &oc.NetworkInstance_Protocol_Isis_Level_Lsp{
Checksum: ygot.Uint16(48899),
LspId: ygot.String("0000.4000.ce39.02-00"),
Expand Down Expand Up @@ -944,8 +945,8 @@ func TestRenderLSP(t *testing.T) {
}},
Atomic: true,
}},
}, {
name: "larger example",
},
"larger example": {
inLSP: &oc.NetworkInstance_Protocol_Isis_Level_Lsp{
Checksum: ygot.Uint16(32515),
LspId: ygot.String("0000.4000.ce39.00-00"),
Expand Down Expand Up @@ -1307,8 +1308,8 @@ func TestRenderLSP(t *testing.T) {
}},
Atomic: true,
}},
}, {
name: "simple - pathelem path",
},
"simple - pathelem path": {
inLSP: func() *oc.NetworkInstance_Protocol_Isis_Level_Lsp {
l := &oc.NetworkInstance_Protocol_Isis_Level_Lsp{}
l.LspId = ygot.String("0000.4000.ce39.00-00")
Expand Down Expand Up @@ -1346,24 +1347,48 @@ func TestRenderLSP(t *testing.T) {
}},
Atomic: true,
}},
}, {
name: "nil LSP ID",
},
"nil LSP ID": {
inLSP: &oc.NetworkInstance_Protocol_Isis_Level_Lsp{},
wantErrSubstring: "nil LSP ID",
}, {
name: "nil LSP",
},
"nil LSP": {
wantErrSubstring: "nil LSP",
}}
},
}

for _, tt := range tests {
func TestRenderLSP(t *testing.T) {
for name, tt := range renderLSPTests {
got, err := RenderNotifications(tt.inLSP, tt.inArgs)
if diff := errdiff.Substring(err, tt.wantErrSubstring); diff != "" {
t.Errorf("%s: RenderNotifications(%v, %v): got unexpected %s", tt.name, tt.inLSP, tt.inArgs, diff)
t.Errorf("%s: RenderNotifications(%v, %v): got unexpected %s", name, tt.inLSP, tt.inArgs, diff)
}

if !testutil.NotificationSetEqual(got, tt.wantNotifications) {
diff := pretty.Compare(got, tt.wantNotifications)
t.Errorf("%s: RenderNotifications(%v, %v): got incorrect return protos, diff(-got,+want):\n%s", tt.name, tt.inLSP, tt.inArgs, diff)
t.Errorf("%s: RenderNotifications(%v, %v): got incorrect return protos, diff(-got,+want):\n%s", name, tt.inLSP, tt.inArgs, diff)
}
}
}

func benchmarkRenderLSP(b *testing.B, name string, usePathElem bool) {
tt := *renderLSPTests[name]
for i := 0; i != b.N; i++ {
tt.inArgs.UsePathElem = usePathElem
_, err := RenderNotifications(tt.inLSP, tt.inArgs)
if diff := errdiff.Substring(err, tt.wantErrSubstring); diff != "" {
b.Errorf("%s: RenderNotifications(%v, %v): got unexpected %s", name, tt.inLSP, tt.inArgs, diff)
}
}
}

func BenchmarkRenderLSP(b *testing.B) {
benchmarkTests := []string{"simple example", "larger example", "simple - pathelem path"}

for _, usePathElem := range []bool{false, true} {
for _, name := range benchmarkTests {
b.Run(name+"/usePathElem="+strconv.FormatBool(usePathElem),
func(b *testing.B) { benchmarkRenderLSP(b, name, usePathElem) })
}
}
}