Skip to content

Commit

Permalink
tests for binary message support and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Oct 18, 2018
1 parent 98ea130 commit 43efde4
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Options:
-d The call data as stringified JSON.
If the value is '@' then the request contents are read from stdin.
-D Path for call data JSON file. For example, /home/user/file.json or ./file.json.
-b The call data comes as serialized binary message read from stdin.
-B Path for the call data as serialized binary message.
-m Request metadata as stringified JSON.
-M Path for call metadata JSON file. For example, /home/user/metadata.json or ./metadata.json.
Expand Down
75 changes: 75 additions & 0 deletions requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"

"github.com/bojand/ghz/internal/helloworld"
Expand Down Expand Up @@ -141,6 +142,36 @@ func TestRequesterUnary(t *testing.T) {
}()
wg.Wait()
})

t.Run("test report binary", func(t *testing.T) {
gs.ResetCounters()

msg := &helloworld.HelloRequest{}
msg.Name = "bob"

binData, err := proto.Marshal(msg)

reqr, err := New(md, &Options{
Host: localhost,
N: 5,
C: 1,
Timeout: 20,
DialTimtout: 20,
BinData: binData,
Binary: true,
Insecure: true,
})
assert.NoError(t, err)

report, err := reqr.Run()
assert.NoError(t, err)
assert.NotNil(t, report)
assert.Equal(t, 5, int(report.Count))
assert.Len(t, report.ErrorDist, 0)

count := gs.GetCount(callType)
assert.Equal(t, 5, count)
})
}

func TestRequesterServerStreaming(t *testing.T) {
Expand Down Expand Up @@ -231,6 +262,50 @@ func TestRequesterClientStreaming(t *testing.T) {
assert.Equal(t, 16, count)
}

func TestRequesterClientStreamingBinary(t *testing.T) {
callType := helloworld.ClientStream

gs, s, err := startServer(false)

if err != nil {
assert.FailNow(t, err.Error())
}

defer s.Stop()

md, err := protodesc.GetMethodDescFromProto("helloworld.Greeter.SayHelloCS", "./testdata/greeter.proto", []string{})

msg := &helloworld.HelloRequest{}
msg.Name = "bob"

binData, err := proto.Marshal(msg)

gs.ResetCounters()

reqr, err := New(md, &Options{
Host: localhost,
N: 24,
C: 4,
Timeout: 20,
DialTimtout: 20,
BinData: binData,
Binary: true,
Insecure: true,
})
assert.NoError(t, err)

report, err := reqr.Run()
assert.NoError(t, err)
assert.NotNil(t, report)
assert.Equal(t, 24, int(report.Count))
assert.True(t, len(report.LatencyDistribution) > 1)
assert.True(t, len(report.Histogram) > 1)
assert.Len(t, report.ErrorDist, 0)

count := gs.GetCount(callType)
assert.Equal(t, 24, count)
}

func TestRequesterBidi(t *testing.T) {
callType := helloworld.Bidi

Expand Down
Loading

0 comments on commit 43efde4

Please sign in to comment.