Skip to content

Commit

Permalink
Merge pull request #21 from wallyatgithub/main
Browse files Browse the repository at this point in the history
sync maock code; update lua script error handling
  • Loading branch information
wallyatgithub committed Jun 12, 2023
2 parents c976b63 + 19e65ea commit 2152fde
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
9 changes: 8 additions & 1 deletion H2Server_Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,14 @@ class H2Server_Response

lua_pushlstring(L, response_body.c_str(), response_body.size());

lua_pcall(L, 4, 2, 0);
auto lua_ret = lua_pcall(L, 4, 2, 0);
if (lua_ret != LUA_OK )
{
const char* error = lua_tostring(L, -1);
std::cerr<<std::endl<<std::endl<<std::flush;
std::cerr<<"ERROR: error executing lua script: "<<error<<std::endl<<std::flush;
exit(1);
}
int top = lua_gettop(L);
for (int i = 0; i < top; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions asio_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ void start_statistic_thread(std::vector<uint64_t>& totalReqsReceived,
{
std::stringstream SStream;
std::this_thread::sleep_for(std::chrono::seconds(config_schema.statistics_interval));
if (counter % 10 == 0)
{
//if (counter % 10 == 0)
{
SStream <<"time, "
<< std::endl << std::setw(req_name_width) << "req-name"
<< std::setw(req_name_width) << "req-name"
<< "," << std::setw(resp_name_width) << "resp-name"
<< "," << std::setw(total_number_width) << "msg-total"
<< "," << std::setw(total_number_width) << "throttled-total"
Expand Down
18 changes: 16 additions & 2 deletions base_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,14 @@ bool base_client::validate_response_with_lua(lua_State* L, const Request_Respons
}

lua_pushlstring(L, finished_request.resp_payload.c_str(), finished_request.resp_payload.size());
lua_pcall(L, 2, 1, 0);
auto lua_ret = lua_pcall(L, 2, 1, 0);
if (lua_ret != LUA_OK )
{
const char* error = lua_tostring(L, -1);
std::cerr<<std::endl<<std::endl<<std::flush;
std::cerr<<"ERROR: error executing lua script: "<<error<<std::endl<<std::flush;
exit(1);
}
int top = lua_gettop(L);
for (int i = 0; i < top; i++)
{
Expand Down Expand Up @@ -1666,7 +1673,14 @@ bool base_client::update_request_with_lua(lua_State* L, const Request_Response_D

lua_pushlstring(L, request_to_send.req_payload->c_str(), request_to_send.req_payload->size());

lua_pcall(L, 4, 2, 0);
auto lua_ret= lua_pcall(L, 4, 2, 0);
if (lua_ret != LUA_OK )
{
const char* error = lua_tostring(L, -1);
std::cerr<<std::endl<<std::endl<<std::flush;
std::cerr<<"ERROR: error executing lua script: "<<error<<std::endl<<std::flush;
exit(1);
}
int top = lua_gettop(L);
for (int i = 0; i < top; i++)
{
Expand Down
7 changes: 7 additions & 0 deletions h2load_lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,13 @@ int lua_resume_wrapper(lua_State* L, int nargs)
auto retCode = lua_resume(L, nargs);
if (LUA_YIELD != retCode)
{
if (LUA_OK != retCode)
{
const char* error = lua_tostring(L, -1);
std::cerr<<std::endl<<std::endl<<std::flush;
std::cerr<<"ERROR: error executing lua script: "<<error<<std::endl<<std::flush;
exit(1);
}
auto group_id = get_group_id(L);
auto& lua_group_config = get_lua_group_config(group_id);
auto worker_index = get_worker_index(L);
Expand Down

0 comments on commit 2152fde

Please sign in to comment.