Skip to content

Commit

Permalink
[TEST] Fix compiling problem and removed -DENABLE_TEST (open-telemetr…
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Nov 11, 2023
1 parent 86ee886 commit 6322607
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 39 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")

include(CTest)
if(BUILD_TESTING)
add_definitions(-DENABLE_TEST)
if(EXISTS ${CMAKE_BINARY_DIR}/lib/libgtest.a)
# Prefer GTest from build tree. GTest is not always working with
# CMAKE_PREFIX_PATH
Expand Down
2 changes: 1 addition & 1 deletion ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg"

switch ($action) {
"bazel.build" {
bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //...
bazel build $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //...
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
Expand Down
2 changes: 1 addition & 1 deletion ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fi
echo "make command: ${MAKE_COMMAND}"
echo "IWYU option: ${IWYU}"

BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"
BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"
BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT"

BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/test/otlp_http_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# include "opentelemetry/sdk/trace/batch_span_processor.h"
# include "opentelemetry/sdk/trace/batch_span_processor_options.h"
# include "opentelemetry/sdk/trace/tracer_provider.h"
# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h"
# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"
# include "opentelemetry/trace/provider.h"

Expand Down Expand Up @@ -102,7 +103,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test
static std::pair<OtlpHttpClient *, std::shared_ptr<http_client::HttpClient>>
GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false)
{
auto http_client = http_client::HttpClientFactory::CreateNoSend();
auto http_client = http_client::HttpClientTestFactory::Create();
return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client),
http_client};
}
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/test/otlp_http_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# include "opentelemetry/sdk/logs/exporter.h"
# include "opentelemetry/sdk/logs/logger_provider.h"
# include "opentelemetry/sdk/resource/resource.h"
# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h"
# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"

# include <google/protobuf/message_lite.h>
Expand Down Expand Up @@ -103,7 +104,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
static std::pair<OtlpHttpClient *, std::shared_ptr<http_client::HttpClient>>
GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false)
{
auto http_client = http_client::HttpClientFactory::CreateNoSend();
auto http_client = http_client::HttpClientTestFactory::Create();
return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client),
http_client};
}
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/test/otlp_http_metric_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h"
#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"

#include <google/protobuf/message_lite.h>
Expand Down Expand Up @@ -109,7 +110,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
static std::pair<OtlpHttpClient *, std::shared_ptr<http_client::HttpClient>>
GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false)
{
auto http_client = http_client::HttpClientFactory::CreateNoSend();
auto http_client = http_client::HttpClientTestFactory::Create();
return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client),
http_client};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HttpCurlGlobalInitializer
HttpCurlGlobalInitializer(HttpCurlGlobalInitializer &&) = delete;

HttpCurlGlobalInitializer &operator=(const HttpCurlGlobalInitializer &) = delete;

HttpCurlGlobalInitializer &operator=(HttpCurlGlobalInitializer &&) = delete;

HttpCurlGlobalInitializer();
Expand Down Expand Up @@ -190,9 +191,7 @@ class Session : public opentelemetry::ext::http::client::Session,
*/
const std::string &GetBaseUri() const { return host_; }

#ifdef ENABLE_TEST
std::shared_ptr<Request> GetRequest() { return http_request_; }
#endif

inline HttpClient &GetHttpClient() noexcept { return http_client_; }
inline const HttpClient &GetHttpClient() const noexcept { return http_client_; }
Expand Down Expand Up @@ -327,7 +326,6 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
void ScheduleAbortSession(uint64_t session_id);
void ScheduleRemoveSession(uint64_t session_id, HttpCurlEasyResource &&resource);

#ifdef ENABLE_TEST
void WaitBackgroundThreadExit()
{
std::unique_ptr<std::thread> background_thread;
Expand All @@ -341,7 +339,6 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
background_thread->join();
}
}
#endif

private:
void wakeupBackgroundThread();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class HttpClientFactory
static std::shared_ptr<HttpClientSync> CreateSync();

static std::shared_ptr<HttpClient> Create();

