|
1 | 1 | #include <chrono> |
| 2 | +#include <functional> |
2 | 3 | #include <memory> |
3 | 4 | #include <string> |
| 5 | +#include <unordered_map> |
4 | 6 |
|
5 | 7 | #include "common/http/header_map_impl.h" |
6 | 8 | #include "common/http/headers.h" |
@@ -577,6 +579,37 @@ TEST_F(ZipkinDriverTest, ExplicitlySetSampledTrue) { |
577 | 579 | // Check B3 sampled flag is set to sample |
578 | 580 | EXPECT_EQ(ZipkinCoreConstants::get().SAMPLED, sampled_entry->value().getStringView()); |
579 | 581 | } |
| 582 | + |
| 583 | +TEST_F(ZipkinDriverTest, DuplicatedHeader) { |
| 584 | + setupValidDriver(); |
| 585 | + request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_TRACE_ID, |
| 586 | + Hex::uint64ToHex(generateRandom64())); |
| 587 | + request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_SPAN_ID, |
| 588 | + Hex::uint64ToHex(generateRandom64())); |
| 589 | + request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_PARENT_SPAN_ID, |
| 590 | + Hex::uint64ToHex(generateRandom64())); |
| 591 | + Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, |
| 592 | + start_time_, {Tracing::Reason::Sampling, false}); |
| 593 | + |
| 594 | + typedef std::function<bool(const std::string& key)> DupCallback; |
| 595 | + DupCallback dup_callback = [](const std::string& key) -> bool { |
| 596 | + static std::unordered_map<std::string, bool> dup; |
| 597 | + if (dup.find(key) == dup.end()) { |
| 598 | + dup[key] = true; |
| 599 | + return false; |
| 600 | + } |
| 601 | + return true; |
| 602 | + }; |
| 603 | + |
| 604 | + span->setSampled(true); |
| 605 | + span->injectContext(request_headers_); |
| 606 | + request_headers_.iterate( |
| 607 | + [](const Http::HeaderEntry& header, void* cb) -> Http::HeaderMap::Iterate { |
| 608 | + EXPECT_FALSE(static_cast<DupCallback*>(cb)->operator()(header.key().c_str())); |
| 609 | + return Http::HeaderMap::Iterate::Continue; |
| 610 | + }, |
| 611 | + &dup_callback); |
| 612 | +} |
580 | 613 | } // namespace Zipkin |
581 | 614 | } // namespace Tracers |
582 | 615 | } // namespace Extensions |
|
0 commit comments