Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Commit

Permalink
Add more test coverage and improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Jan 11, 2017
1 parent c3e50c1 commit c59f1ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pprof/parser.go
Expand Up @@ -198,7 +198,7 @@ func (p *rawParser) addSample(line string) {
funcIDs := p.parseFuncIDs(lineParts[1])

if len(samples) != len(p.columns) {
p.setError(fmt.Errorf("line has more samples (%v) than columns (%v): %v",
p.setError(fmt.Errorf("line has a different sample count (%v) than columns (%v): %v",
len(samples), len(p.columns), line))
return
}
Expand Down
15 changes: 15 additions & 0 deletions pprof/parser_test.go
Expand Up @@ -27,6 +27,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber/go-torch/stack"
)

Expand Down Expand Up @@ -56,6 +57,8 @@ func TestParseMemProfile(t *testing.T) {
func TestParse(t *testing.T) {
_, parser := parseTest1(t)

assert.Equal(t, []string{"samples/count", "cpu/nanoseconds"}, parser.columns)

// line 7 - 249 are stack records in the test file.
const expectedNumRecords = 242
if len(parser.records) != expectedNumRecords {
Expand Down Expand Up @@ -160,6 +163,18 @@ func TestParseMissingSourceLine(t *testing.T) {
}
}

func TestParseSampleCountMismatch(t *testing.T) {
contents := `Samples:
samples/count cpu/nanoseconds alloc_objects/count
2 10000000: 1
Locations:
1: 0xaaaaa funcName :0 s=0
`
_, err := ParseRaw([]byte(contents))
require.Error(t, err, "Expected parseRaw to fail with sample count mismatch")
assert.Contains(t, err.Error(), "different sample count (2) than columns (3)")
}

func testParseRawBad(t *testing.T, errorReason, errorSubstr, contents string) {
_, err := ParseRaw([]byte(contents))
if err == nil {
Expand Down

0 comments on commit c59f1ab

Please sign in to comment.