MCPcopy Create free account
hub / github.com/SeldonIO/seldon-core / TestModelInference

Function TestModelInference

tests/integration/pkg/tests/model_test.go:24–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestModelInference(t *testing.T) {
25 g := NewGomegaWithT(t)
26 type test struct {
27 name string
28 modelPath string
29 inferRequestPath string
30 inferResponsePath string
31 }
32 tests := []test{
33 {
34 name: "sklearn - iris",
35 modelPath: "testdata/sklearn-iris.yaml",
36 inferRequestPath: `testdata/sklearn-iris-request.json`,
37 inferResponsePath: `testdata/sklearn-iris-response.json`,
38 },
39 {
40 name: "tensorflow - tfsimple",
41 modelPath: "testdata/tensorflow-tfsimple.yaml",
42 inferRequestPath: `testdata/tensorflow-tfsimple-request.json`,
43 inferResponsePath: `testdata/tensorflow-tfsimple-response.json`,
44 },
45 {
46 name: "xgboost - income",
47 modelPath: "testdata/xgboost-income.yaml",
48 inferRequestPath: `testdata/xgboost-income-request.json`,
49 inferResponsePath: `testdata/xgboost-income-response.json`,
50 },
51 }
52
53 sapi, err := resources.NewSeldonBackendAPI()
54 g.Expect(err).To(BeNil())
55 for _, test := range tests {
56 t.Run(test.name, func(t *testing.T) {
57 // load
58 err = sapi.Load(test.modelPath)
59 g.Expect(err).To(BeNil())
60 // wait ready
61 await := func() bool {
62 loaded, err := sapi.IsLoaded(test.modelPath)
63 g.Expect(err).To(BeNil())
64 t.Logf("Waiting for model %s:%v", test.modelPath, loaded)
65 return loaded
66 }
67 g.Eventually(await).WithTimeout(time.Second * 60).WithPolling(time.Second).Should(BeTrue())
68 // Infer grpc
69 res, err := sapi.Infer(test.modelPath, test.inferRequestPath)
70 g.Expect(err).To(BeNil())
71 expectedResponse, err := os.ReadFile(test.inferResponsePath)
72 g.Expect(err).To(BeNil())
73 g.Expect(expectedResponse).To(MatchJSON(res))
74 // Unload
75 err = sapi.Unload(test.modelPath)
76 g.Expect(err).To(BeNil())
77 })
78 }
79}

Callers

nothing calls this directly

Calls 5

LoadMethod · 0.95
IsLoadedMethod · 0.95
InferMethod · 0.95
UnloadMethod · 0.95
RunMethod · 0.80

Tested by

no test coverage detected