Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Dec 16, 2024
2 parents 66356c5 + 6ed0651 commit 0208fc9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion api/include/opentelemetry/semconv/incubating/hw_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static inline nostd::shared_ptr<metrics::ObservableInstrument> CreateAsyncDouble
* states <p>
* @code hw.status @endcode is currently specified as an <em>UpDownCounter</em> but would ideally be
* represented using a <a
* href="https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#stateset"><em>StateSet</em>
* href="https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#stateset"><em>StateSet</em>
* as defined in OpenMetrics</a>. This semantic convention will be updated once <em>StateSet</em> is
* specified in OpenTelemetry. This planned change is not expected to have any consequence on the
* way users query their timeseries backend to retrieve the values of @code hw.status @endcode over
Expand Down
55 changes: 30 additions & 25 deletions ext/test/http/curl_http_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,28 @@ class CustomEventHandler : public http_client::EventHandler
public:
void OnResponse(http_client::Response & /* response */) noexcept override
{
got_response_ = true;
got_response_.store(true, std::memory_order_release);
}
void OnEvent(http_client::SessionState state, nostd::string_view /* reason */) noexcept override
{
switch (state)
{
case http_client::SessionState::ConnectFailed:
case http_client::SessionState::SendFailed: {
is_called_ = true;
is_called_.store(true, std::memory_order_release);
break;
}
default:
break;
}
}

CustomEventHandler() : is_called_(false), got_response_(false) {}

~CustomEventHandler() override = default;
bool is_called_ = false;
bool got_response_ = false;

std::atomic<bool> is_called_;
std::atomic<bool> got_response_;
};

class GetEventHandler : public CustomEventHandler
Expand All @@ -61,8 +65,8 @@ class GetEventHandler : public CustomEventHandler
{
ASSERT_EQ(200, response.GetStatusCode());
ASSERT_EQ(response.GetBody().size(), 0);
is_called_ = true;
got_response_ = true;
is_called_.store(true, std::memory_order_release);
got_response_.store(true, std::memory_order_release);
}
};

Expand All @@ -73,8 +77,8 @@ class PostEventHandler : public CustomEventHandler
ASSERT_EQ(200, response.GetStatusCode());
std::string body(response.GetBody().begin(), response.GetBody().end());
ASSERT_EQ(body, "{'k1':'v1', 'k2':'v2', 'k3':'v3'}");
is_called_ = true;
got_response_ = true;
is_called_.store(true, std::memory_order_release);
got_response_.store(true, std::memory_order_release);
}
};

Expand All @@ -89,8 +93,8 @@ class FinishInCallbackHandler : public CustomEventHandler
{
ASSERT_EQ(200, response.GetStatusCode());
ASSERT_EQ(response.GetBody().size(), 0);
is_called_ = true;
got_response_ = true;
is_called_.store(true, std::memory_order_release);
got_response_.store(true, std::memory_order_release);

if (session_)
{
Expand Down Expand Up @@ -251,8 +255,8 @@ TEST_F(BasicCurlHttpTests, SendGetRequest)
session->SendRequest(handler);
ASSERT_TRUE(waitForRequests(30, 1));
session->FinishSession();
ASSERT_TRUE(handler->is_called_);
ASSERT_TRUE(handler->got_response_);
ASSERT_TRUE(handler->is_called_.load(std::memory_order_acquire));
ASSERT_TRUE(handler->got_response_.load(std::memory_order_acquire));
}

TEST_F(BasicCurlHttpTests, SendPostRequest)
Expand All @@ -274,8 +278,8 @@ TEST_F(BasicCurlHttpTests, SendPostRequest)
session->SendRequest(handler);
ASSERT_TRUE(waitForRequests(30, 1));
session->FinishSession();
ASSERT_TRUE(handler->is_called_);
ASSERT_TRUE(handler->got_response_);
ASSERT_TRUE(handler->is_called_.load(std::memory_order_acquire));
ASSERT_TRUE(handler->got_response_.load(std::memory_order_acquire));

session_manager->CancelAllSessions();
session_manager->FinishAllSessions();
Expand All @@ -293,8 +297,8 @@ TEST_F(BasicCurlHttpTests, RequestTimeout)
auto handler = std::make_shared<GetEventHandler>();
session->SendRequest(handler);
session->FinishSession();
ASSERT_TRUE(handler->is_called_);
ASSERT_FALSE(handler->got_response_);
ASSERT_TRUE(handler->is_called_.load(std::memory_order_acquire));
ASSERT_FALSE(handler->got_response_.load(std::memory_order_acquire));
}

TEST_F(BasicCurlHttpTests, CurlHttpOperations)
Expand Down Expand Up @@ -410,8 +414,8 @@ TEST_F(BasicCurlHttpTests, SendGetRequestAsync)
sessions[i]->FinishSession();
ASSERT_FALSE(sessions[i]->IsSessionActive());

ASSERT_TRUE(handlers[i]->is_called_);
ASSERT_TRUE(handlers[i]->got_response_);
ASSERT_TRUE(handlers[i]->is_called_.load(std::memory_order_acquire));
ASSERT_TRUE(handlers[i]->got_response_.load(std::memory_order_acquire));
}

http_client.WaitBackgroundThreadExit();
Expand Down Expand Up @@ -439,16 +443,17 @@ TEST_F(BasicCurlHttpTests, SendGetRequestAsyncTimeout)
// Lock mtx_requests to prevent response, we will check IsSessionActive() in the end
std::unique_lock<std::mutex> lock_requests(mtx_requests);
sessions[i]->SendRequest(handlers[i]);
ASSERT_TRUE(sessions[i]->IsSessionActive() || handlers[i]->is_called_);
ASSERT_TRUE(sessions[i]->IsSessionActive() ||
handlers[i]->is_called_.load(std::memory_order_acquire));
}

for (unsigned i = 0; i < batch_count; ++i)
{
sessions[i]->FinishSession();
ASSERT_FALSE(sessions[i]->IsSessionActive());

ASSERT_TRUE(handlers[i]->is_called_);
ASSERT_FALSE(handlers[i]->got_response_);
ASSERT_TRUE(handlers[i]->is_called_.load(std::memory_order_acquire));
ASSERT_FALSE(handlers[i]->got_response_.load(std::memory_order_acquire));
}
}

Expand Down Expand Up @@ -484,8 +489,8 @@ TEST_F(BasicCurlHttpTests, SendPostRequestAsync)
ASSERT_FALSE(session->IsSessionActive());
}

ASSERT_TRUE(handler->is_called_);
ASSERT_TRUE(handler->got_response_);
ASSERT_TRUE(handler->is_called_.load(std::memory_order_acquire));
ASSERT_TRUE(handler->got_response_.load(std::memory_order_acquire));

http_client.WaitBackgroundThreadExit();
}
Expand Down Expand Up @@ -523,8 +528,8 @@ TEST_F(BasicCurlHttpTests, FinishInAsyncCallback)
{
ASSERT_FALSE(sessions[i]->IsSessionActive());

ASSERT_TRUE(handlers[i]->is_called_);
ASSERT_TRUE(handlers[i]->got_response_);
ASSERT_TRUE(handlers[i]->is_called_.load(std::memory_order_acquire));
ASSERT_TRUE(handlers[i]->got_response_.load(std::memory_order_acquire));
}
}
}
Expand Down

0 comments on commit 0208fc9

Please sign in to comment.