Skip to content

Commit

Permalink
Fix missing notify of conditional variable in OTLP HTTP exporter test (
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Jun 15, 2021
1 parent 7fca2c3 commit 8a8ffe5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ struct OtlpHttpExporterOptions
bool console_debug = false;

// TODO: Enable/disable to verify SSL certificate
// TODO: Reuqest timeout
std::chrono::milliseconds timeout = std::chrono::milliseconds(30000);
};

Expand Down
22 changes: 14 additions & 8 deletions exporters/otlp/test/otlp_http_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class OtlpHttpExporterTestPeer : public ::testing::Test, public HTTP_SERVER_NS::
}
}

int response_status = 0;

if (request.uri == kDefaultTracePath)
{
response.headers["Content-Type"] = "application/json";
Expand All @@ -102,8 +104,8 @@ class OtlpHttpExporterTestPeer : public ::testing::Test, public HTTP_SERVER_NS::
}
else
{
response.body = "{\"code\": 400, \"message\": \"Parse binary failed\"}";
return 400;
response.body = "{\"code\": 400, \"message\": \"Parse binary failed\"}";
response_status = 400;
}
}
else if (nullptr != request_content_type && *request_content_type == kHttpJsonContentType)
Expand All @@ -112,8 +114,8 @@ class OtlpHttpExporterTestPeer : public ::testing::Test, public HTTP_SERVER_NS::
response.headers["Content-Type"] = "application/json";
if (json.is_discarded())
{
response.body = "{\"code\": 400, \"message\": \"Parse json failed\"}";
return 400;
response.body = "{\"code\": 400, \"message\": \"Parse json failed\"}";
response_status = 400;
}
else
{
Expand All @@ -123,19 +125,23 @@ class OtlpHttpExporterTestPeer : public ::testing::Test, public HTTP_SERVER_NS::
}
else
{
response.body = "{\"code\": 400, \"message\": \"Unsupported content type\"}";
return 400;
response.body = "{\"code\": 400, \"message\": \"Unsupported content type\"}";
response_status = 400;
}

return 200;
response_status = 200;
}
else
{
std::unique_lock<std::mutex> lk(mtx_requests);
response.headers["Content-Type"] = "text/plain";
response.body = "404 Not Found";
return 200;
response_status = 200;
}

cv_got_events.notify_one();

return response_status;
}

bool waitForRequests(unsigned timeOutSec, size_t expected_count = 1)
Expand Down
10 changes: 7 additions & 3 deletions ext/test/http/curl_http_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,27 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe
virtual int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request,
HTTP_SERVER_NS::HttpResponse &response) override
{
int response_status = 404;
if (request.uri == "/get/")
{

std::unique_lock<std::mutex> lk(mtx_requests);
received_requests_.push_back(request);
response.headers["Content-Type"] = "text/plain";
return 200;
response_status = 200;
}
if (request.uri == "/post/")
{
std::unique_lock<std::mutex> lk(mtx_requests);
received_requests_.push_back(request);
response.headers["Content-Type"] = "application/json";
response.body = "{'k1':'v1', 'k2':'v2', 'k3':'v3'}";
return 200;
response_status = 200;
}
return 404;

cv_got_events.notify_one();

return response_status;
}

bool waitForRequests(unsigned timeOutSec, unsigned expected_count = 1)
Expand Down

0 comments on commit 8a8ffe5

Please sign in to comment.