-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathdisabled_mediapipe_test.cpp
116 lines (102 loc) · 4.08 KB
/
disabled_mediapipe_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//*****************************************************************************
// Copyright 2025 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "../http_rest_api_handler.hpp"
#include "../http_status_code.hpp"
#include "../ov_utils.hpp"
#include "../server.hpp"
#include "test_http_utils.hpp"
#include "test_utils.hpp"
using namespace ovms;
class MediapipeDisabledTest : public ::testing::Test {
protected:
static std::unique_ptr<std::thread> t;
public:
std::unique_ptr<ovms::HttpRestApiHandler> handler;
std::vector<std::pair<std::string, std::string>> headers;
ovms::HttpRequestComponents comp;
const std::string endpointChatCompletions = "/v3/chat/completions";
const std::string endpointCompletions = "/v3/completions";
std::shared_ptr<MockedServerRequestInterface> writer;
ovms::HttpResponseComponents responseComponents;
std::string response;
std::vector<std::string> expectedMessages;
static void SetUpTestSuite() {
std::string port = "9173";
randomizePort(port);
ovms::Server& server = ovms::Server::instance();
::SetUpServer(t, server, port, getGenericFullPathForSrcTest("/ovms/src/test/configs/config_cpu_dummy.json").c_str());
auto start = std::chrono::high_resolution_clock::now();
const int numberOfRetries = 5;
while ((server.getModuleState(ovms::SERVABLE_MANAGER_MODULE_NAME) != ovms::ModuleState::INITIALIZED) &&
(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now() - start).count() < numberOfRetries)) {
}
}
void SetUp() {
writer = std::make_shared<MockedServerRequestInterface>();
ON_CALL(*writer, PartialReplyBegin(::testing::_)).WillByDefault(testing::Invoke([](std::function<void()> fn) { fn(); })); // make the streaming flow sequential
ovms::Server& server = ovms::Server::instance();
handler = std::make_unique<ovms::HttpRestApiHandler>(server, 5);
ASSERT_EQ(handler->parseRequestComponents(comp, "POST", endpointChatCompletions, headers), ovms::StatusCode::OK);
}
static void TearDownTestSuite() {
ovms::Server& server = ovms::Server::instance();
server.setShutdownRequest(1);
t->join();
server.setShutdownRequest(0);
}
void TearDown() {
handler.reset();
}
};
std::unique_ptr<std::thread> MediapipeDisabledTest::t;
TEST_F(MediapipeDisabledTest, completionsRequest) {
std::string requestBody = R"(
{
"model": "dummy",
"stream": false,
"seed" : 1,
"best_of": 16,
"max_tokens": 5,
"prompt": "What is OpenVINO?"
}
)";
ASSERT_EQ(
handler->dispatchToProcessor(endpointCompletions, requestBody, &response, comp, responseComponents, writer),
ovms::StatusCode::NOT_IMPLEMENTED);
}
TEST_F(MediapipeDisabledTest, chatCompletionsRequest) {
std::string requestBody = R"(
{
"model": "dummy",
"stream": false,
"seed" : 1,
"best_of" : 16,
"n" : 8,
"max_tokens": 5,
"messages": [
{
"role": "user",
"content": "What is OpenVINO?"
}
]
}
)";
ASSERT_EQ(
handler->dispatchToProcessor(endpointChatCompletions, requestBody, &response, comp, responseComponents, writer),
ovms::StatusCode::NOT_IMPLEMENTED);
}