Skip to content

Commit

Permalink
Remove -DENABLE_TEST, rename HttpClientFactory::CreateNoSend() to…
Browse files Browse the repository at this point in the history
… `HttpClientTestFactory::Create()`
  • Loading branch information
owent committed Nov 10, 2023
1 parent ced3dbc commit 70103e9
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 138 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,27 +639,6 @@ jobs:
- name: run tests
run: ./ci/do_ci.sh bazel.macos.test

bazel_notest:
name: Bazel without test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
path: /home/runner/.cache/bazel
key: bazel_test
- name: setup
run: |
sudo ./ci/setup_ci_environment.sh
sudo ./ci/install_bazelisk.sh
- name: run tests
run: ./ci/do_ci.sh bazel.notest

benchmark:
name: Benchmark
runs-on: ubuntu-latest
Expand Down
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
5 changes: 1 addition & 4 deletions 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 Expand Up @@ -434,9 +434,6 @@ elif [[ "$1" == "bazel.macos.test" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_MACOS_OPTIONS -- //...
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_MACOS_TEST_OPTIONS -- //...
exit 0
elif [[ "$1" == "bazel.notest" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build ${BAZEL_OPTIONS_ASYNC/--copt=-DENABLE_TEST /} //...
exit 0
elif [[ "$1" == "bazel.legacy.test" ]]; then
# we uses C++ future and async() function to test the Prometheus Exporter functionality,
# that make this test always fail. ignore Prometheus exporter here.
Expand Down
42 changes: 20 additions & 22 deletions 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_factory.h"
# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"
# include "opentelemetry/trace/provider.h"

Expand All @@ -35,8 +36,6 @@ using opentelemetry::sdk::common::unsetenv;
# endif
using namespace testing;

# ifdef ENABLE_TEST

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand All @@ -63,19 +62,19 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
std::make_pair<const std::string, std::string>("Custom-Header-Key", "Custom-Header-Value"));
OtlpHttpClientOptions otlp_http_client_options(
options.url,
# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW
# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW
false, /* ssl_insecure_skip_verify */
"", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */
"", /* ssl_client_key_path */
"", /* ssl_client_key_string */ "", /* ssl_client_cert_path */
"", /* ssl_client_cert_string */
# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */
# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW
"", /* ssl_min_tls */
"", /* ssl_max_tls */
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */
# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */
# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW
"", /* ssl_min_tls */
"", /* ssl_max_tls */
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */
options.content_type, options.json_bytes_mapping, options.use_json_name,
options.console_debug, options.timeout, options.http_headers);
if (!async_mode)
Expand Down Expand Up @@ -104,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 Expand Up @@ -199,7 +198,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test
static_cast<sdk::trace::TracerProvider *>(provider.get())->ForceFlush();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
void ExportJsonIntegrationTestAsync()
{
auto mock_otlp_client =
Expand Down Expand Up @@ -293,7 +292,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test

static_cast<sdk::trace::TracerProvider *>(provider.get())->ForceFlush();
}
# endif
# endif

void ExportBinaryIntegrationTest()
{
Expand Down Expand Up @@ -375,7 +374,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test
static_cast<sdk::trace::TracerProvider *>(provider.get())->ForceFlush();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
void ExportBinaryIntegrationTestAsync()
{
auto mock_otlp_client =
Expand Down Expand Up @@ -460,7 +459,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test

static_cast<sdk::trace::TracerProvider *>(provider.get())->ForceFlush();
}
# endif
# endif
};

TEST(OtlpHttpExporterTest, Shutdown)
Expand All @@ -480,26 +479,26 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestSync)
ExportJsonIntegrationTest();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestAsync)
{
ExportJsonIntegrationTestAsync();
google::protobuf::ShutdownProtobufLibrary();
}
# endif
# endif

// Create spans, let processor call Export()
TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync)
{
ExportBinaryIntegrationTest();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestAsync)
{
ExportBinaryIntegrationTestAsync();
}
# endif
# endif