#ifdef ENABLE_TEST
static std::shared_ptr<HttpClient> CreateNoSend();
#endif
};
} // namespace client
} // namespace http
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once
#include "opentelemetry/ext/http/client/http_client.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace ext
{
namespace http
{
namespace client
{
class HttpClientTestFactory
{
public:
static std::shared_ptr<HttpClient> Create();
};
} // namespace client
} // namespace http
} // namespace ext
OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

#pragma once

#ifdef ENABLE_TEST
# include "opentelemetry/ext/http/client/http_client.h"
# include "opentelemetry/ext/http/common/url_parser.h"
# include "opentelemetry/version.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/ext/http/common/url_parser.h"
#include "opentelemetry/version.h"

# include <map>
# include <string>
# include <vector>
#include <map>
#include <string>
#include <vector>

# include <gtest/gtest.h>
# include "gmock/gmock.h"
#include <gtest/gtest.h>
#include "gmock/gmock.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace ext
Expand All @@ -37,12 +36,12 @@ class Request : public opentelemetry::ext::http::client::Request
method_ = method;
}

# ifdef ENABLE_HTTP_SSL_PREVIEW
#ifdef ENABLE_HTTP_SSL_PREVIEW
void SetSslOptions(const HttpSslOptions &ssl_options) noexcept override
{
ssl_options_ = ssl_options;
}
# endif /* ENABLE_HTTP_SSL_PREVIEW */
#endif /* ENABLE_HTTP_SSL_PREVIEW */

void SetBody(opentelemetry::ext::http::client::Body &body) noexcept override
{
Expand All @@ -66,9 +65,9 @@ class Request : public opentelemetry::ext::http::client::Request

public:
opentelemetry::ext::http::client::Method method_;
# ifdef ENABLE_HTTP_SSL_PREVIEW
#ifdef ENABLE_HTTP_SSL_PREVIEW
opentelemetry::ext::http::client::HttpSslOptions ssl_options_;
# endif /* ENABLE_HTTP_SSL_PREVIEW */
#endif /* ENABLE_HTTP_SSL_PREVIEW */
opentelemetry::ext::http::client::Body body_;
opentelemetry::ext::http::client::Headers headers_;
std::string uri_;
Expand Down Expand Up @@ -186,4 +185,3 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
} // namespace http
} // namespace ext
OPENTELEMETRY_END_NAMESPACE
#endif
2 changes: 1 addition & 1 deletion test_common/src/http/client/nosend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package(default_visibility = ["//visibility:public"])
cc_library(
name = "http_client_nosend",
srcs = [
"http_client_factory_nosend.cc",
"http_client_nosend.cc",
"http_client_test_factory.cc",
],
include_prefix = "src/http/client/nosend",
tags = [
Expand Down
2 changes: 1 addition & 1 deletion test_common/src/http/client/nosend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

if(${BUILD_TESTING})
add_library(opentelemetry_http_client_nosend http_client_factory_nosend.cc
add_library(opentelemetry_http_client_nosend http_client_test_factory.cc
http_client_nosend.cc)

set_target_properties(opentelemetry_http_client_nosend
Expand Down
4 changes: 1 addition & 3 deletions test_common/src/http/client/nosend/http_client_nosend.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifdef ENABLE_TEST
# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"
#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace ext
Expand Down Expand Up @@ -96,4 +95,3 @@ void HttpClient::CleanupSession(uint64_t /* session_id */) {}
} // namespace http
} // namespace ext
OPENTELEMETRY_END_NAMESPACE
#endif
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifdef ENABLE_TEST
# include "opentelemetry/ext/http/client/http_client.h"
# include "opentelemetry/ext/http/client/http_client_factory.h"
# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"
#include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"

namespace http_client = opentelemetry::ext::http::client;

std::shared_ptr<http_client::HttpClient> http_client::HttpClientFactory::CreateNoSend()
std::shared_ptr<http_client::HttpClient> http_client::HttpClientTestFactory::Create()
{
return std::make_shared<http_client::nosend::HttpClient>();
}
#endif

0 comments on commit 6322607

Please sign in to comment.