Skip to content

Commit

Permalink
Routers not working with new Executor, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
neopobo authored May 28, 2020
1 parent fb697d7 commit 06b3e9e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion executor/api/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ func ExtractRouteFromSeldonMessage(msg *proto.SeldonMessage) []int {
values := msg.GetData().GetNdarray().GetValues()
routeArr := make([]int, len(values))
for i, value := range values {
routeArr[i] = int(value.GetNumberValue())
if listValue := value.GetListValue(); listValue != nil {
routeArr[i] = int(listValue.GetValues()[0].GetNumberValue())
} else {
routeArr[i] = int(value.GetNumberValue())
}
}
return routeArr
case *proto.DefaultData_Tensor:
Expand Down
47 changes: 47 additions & 0 deletions executor/api/util/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package util

import (
"testing"

"github.com/golang/protobuf/jsonpb"
. "github.com/onsi/gomega"
"github.com/seldonio/seldon-core/executor/api/grpc/seldon/proto"
)

func TestExtractRouteFromSeldonMessage(t *testing.T) {
g := NewGomegaWithT(t)

cases := []struct {
msg string
expected []int
}{
{
msg: `{"data":{"names":["X1L"],"ndarray":[[1]]}}`,
expected: []int{1},
},
{
msg: `{"data":{"ndarray":[2]}}`,
expected: []int{2},
},
{
msg: `{"data":{"ndarray":[3,4]}}`,
expected: []int{3, 4},
},
{
msg: `{"data":{"names":["X1L","X2L"],"ndarray":[[1,2],[3,4]]}}`,
expected: []int{1, 3},
},
{
msg: `{"data":{"ndarray":[]}}`,
expected: []int{},
},
}

for _, c := range cases {
var sm proto.SeldonMessage
jsonpb.UnmarshalString(c.msg, &sm)
routes := ExtractRouteFromSeldonMessage(&sm)

g.Expect(routes).To(Equal(c.expected))
}
}

0 comments on commit 06b3e9e

Please sign in to comment.