Skip to content

Commit

Permalink
binary format "guessing"
Browse files Browse the repository at this point in the history
  • Loading branch information
ezsilmar committed Apr 23, 2019
1 parent b70d4f1 commit b2a6a3e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 47 deletions.
10 changes: 10 additions & 0 deletions runner/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ func createPayloadsFromBinCountDelimited(binData []byte, mtd *desc.MethodDescrip

return &inputs, nil
}

func createPayloadsFromBin(binData []byte, mtd *desc.MethodDescriptor) (*[]*dynamic.Message, error) {
inputs, err := createPayloadsFromBinCountDelimited(binData, mtd)

if err == nil && len(*inputs) > 0 {
return inputs, err
}

return createPayloadsFromBinSingleMessage(binData, mtd)
}
13 changes: 11 additions & 2 deletions runner/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestData_createPayloads(t *testing.T) {

binData, err := proto.Marshal(msg1)

inputs, err := createPayloadsFromBinSingleMessage(binData, mtdUnary)
inputs, err := createPayloadsFromBin(binData, mtdUnary)

assert.NoError(t, err)
assert.NotNil(t, inputs)
Expand All @@ -227,12 +227,21 @@ func TestData_createPayloads(t *testing.T) {
_ = buf.EncodeMessage(msg1)
_ = buf.EncodeMessage(msg2)

inputs, err := createPayloadsFromBinCountDelimited(buf.Bytes(), mtdUnary)
inputs, err := createPayloadsFromBin(buf.Bytes(), mtdUnary)

assert.NoError(t, err)
assert.NotNil(t, inputs)
assert.Len(t, *inputs, 2)
assert.EqualValues(t, msg1.GetName(), (*inputs)[0].GetFieldByName("name"))
assert.EqualValues(t, msg2.GetName(), (*inputs)[1].GetFieldByName("name"))
})

t.Run("on empty binary data returns empty slice", func(t *testing.T) {
buf := make([]byte, 0)
inputs, err := createPayloadsFromBin(buf, mtdUnary)

assert.NoError(t, err)
assert.NotNil(t, inputs)
assert.Len(t, *inputs, 0)
})
}
85 changes: 42 additions & 43 deletions runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,49 +350,48 @@ func TestRunUnary(t *testing.T) {
assert.Equal(t, []string {"0", "1", "2", "0", "1", "2"}, names)
})

// todo fix this test
//t.Run("test round-robin binary", func(t *testing.T) {
// gs.ResetCounters()
//
// buf := proto.Buffer{}
// for i := 0; i < 3; i++ {
// msg := &helloworld.HelloRequest{}
// msg.Name = strconv.Itoa(i)
// err = buf.EncodeMessage(msg)
// assert.NoError(t, err)
// }
// binData := buf.Bytes()
//
// report, err := Run(
// "helloworld.Greeter.SayHello",
// internal.TestLocalhost,
// WithProtoFile("../testdata/greeter.proto", []string{}),
// WithTotalRequests(6),
// WithConcurrency(1),
// WithTimeout(time.Duration(20*time.Second)),
// WithDialTimeout(time.Duration(20*time.Second)),
// WithInsecure(true),
// WithBinaryDataCountDelimited(binData),
// )
//
// assert.NoError(t, err)
// assert.NotNil(t, report)
//
// count := gs.GetCount(callType)
// assert.Equal(t, 6, count)
//
// calls := gs.GetCalls(callType)
// assert.NotNil(t, calls)
// assert.Len(t, calls, 6)
// names := make([]string, 0)
// for _, msgs := range calls {
// for _, msg := range msgs {
// names = append(names, msg.GetName())
// }
// }
//
// assert.Equal(t, []string {"0", "1", "2", "0", "1", "2"}, names)
//})
t.Run("test round-robin binary", func(t *testing.T) {
gs.ResetCounters()

buf := proto.Buffer{}
for i := 0; i < 3; i++ {
msg := &helloworld.HelloRequest{}
msg.Name = strconv.Itoa(i)
err = buf.EncodeMessage(msg)
assert.NoError(t, err)
}
binData := buf.Bytes()

report, err := Run(
"helloworld.Greeter.SayHello",
internal.TestLocalhost,
WithProtoFile("../testdata/greeter.proto", []string{}),
WithTotalRequests(6),
WithConcurrency(1),
WithTimeout(time.Duration(20*time.Second)),
WithDialTimeout(time.Duration(20*time.Second)),
WithInsecure(true),
WithBinaryData(binData),
)

assert.NoError(t, err)
assert.NotNil(t, report)

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

calls := gs.GetCalls(callType)
assert.NotNil(t, calls)
assert.Len(t, calls, 6)
names := make([]string, 0)
for _, msgs := range calls {
for _, msg := range msgs {
names = append(names, msg.GetName())
}
}

assert.Equal(t, []string {"0", "1", "2", "0", "1", "2"}, names)
})
}

func TestRunServerStreaming(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions runner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func (w *Worker) makeRequest() error {
}
} else {
var err error
// todo we need an explicit way to choose between binary formats, it's impossible to distinguish from data itself
inputs, err = createPayloadsFromBinSingleMessage(w.config.data, w.mtd)
inputs, err = createPayloadsFromBin(w.config.data, w.mtd)
if err != nil {
return err
}
Expand Down

0 comments on commit b2a6a3e

Please sign in to comment.