Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/extensions/clusters/aggregate/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Cluster::Cluster(const envoy::config::cluster::v3::Cluster& cluster,
: Upstream::ClusterImplBase(cluster, runtime, factory_context, std::move(stats_scope),
added_via_api, factory_context.dispatcher().timeSource()),
cluster_manager_(cluster_manager), runtime_(runtime), random_(random), tls_(tls),
clusters_(config.clusters().begin(), config.clusters().end()) {}
clusters_(config.clusters().begin(), config.clusters().end()) {
tls_.set([](Event::Dispatcher&) { return nullptr; });
}

PriorityContextPtr
Cluster::linearizePrioritySet(const std::function<bool(const std::string&)>& skip_predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ TEST(HttpJwtAuthnFilterConfigTest, VerifyTLSLifetime) {

NiceMock<Server::Configuration::MockServerFactoryContext> server_context;
// Make sure that the thread callbacks are not invoked inline.
server_context.thread_local_.defer_data = true;
server_context.thread_local_.defer_data_ = true;
{
// Scope in all the things that the filter depends on, so they are destroyed as we leave the
// scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ TEST_F(RedisConnPoolImplTest, AskRedirectionFailure) {

TEST_F(RedisConnPoolImplTest, MakeRequestAndRedirectFollowedByDelete) {
cm_.initializeThreadLocalClusters({"fake_cluster"});
tls_.defer_delete = true;
tls_.defer_delete_ = true;
std::unique_ptr<NiceMock<Stats::MockStore>> store =
std::make_unique<NiceMock<Stats::MockStore>>();
cluster_refresh_manager_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ TEST_F(LightStepDriverTest, DeferredTlsInitialization) {

auto propagation_mode = Common::Ot::OpenTracingDriver::PropagationMode::TracerNative;

tls_.defer_data = true;
tls_.defer_data_ = true;
cm_.initializeClusters({"fake_cluster"}, {});
ON_CALL(*cm_.active_clusters_["fake_cluster"]->info_, features())
.WillByDefault(Return(Upstream::ClusterInfo::Features::HTTP2));
Expand Down
20 changes: 14 additions & 6 deletions test/mocks/thread_local/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,32 @@ class MockInstance : public Instance {

~SlotImpl() override {
// Do not actually clear slot data during shutdown. This mimics the production code.
// The defer_delete mimics the recycle() code with Bookkeeper.
if (!parent_.shutdown_ && !parent_.defer_delete) {
// The defer_delete mimics the slot being deleted on the main thread but the update not yet
// getting to a worker.
if (!parent_.shutdown_ && !parent_.defer_delete_) {
EXPECT_LT(index_, parent_.data_.size());
parent_.data_[index_].reset();
}
}

// ThreadLocal::Slot
ThreadLocalObjectSharedPtr get() override { return parent_.data_[index_]; }
ThreadLocalObjectSharedPtr get() override {
EXPECT_TRUE(was_set_);
return parent_.data_[index_];
}
bool currentThreadRegistered() override { return parent_.registered_; }
void runOnAllThreads(const UpdateCb& cb) override {
EXPECT_TRUE(was_set_);
parent_.runOnAllThreads([cb, this]() { cb(parent_.data_[index_]); });
}
void runOnAllThreads(const UpdateCb& cb, const Event::PostCb& main_callback) override {
EXPECT_TRUE(was_set_);
parent_.runOnAllThreads([cb, this]() { cb(parent_.data_[index_]); }, main_callback);
}

void set(InitializeCb cb) override {
if (parent_.defer_data) {
was_set_ = true;
if (parent_.defer_data_) {
parent_.deferred_data_[index_] = cb;
} else {
parent_.data_[index_] = cb(parent_.dispatcher_);
Expand All @@ -77,6 +84,7 @@ class MockInstance : public Instance {

MockInstance& parent_;
const uint32_t index_;
bool was_set_{}; // set() must be called before other functions.
};

void call() {
Expand All @@ -90,10 +98,10 @@ class MockInstance : public Instance {
testing::NiceMock<Event::MockDispatcher> dispatcher_;
std::vector<ThreadLocalObjectSharedPtr> data_;
std::vector<Slot::InitializeCb> deferred_data_;
bool defer_data{};
bool defer_data_{};
bool shutdown_{};
bool registered_{true};
bool defer_delete{};
bool defer_delete_{};
};

} // namespace ThreadLocal
Expand Down