|
|
|
@ -21,7 +21,9 @@ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
|
|
#include <thread> |
|
|
|
|
|
|
|
|
|
#include "absl/synchronization/notification.h" |
|
|
|
|
#include "gtest/gtest.h" |
|
|
|
|
|
|
|
|
|
#include <grpc/credentials.h> |
|
|
|
@ -317,6 +319,29 @@ TEST(ChannelTracerTest, TestTotalEviction) { |
|
|
|
|
ValidateChannelTraceCustom(&tracer, kNumEvents + 1, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that the code is thread-safe.
|
|
|
|
|
TEST(ChannelTracerTest, ThreadSafety) { |
|
|
|
|
ExecCtx exec_ctx; |
|
|
|
|
ChannelTrace tracer(kEventListMemoryLimit); |
|
|
|
|
absl::Notification done; |
|
|
|
|
std::vector<std::unique_ptr<std::thread>> threads; |
|
|
|
|
for (size_t i = 0; i < 10; ++i) { |
|
|
|
|
threads.push_back(std::make_unique<std::thread>( |
|
|
|
|
[&]() { |
|
|
|
|
do { |
|
|
|
|
AddSimpleTrace(&tracer); |
|
|
|
|
} while (!done.HasBeenNotified()); |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
for (size_t i = 0; i < 10; ++i) { |
|
|
|
|
tracer.RenderJson(); |
|
|
|
|
} |
|
|
|
|
done.Notify(); |
|
|
|
|
for (const auto& thd : threads) { |
|
|
|
|
thd->join(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
|
} // namespace channelz
|
|
|
|
|
} // namespace grpc_core
|
|
|
|
|