// Test exporter configuration options
TEST_F(OtlpHttpExporterTestPeer, ConfigTest)
Expand Down Expand Up @@ -528,7 +527,7 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigJsonBytesMappingTest)
EXPECT_EQ(GetOptions(exporter).json_bytes_mapping, JsonBytesMappingKind::kHex);
}

# ifndef NO_GETENV
# ifndef NO_GETENV
// Test exporter configuration options with use_ssl_credentials
TEST_F(OtlpHttpExporterTestPeer, ConfigFromEnv)
{
Expand Down Expand Up @@ -609,10 +608,9 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigFromTracesEnv)
unsetenv("OTEL_EXPORTER_OTLP_HEADERS");
unsetenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS");
}
# endif
# endif

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
# endif
#endif /* OPENTELEMETRY_STL_VERSION */
42 changes: 20 additions & 22 deletions 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_factory.h"
# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h"

# include <google/protobuf/message_lite.h>
Expand All @@ -38,8 +39,6 @@ using opentelemetry::sdk::common::unsetenv;

using namespace testing;

# ifdef ENABLE_TEST

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand All @@ -62,19 +61,19 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
std::make_pair<const std::string, std::string>("Custom-Header-Key", "Custom-Header-Value"));
OtlpHttpClientOptions otlp_http_client_options(
options.url,
# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW
# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW
false, /* ssl_insecure_skip_verify */
"", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */
"", /* ssl_client_key_path */
"", /* ssl_client_key_string */ "", /* ssl_client_cert_path */
"", /* ssl_client_cert_string */
# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */
# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW
"", /* ssl_min_tls */
"", /* ssl_max_tls */
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */
# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */
# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW
"", /* ssl_min_tls */
"", /* ssl_max_tls */
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */
options.content_type, options.json_bytes_mapping, options.use_json_name,
options.console_debug, options.timeout, options.http_headers);
if (!async_mode)
Expand Down Expand Up @@ -105,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 Expand Up @@ -223,7 +222,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
provider->ForceFlush();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
void ExportJsonIntegrationTestAsync()
{
auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient(
Expand Down Expand Up @@ -350,7 +349,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test

provider->ForceFlush();
}
# endif
# endif

void ExportBinaryIntegrationTest()
{
Expand Down Expand Up @@ -463,7 +462,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
provider->ForceFlush();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
void ExportBinaryIntegrationTestAsync()
{
auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient(
Expand Down Expand Up @@ -579,7 +578,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test

provider->ForceFlush();
}
# endif
# endif
};

TEST(OtlpHttpLogRecordExporterTest, Shutdown)
Expand All @@ -600,26 +599,26 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestSync)
ExportJsonIntegrationTest();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestAsync)
{
ExportJsonIntegrationTestAsync();
google::protobuf::ShutdownProtobufLibrary();
}
# endif
# endif

// Create log records, let processor call Export()
TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync)
{
ExportBinaryIntegrationTest();
}

# ifdef ENABLE_ASYNC_EXPORT
# ifdef ENABLE_ASYNC_EXPORT
TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestAsync)
{
ExportBinaryIntegrationTestAsync();
}
# endif
# endif

// Test exporter configuration options
TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigTest)
Expand Down Expand Up @@ -648,7 +647,7 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigJsonBytesMappingTest)
EXPECT_EQ(GetOptions(exporter).json_bytes_mapping, JsonBytesMappingKind::kHex);
}

# ifndef NO_GETENV
# ifndef NO_GETENV
// Test exporter configuration options with use_ssl_credentials
TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigFromEnv)
{
Expand Down Expand Up @@ -737,10 +736,9 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, DefaultEndpoint)
EXPECT_EQ("http://localhost:4317", GetOtlpDefaultGrpcEndpoint());
}

# endif
# endif

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
# endif
#endif /* OPENTELEMETRY_STL_VERSION */
Loading

0 comments on commit 70103e9

Please sign in to comment.