Skip to content

Commit

Permalink
Fixes for CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chusitoo committed Dec 23, 2024
1 parent 863e0ed commit c4ee1dd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 50 deletions.
2 changes: 1 addition & 1 deletion exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ if(BUILD_TESTING)
add_executable(otlp_grpc_exporter_test test/otlp_grpc_exporter_test.cc)
target_link_libraries(
otlp_grpc_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB} opentelemetry_exporter_otlp_grpc)
${GMOCK_LIB} opentelemetry_exporter_otlp_grpc gRPC::grpc++)
gtest_add_tests(
TARGET otlp_grpc_exporter_test
TEST_PREFIX exporter.otlp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <chrono>
#include <cstdint>
#include <string>

#include "opentelemetry/exporters/otlp/otlp_environment.h"
Expand Down
106 changes: 57 additions & 49 deletions exporters/otlp/test/otlp_grpc_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
# include "opentelemetry/nostd/shared_ptr.h"

# include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"
// Problematic code that pulls in Gmock and breaks with vs2019/c++latest :
# include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h"

# include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"

# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"

# include "opentelemetry/sdk/trace/simple_processor.h"
Expand Down Expand Up @@ -432,73 +433,79 @@ struct TestTraceService : public opentelemetry::proto::collector::trace::v1::Tra
std::vector<grpc::StatusCode> status_codes_;
};

using StatusCodeVector = std::vector<grpc::StatusCode>;

class OtlpGrpcExporterRetryIntegrationTests
: public ::testing::TestWithParam<std::tuple<bool, std::vector<grpc::StatusCode>, std::size_t>>
: public ::testing::TestWithParam<std::tuple<bool, StatusCodeVector, std::size_t>>
{};

INSTANTIATE_TEST_SUITE_P(
StatusCodes,
OtlpGrpcExporterRetryIntegrationTests,
testing::Values(
// With retry policy enabled
std::make_tuple(true, std::vector{grpc::StatusCode::CANCELLED}, 5),
std::make_tuple(true, std::vector{grpc::StatusCode::UNKNOWN}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::INVALID_ARGUMENT}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::DEADLINE_EXCEEDED}, 5),
std::make_tuple(true, std::vector{grpc::StatusCode::NOT_FOUND}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::ALREADY_EXISTS}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::PERMISSION_DENIED}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::UNAUTHENTICATED}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::RESOURCE_EXHAUSTED}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::FAILED_PRECONDITION}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::ABORTED}, 5),
std::make_tuple(true, std::vector{grpc::StatusCode::OUT_OF_RANGE}, 5),
std::make_tuple(true, std::vector{grpc::StatusCode::UNIMPLEMENTED}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::INTERNAL}, 1),
std::make_tuple(true, std::vector{grpc::StatusCode::UNAVAILABLE}, 5),
std::make_tuple(true, std::vector{grpc::StatusCode::DATA_LOSS}, 5),
std::make_tuple(true, std::vector{grpc::StatusCode::OK}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::CANCELLED}, 5),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::UNKNOWN}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::INVALID_ARGUMENT}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::DEADLINE_EXCEEDED}, 5),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::NOT_FOUND}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::ALREADY_EXISTS}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::PERMISSION_DENIED}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::UNAUTHENTICATED}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::RESOURCE_EXHAUSTED}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::FAILED_PRECONDITION}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::ABORTED}, 5),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::OUT_OF_RANGE}, 5),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::UNIMPLEMENTED}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::INTERNAL}, 1),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::UNAVAILABLE}, 5),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::DATA_LOSS}, 5),
std::make_tuple(true, StatusCodeVector{grpc::StatusCode::OK}, 1),
std::make_tuple(true,
std::vector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::ABORTED,
grpc::StatusCode::OUT_OF_RANGE, grpc::StatusCode::DATA_LOSS},
StatusCodeVector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::ABORTED,
grpc::StatusCode::OUT_OF_RANGE,
grpc::StatusCode::DATA_LOSS},
5),
std::make_tuple(true,
std::vector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::UNAVAILABLE,
grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::OK},
StatusCodeVector{grpc::StatusCode::UNAVAILABLE,
grpc::StatusCode::UNAVAILABLE,
grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::OK},
4),
std::make_tuple(true,
std::vector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::CANCELLED,
grpc::StatusCode::DEADLINE_EXCEEDED, grpc::StatusCode::OK},
StatusCodeVector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::CANCELLED,
grpc::StatusCode::DEADLINE_EXCEEDED, grpc::StatusCode::OK},
4),
// With retry policy disabled
std::make_tuple(false, std::vector{grpc::StatusCode::CANCELLED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::UNKNOWN}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::INVALID_ARGUMENT}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::DEADLINE_EXCEEDED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::NOT_FOUND}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::ALREADY_EXISTS}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::PERMISSION_DENIED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::UNAUTHENTICATED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::RESOURCE_EXHAUSTED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::FAILED_PRECONDITION}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::ABORTED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::OUT_OF_RANGE}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::UNIMPLEMENTED}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::INTERNAL}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::UNAVAILABLE}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::DATA_LOSS}, 1),
std::make_tuple(false, std::vector{grpc::StatusCode::OK}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::CANCELLED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::UNKNOWN}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::INVALID_ARGUMENT}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::DEADLINE_EXCEEDED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::NOT_FOUND}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::ALREADY_EXISTS}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::PERMISSION_DENIED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::UNAUTHENTICATED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::RESOURCE_EXHAUSTED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::FAILED_PRECONDITION}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::ABORTED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::OUT_OF_RANGE}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::UNIMPLEMENTED}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::INTERNAL}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::UNAVAILABLE}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::DATA_LOSS}, 1),
std::make_tuple(false, StatusCodeVector{grpc::StatusCode::OK}, 1),
std::make_tuple(false,
std::vector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::ABORTED,
grpc::StatusCode::OUT_OF_RANGE, grpc::StatusCode::DATA_LOSS},
StatusCodeVector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::ABORTED,
grpc::StatusCode::OUT_OF_RANGE,
grpc::StatusCode::DATA_LOSS},
1),
std::make_tuple(false,
std::vector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::UNAVAILABLE,
grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::OK},
StatusCodeVector{grpc::StatusCode::UNAVAILABLE,
grpc::StatusCode::UNAVAILABLE,
grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::OK},
1),
std::make_tuple(false,
std::vector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::CANCELLED,
grpc::StatusCode::DEADLINE_EXCEEDED, grpc::StatusCode::OK},
StatusCodeVector{grpc::StatusCode::UNAVAILABLE, grpc::StatusCode::CANCELLED,
grpc::StatusCode::DEADLINE_EXCEEDED, grpc::StatusCode::OK},
1)));

TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes)
Expand All @@ -513,7 +520,7 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes)
std::unique_ptr<grpc::Server> server;

std::thread server_thread([&server, &service]() {
std::string address("0.0.0.0:4317");
std::string address("localhost:4317");
grpc::ServerBuilder builder;
builder.RegisterService(&service);
builder.AddListeningPort(address, grpc::InsecureServerCredentials());
Expand Down Expand Up @@ -542,6 +549,7 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes)
auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter));
auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor));
provider->GetTracer("Test tracer")->StartSpan("Test span")->End();
provider->ForceFlush();

ASSERT_TRUE(server);
server->Shutdown();
Expand Down

0 comments on commit c4ee1dd

Please sign in to comment.