Skip to content

Commit

Permalink
Merge pull request #312 from jbub/data-file-empty-panic
Browse files Browse the repository at this point in the history
Avoid panic on empty file provided by --data-file.
  • Loading branch information
bojand authored Sep 25, 2021
2 parents 5ae1b06 + cfd0584 commit 15ea81a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runner/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (dp *dataProvider) getDataForCall(ctd *CallData) ([]*dynamic.Message, error
return nil, err
}

if !dp.mtd.IsClientStreaming() {
if !dp.mtd.IsClientStreaming() && len(inputs) > 0 {
inputIdx := int(ctd.RequestNumber % int64(len(inputs)))
unaryInput := inputs[inputIdx]

Expand Down
33 changes: 33 additions & 0 deletions runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3171,6 +3171,39 @@ func TestRunWrappedUnary(t *testing.T) {
assert.Equal(t, report.Average, report.Slowest)
assert.Equal(t, report.Average, report.Fastest)
})

t.Run("json string data from empty file", func(t *testing.T) {
report, err := Run(
"wrapped.WrappedService.GetMessage",
internal.TestLocalhost,
WithProtoFile("../testdata/wrapped.proto", []string{"../testdata"}),
WithDataFromFile(`../testdata/data_empty.json`),
WithInsecure(true),
)

assert.Error(t, err)

assert.NotNil(t, report)

assert.Equal(t, 0, int(report.Count))
assert.Zero(t, report.Average)
assert.Zero(t, report.Fastest)
assert.Zero(t, report.Slowest)
assert.Zero(t, report.Rps)
assert.Empty(t, report.Name)
assert.NotEmpty(t, report.Date)
assert.NotEmpty(t, report.Options)
assert.Empty(t, report.Details)
assert.Equal(t, true, report.Options.Insecure)
assert.Empty(t, report.LatencyDistribution)
assert.Equal(t, ReasonNormalEnd, report.EndReason)
assert.Empty(t, report.ErrorDist)

assert.Equal(t, report.Average, report.Slowest)
assert.Equal(t, report.Average, report.Fastest)
})


}

func TestRunGtimeUnary(t *testing.T) {
Expand Down
Empty file added testdata/data_empty.json
Empty file.

0 comments on commit 15ea81a

Please sign in to comment.