aboutsummaryrefslogtreecommitdiff
path: root/test/core/gprpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/gprpp')
-rw-r--r--test/core/gprpp/BUILD21
-rw-r--r--test/core/gprpp/cpp_impl_of_test.cc2
-rw-r--r--test/core/gprpp/directory_reader_test.cc64
-rw-r--r--test/core/gprpp/dual_ref_counted_test.cc20
-rw-r--r--test/core/gprpp/if_list_test.cc2
-rw-r--r--test/core/gprpp/match_test.cc2
-rw-r--r--test/core/gprpp/mpscq_test.cc2
-rw-r--r--test/core/gprpp/notification_test.cc1
-rw-r--r--test/core/gprpp/orphanable_test.cc40
-rw-r--r--test/core/gprpp/ref_counted_ptr_test.cc49
-rw-r--r--test/core/gprpp/ref_counted_test.cc23
-rw-r--r--test/core/gprpp/stat_test.cc2
-rw-r--r--test/core/gprpp/status_helper_test.cc2
-rw-r--r--test/core/gprpp/table_test.cc1
-rw-r--r--test/core/gprpp/unique_type_name_test.cc1
-rw-r--r--test/core/gprpp/work_serializer_test.cc59
16 files changed, 253 insertions, 38 deletions
diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD
index 283b9a44b3..620004d769 100644
--- a/test/core/gprpp/BUILD
+++ b/test/core/gprpp/BUILD
@@ -21,6 +21,27 @@ licenses(["notice"])
grpc_package(name = "test/core/gprpp")
grpc_cc_test(
+ name = "directory_reader_test",
+ srcs = ["directory_reader_test.cc"],
+ data = [
+ "//test/core/tsi/test_creds/crl_data/crls:ab06acdd.r0",
+ "//test/core/tsi/test_creds/crl_data/crls:b9322cac.r0",
+ "//test/core/tsi/test_creds/crl_data/crls:current.crl",
+ "//test/core/tsi/test_creds/crl_data/crls:intermediate.crl",
+ ],
+ external_deps = [
+ "gtest",
+ ],
+ language = "C++",
+ uses_event_engine = False,
+ uses_polling = False,
+ deps = [
+ "//src/core:directory_reader",
+ "//test/core/util:grpc_test_util",
+ ],
+)
+
+grpc_cc_test(
name = "examine_stack_test",
srcs = ["examine_stack_test.cc"],
external_deps = [
diff --git a/test/core/gprpp/cpp_impl_of_test.cc b/test/core/gprpp/cpp_impl_of_test.cc
index d610c2d27c..00b164cb3a 100644
--- a/test/core/gprpp/cpp_impl_of_test.cc
+++ b/test/core/gprpp/cpp_impl_of_test.cc
@@ -14,6 +14,8 @@
#include "src/core/lib/gprpp/cpp_impl_of.h"
+#include <memory>
+
#include <gtest/gtest.h>
typedef struct grpc_foo grpc_foo;
diff --git a/test/core/gprpp/directory_reader_test.cc b/test/core/gprpp/directory_reader_test.cc
new file mode 100644
index 0000000000..3aa4c9d5cc
--- /dev/null
+++ b/test/core/gprpp/directory_reader_test.cc
@@ -0,0 +1,64 @@
+//
+// Copyright 2023 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "src/core/lib/gprpp/directory_reader.h"
+
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "test/core/util/test_config.h"
+
+static constexpr absl::string_view kCrlDirectory =
+ "test/core/tsi/test_creds/crl_data/crls/";
+
+namespace grpc_core {
+namespace testing {
+namespace {
+
+TEST(DirectoryReader, CanListFiles) {
+ auto reader = MakeDirectoryReader(kCrlDirectory);
+ std::vector<std::string> contents;
+ absl::Status status = reader->ForEach([&](absl::string_view filename) {
+ contents.push_back(std::string(filename));
+ });
+ ASSERT_TRUE(status.ok()) << status;
+ // IsSupersetOf() is needed instead of UnorderedElementsAre() because some
+ // builds/OS combinations will include the BUILD file in this directory when
+ // the tests are run
+ EXPECT_THAT(contents,
+ ::testing::IsSupersetOf({"ab06acdd.r0", "b9322cac.r0",
+ "current.crl", "intermediate.crl"}));
+}
+
+TEST(DirectoryReader, NonexistentDirectory) {
+ auto reader = MakeDirectoryReader("DOES_NOT_EXIST");
+ absl::Status status = reader->ForEach([](absl::string_view) {});
+ ASSERT_FALSE(status.ok()) << status;
+}
+
+} // namespace
+} // namespace testing
+} // namespace grpc_core
+
+int main(int argc, char** argv) {
+ grpc::testing::TestEnvironment env(&argc, argv);
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/test/core/gprpp/dual_ref_counted_test.cc b/test/core/gprpp/dual_ref_counted_test.cc
index 917fac0d29..b82c66bf1c 100644
--- a/test/core/gprpp/dual_ref_counted_test.cc
+++ b/test/core/gprpp/dual_ref_counted_test.cc
@@ -16,6 +16,8 @@
#include "src/core/lib/gprpp/dual_ref_counted.h"
+#include <memory>
+
#include "gtest/gtest.h"
#include "test/core/util/test_config.h"
@@ -69,6 +71,24 @@ TEST(DualRefCounted, RefIfNonZero) {
foo->WeakUnref();
}
+TEST(DualRefCounted, RefAndWeakRefAsSubclass) {
+ class Bar : public Foo {};
+ Foo* foo = new Bar();
+ RefCountedPtr<Bar> barp = foo->RefAsSubclass<Bar>();
+ barp.release();
+ barp = foo->RefAsSubclass<Bar>(DEBUG_LOCATION, "test");
+ barp.release();
+ WeakRefCountedPtr<Bar> weak_barp = foo->WeakRefAsSubclass<Bar>();
+ weak_barp.release();
+ weak_barp = foo->WeakRefAsSubclass<Bar>(DEBUG_LOCATION, "test");
+ weak_barp.release();
+ foo->WeakUnref();
+ foo->WeakUnref();
+ foo->Unref();
+ foo->Unref();
+ foo->Unref();
+}
+
class FooWithTracing : public DualRefCounted<FooWithTracing> {
public:
FooWithTracing() : DualRefCounted("FooWithTracing") {}
diff --git a/test/core/gprpp/if_list_test.cc b/test/core/gprpp/if_list_test.cc
index b46d582ec5..38dce561bf 100644
--- a/test/core/gprpp/if_list_test.cc
+++ b/test/core/gprpp/if_list_test.cc
@@ -14,6 +14,8 @@
#include "src/core/lib/gprpp/if_list.h"
+#include <memory>
+
#include "gtest/gtest.h"
namespace grpc_core {
diff --git a/test/core/gprpp/match_test.cc b/test/core/gprpp/match_test.cc
index c88b29fa7b..370a650156 100644
--- a/test/core/gprpp/match_test.cc
+++ b/test/core/gprpp/match_test.cc
@@ -16,7 +16,7 @@
#include <stdlib.h>
-#include <utility>
+#include <memory>
#include "gtest/gtest.h"
diff --git a/test/core/gprpp/mpscq_test.cc b/test/core/gprpp/mpscq_test.cc
index 409144b9d5..ddb5ef6883 100644
--- a/test/core/gprpp/mpscq_test.cc
+++ b/test/core/gprpp/mpscq_test.cc
@@ -21,6 +21,8 @@
#include <inttypes.h>
#include <stdlib.h>
+#include <memory>
+
#include "gtest/gtest.h"
#include <grpc/support/log.h>
diff --git a/test/core/gprpp/notification_test.cc b/test/core/gprpp/notification_test.cc
index be431dce0d..ed5dcf4802 100644
--- a/test/core/gprpp/notification_test.cc
+++ b/test/core/gprpp/notification_test.cc
@@ -14,6 +14,7 @@
#include "src/core/lib/gprpp/notification.h"
+#include <memory>
#include <thread>
#include "gtest/gtest.h"
diff --git a/test/core/gprpp/orphanable_test.cc b/test/core/gprpp/orphanable_test.cc
index e5b7414666..bf992fd5c4 100644
--- a/test/core/gprpp/orphanable_test.cc
+++ b/test/core/gprpp/orphanable_test.cc
@@ -78,6 +78,20 @@ TEST(OrphanablePtr, InternallyRefCounted) {
bar->FinishWork();
}
+TEST(OrphanablePtr, InternallyRefCountedRefAsSubclass) {
+ class Subclass : public Bar {
+ public:
+ void StartWork() { self_ref_ = RefAsSubclass<Subclass>(); }
+ void FinishWork() { self_ref_.reset(); }
+
+ private:
+ RefCountedPtr<Subclass> self_ref_;
+ };
+ auto bar = MakeOrphanable<Subclass>();
+ bar->StartWork();
+ bar->FinishWork();
+}
+
class Baz : public InternallyRefCounted<Baz> {
public:
Baz() : Baz(0) {}
@@ -103,6 +117,32 @@ TEST(OrphanablePtr, InternallyRefCountedWithTracing) {
baz->FinishWork();
}
+class Qux : public InternallyRefCounted<Qux> {
+ public:
+ Qux() : Qux(0) {}
+ explicit Qux(int value) : InternallyRefCounted<Qux>("Qux"), value_(value) {}
+ ~Qux() override { self_ref_ = RefIfNonZero(DEBUG_LOCATION, "extra_work"); }
+ void Orphan() override { Unref(); }
+ int value() const { return value_; }
+
+ void StartWork() { self_ref_ = RefIfNonZero(DEBUG_LOCATION, "work"); }
+ void FinishWork() {
+ // This is a little ugly, but it makes the logged ref and unref match up.
+ self_ref_.release();
+ Unref(DEBUG_LOCATION, "work");
+ }
+
+ private:
+ int value_;
+ RefCountedPtr<Qux> self_ref_;
+};
+
+TEST(OrphanablePtr, InternallyRefCountedIfNonZero) {
+ auto qux = MakeOrphanable<Qux>();
+ qux->StartWork();
+ qux->FinishWork();
+}
+
} // namespace
} // namespace testing
} // namespace grpc_core
diff --git a/test/core/gprpp/ref_counted_ptr_test.cc b/test/core/gprpp/ref_counted_ptr_test.cc
index c6e7b0a458..f692533c9a 100644
--- a/test/core/gprpp/ref_counted_ptr_test.cc
+++ b/test/core/gprpp/ref_counted_ptr_test.cc
@@ -18,6 +18,8 @@
#include "src/core/lib/gprpp/ref_counted_ptr.h"
+#include <memory>
+
#include "absl/container/flat_hash_set.h"
#include "gtest/gtest.h"
@@ -192,6 +194,9 @@ TEST(RefCountedPtr, RefCountedWithTracing) {
RefCountedPtr<FooWithTracing> foo(new FooWithTracing());
RefCountedPtr<FooWithTracing> foo2 = foo->Ref(DEBUG_LOCATION, "foo");
foo2.release();
+ RefCountedPtr<FooWithTracing> foo3 = foo.Ref(DEBUG_LOCATION, "foo");
+ foo3.release();
+ foo->Unref(DEBUG_LOCATION, "foo");
foo->Unref(DEBUG_LOCATION, "foo");
}
@@ -238,24 +243,27 @@ TEST(RefCountedPtr, EqualityWithSubclass) {
EXPECT_EQ(b, s);
}
-void FunctionTakingBaseClass(RefCountedPtr<BaseClass> p) {
- p.reset(); // To appease clang-tidy.
-}
+void FunctionTakingBaseClass(RefCountedPtr<BaseClass>) {}
TEST(RefCountedPtr, CanPassSubclassToFunctionExpectingBaseClass) {
RefCountedPtr<Subclass> p = MakeRefCounted<Subclass>();
FunctionTakingBaseClass(p);
}
-void FunctionTakingSubclass(RefCountedPtr<Subclass> p) {
- p.reset(); // To appease clang-tidy.
-}
+void FunctionTakingSubclass(RefCountedPtr<Subclass>) {}
TEST(RefCountedPtr, CanPassSubclassToFunctionExpectingSubclass) {
RefCountedPtr<Subclass> p = MakeRefCounted<Subclass>();
FunctionTakingSubclass(p);
}
+TEST(RefCountedPtr, TakeAsSubclass) {
+ RefCountedPtr<BaseClass> p = MakeRefCounted<Subclass>();
+ auto s = p.TakeAsSubclass<Subclass>();
+ EXPECT_EQ(p.get(), nullptr);
+ EXPECT_NE(s.get(), nullptr);
+}
+
//
// WeakRefCountedPtr<> tests
//
@@ -435,6 +443,9 @@ TEST(WeakRefCountedPtr, RefCountedWithTracing) {
WeakRefCountedPtr<BarWithTracing> bar = bar_strong->WeakRef();
WeakRefCountedPtr<BarWithTracing> bar2 = bar->WeakRef(DEBUG_LOCATION, "bar");
bar2.release();
+ WeakRefCountedPtr<BarWithTracing> bar3 = bar.WeakRef(DEBUG_LOCATION, "bar");
+ bar3.release();
+ bar->WeakUnref(DEBUG_LOCATION, "bar");
bar->WeakUnref(DEBUG_LOCATION, "bar");
}
@@ -464,7 +475,7 @@ TEST(WeakRefCountedPtr, CopyAssignFromWeakSubclass) {
RefCountedPtr<WeakSubclass> strong(new WeakSubclass());
WeakRefCountedPtr<WeakBaseClass> b;
EXPECT_EQ(nullptr, b.get());
- WeakRefCountedPtr<WeakSubclass> s = strong->WeakRef();
+ WeakRefCountedPtr<WeakSubclass> s = strong->WeakRefAsSubclass<WeakSubclass>();
b = s;
EXPECT_NE(nullptr, b.get());
}
@@ -473,7 +484,7 @@ TEST(WeakRefCountedPtr, MoveAssignFromWeakSubclass) {
RefCountedPtr<WeakSubclass> strong(new WeakSubclass());
WeakRefCountedPtr<WeakBaseClass> b;
EXPECT_EQ(nullptr, b.get());
- WeakRefCountedPtr<WeakSubclass> s = strong->WeakRef();
+ WeakRefCountedPtr<WeakSubclass> s = strong->WeakRefAsSubclass<WeakSubclass>();
b = std::move(s);
EXPECT_NE(nullptr, b.get());
}
@@ -482,7 +493,7 @@ TEST(WeakRefCountedPtr, ResetFromWeakSubclass) {
RefCountedPtr<WeakSubclass> strong(new WeakSubclass());
WeakRefCountedPtr<WeakBaseClass> b;
EXPECT_EQ(nullptr, b.get());
- b.reset(strong->WeakRef().release());
+ b.reset(strong->WeakRefAsSubclass<WeakSubclass>().release());
EXPECT_NE(nullptr, b.get());
}
@@ -492,26 +503,30 @@ TEST(WeakRefCountedPtr, EqualityWithWeakSubclass) {
EXPECT_EQ(b, strong.get());
}
-void FunctionTakingWeakBaseClass(WeakRefCountedPtr<WeakBaseClass> p) {
- p.reset(); // To appease clang-tidy.
-}
+void FunctionTakingWeakBaseClass(WeakRefCountedPtr<WeakBaseClass>) {}
TEST(WeakRefCountedPtr, CanPassWeakSubclassToFunctionExpectingWeakBaseClass) {
RefCountedPtr<WeakSubclass> strong(new WeakSubclass());
- WeakRefCountedPtr<WeakSubclass> p = strong->WeakRef();
+ WeakRefCountedPtr<WeakSubclass> p = strong->WeakRefAsSubclass<WeakSubclass>();
FunctionTakingWeakBaseClass(p);
}
-void FunctionTakingWeakSubclass(WeakRefCountedPtr<WeakSubclass> p) {
- p.reset(); // To appease clang-tidy.
-}
+void FunctionTakingWeakSubclass(WeakRefCountedPtr<WeakSubclass>) {}
TEST(WeakRefCountedPtr, CanPassWeakSubclassToFunctionExpectingWeakSubclass) {
RefCountedPtr<WeakSubclass> strong(new WeakSubclass());
- WeakRefCountedPtr<WeakSubclass> p = strong->WeakRef();
+ WeakRefCountedPtr<WeakSubclass> p = strong->WeakRefAsSubclass<WeakSubclass>();
FunctionTakingWeakSubclass(p);
}
+TEST(WeakRefCountedPtr, TakeAsSubclass) {
+ RefCountedPtr<WeakBaseClass> strong = MakeRefCounted<WeakSubclass>();
+ WeakRefCountedPtr<WeakBaseClass> p = strong->WeakRef();
+ WeakRefCountedPtr<WeakSubclass> s = p.TakeAsSubclass<WeakSubclass>();
+ EXPECT_EQ(p.get(), nullptr);
+ EXPECT_NE(s.get(), nullptr);
+}
+
//
// tests for absl hash integration
//
diff --git a/test/core/gprpp/ref_counted_test.cc b/test/core/gprpp/ref_counted_test.cc
index 4d8761ecb1..41356714e7 100644
--- a/test/core/gprpp/ref_counted_test.cc
+++ b/test/core/gprpp/ref_counted_test.cc
@@ -53,6 +53,29 @@ TEST(RefCounted, ExtraRef) {
foo->Unref();
}
+TEST(RefCounted, Const) {
+ const Foo* foo = new Foo();
+ RefCountedPtr<const Foo> foop = foo->Ref();
+ foop.release();
+ foop = foo->RefIfNonZero();
+ foop.release();
+ foo->Unref();
+ foo->Unref();
+ foo->Unref();
+}
+
+TEST(RefCounted, SubclassOfRefCountedType) {
+ class Bar : public Foo {};
+ Bar* bar = new Bar();
+ RefCountedPtr<Bar> barp = bar->RefAsSubclass<Bar>();
+ barp.release();
+ barp = bar->RefAsSubclass<Bar>(DEBUG_LOCATION, "whee");
+ barp.release();
+ bar->Unref();
+ bar->Unref();
+ bar->Unref();
+}
+
class Value : public RefCounted<Value, PolymorphicRefCount, UnrefNoDelete> {
public:
Value(int value, std::set<std::unique_ptr<Value>>* registry) : value_(value) {
diff --git a/test/core/gprpp/stat_test.cc b/test/core/gprpp/stat_test.cc
index c39a25ba89..b3b504ee55 100644
--- a/test/core/gprpp/stat_test.cc
+++ b/test/core/gprpp/stat_test.cc
@@ -18,6 +18,8 @@
#include <stdio.h>
+#include <memory>
+
#include "gtest/gtest.h"
#include <grpc/support/alloc.h>
diff --git a/test/core/gprpp/status_helper_test.cc b/test/core/gprpp/status_helper_test.cc
index 60c257f4a1..fd967742a2 100644
--- a/test/core/gprpp/status_helper_test.cc
+++ b/test/core/gprpp/status_helper_test.cc
@@ -25,7 +25,7 @@
#include "gmock/gmock.h"
#include "google/rpc/status.upb.h"
#include "gtest/gtest.h"
-#include "upb/upb.hpp"
+#include "upb/mem/arena.hpp"
namespace grpc_core {
namespace {
diff --git a/test/core/gprpp/table_test.cc b/test/core/gprpp/table_test.cc
index 672795256d..9c9ba50726 100644
--- a/test/core/gprpp/table_test.cc
+++ b/test/core/gprpp/table_test.cc
@@ -16,6 +16,7 @@
#include <string>
#include <tuple>
+#include <variant>
#include "absl/types/optional.h"
#include "gtest/gtest.h"
diff --git a/test/core/gprpp/unique_type_name_test.cc b/test/core/gprpp/unique_type_name_test.cc
index e34dde3b19..bce147edd3 100644
--- a/test/core/gprpp/unique_type_name_test.cc
+++ b/test/core/gprpp/unique_type_name_test.cc
@@ -14,7 +14,6 @@
#include "src/core/lib/gprpp/unique_type_name.h"
-#include <initializer_list>
#include <iosfwd>
#include <map>
diff --git a/test/core/gprpp/work_serializer_test.cc b/test/core/gprpp/work_serializer_test.cc
index d97d98fe4b..918c845e15 100644
--- a/test/core/gprpp/work_serializer_test.cc
+++ b/test/core/gprpp/work_serializer_test.cc
@@ -20,7 +20,6 @@
#include <stddef.h>
-#include <algorithm>
#include <memory>
#include <thread>
#include <utility>
@@ -52,28 +51,37 @@ using grpc_event_engine::experimental::WaitForSingleOwner;
namespace grpc_core {
namespace {
-TEST(WorkSerializerTest, NoOp) { WorkSerializer lock(GetDefaultEventEngine()); }
+TEST(WorkSerializerTest, NoOp) {
+ auto lock = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
+ lock.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
+}
TEST(WorkSerializerTest, ExecuteOneRun) {
- WorkSerializer lock(GetDefaultEventEngine());
+ auto lock = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
gpr_event done;
gpr_event_init(&done);
- lock.Run([&done]() { gpr_event_set(&done, reinterpret_cast<void*>(1)); },
- DEBUG_LOCATION);
+ lock->Run([&done]() { gpr_event_set(&done, reinterpret_cast<void*>(1)); },
+ DEBUG_LOCATION);
EXPECT_TRUE(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) !=
nullptr);
+ lock.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
TEST(WorkSerializerTest, ExecuteOneScheduleAndDrain) {
- WorkSerializer lock(GetDefaultEventEngine());
+ auto lock = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
gpr_event done;
gpr_event_init(&done);
- lock.Schedule([&done]() { gpr_event_set(&done, reinterpret_cast<void*>(1)); },
- DEBUG_LOCATION);
+ lock->Schedule(
+ [&done]() { gpr_event_set(&done, reinterpret_cast<void*>(1)); },
+ DEBUG_LOCATION);
EXPECT_EQ(gpr_event_get(&done), nullptr);
- lock.DrainQueue();
+ lock->DrainQueue();
EXPECT_TRUE(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) !=
nullptr);
+ lock.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
class TestThread {
@@ -126,13 +134,15 @@ class TestThread {
};
TEST(WorkSerializerTest, ExecuteMany) {
- WorkSerializer lock(GetDefaultEventEngine());
+ auto lock = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
{
std::vector<std::unique_ptr<TestThread>> threads;
for (size_t i = 0; i < 10; ++i) {
- threads.push_back(std::make_unique<TestThread>(&lock));
+ threads.push_back(std::make_unique<TestThread>(lock.get()));
}
}
+ lock.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
class TestThreadScheduleAndDrain {
@@ -187,26 +197,31 @@ class TestThreadScheduleAndDrain {
};
TEST(WorkSerializerTest, ExecuteManyScheduleAndDrain) {
- WorkSerializer lock(GetDefaultEventEngine());
+ auto lock = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
{
std::vector<std::unique_ptr<TestThreadScheduleAndDrain>> threads;
for (size_t i = 0; i < 10; ++i) {
- threads.push_back(std::make_unique<TestThreadScheduleAndDrain>(&lock));
+ threads.push_back(
+ std::make_unique<TestThreadScheduleAndDrain>(lock.get()));
}
}
+ lock.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
TEST(WorkSerializerTest, ExecuteManyMixedRunScheduleAndDrain) {
- WorkSerializer lock(GetDefaultEventEngine());
+ auto lock = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
{
std::vector<std::unique_ptr<TestThread>> run_threads;
std::vector<std::unique_ptr<TestThreadScheduleAndDrain>> schedule_threads;
for (size_t i = 0; i < 10; ++i) {
- run_threads.push_back(std::make_unique<TestThread>(&lock));
+ run_threads.push_back(std::make_unique<TestThread>(lock.get()));
schedule_threads.push_back(
- std::make_unique<TestThreadScheduleAndDrain>(&lock));
+ std::make_unique<TestThreadScheduleAndDrain>(lock.get()));
}
}
+ lock.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
// Tests that work serializers allow destruction from the last callback
@@ -229,6 +244,7 @@ TEST(WorkSerializerTest, WorkSerializerDestructionRace) {
lock->Run([&]() { notification.Notify(); }, DEBUG_LOCATION);
t1.join();
}
+ WaitForSingleOwner(GetDefaultEventEngine());
}
// Tests racy conditions when the last callback triggers work
@@ -249,6 +265,7 @@ TEST(WorkSerializerTest, WorkSerializerDestructionRaceMultipleThreads) {
for (auto& thread : threads) {
thread.join();
}
+ WaitForSingleOwner(GetDefaultEventEngine());
}
TEST(WorkSerializerTest, MetricsWork) {
@@ -256,11 +273,11 @@ TEST(WorkSerializerTest, MetricsWork) {
GTEST_SKIP() << "Work serializer dispatch experiment not enabled";
}
- WorkSerializer serializer(GetDefaultEventEngine());
+ auto serializer = std::make_unique<WorkSerializer>(GetDefaultEventEngine());
auto schedule_sleep = [&serializer](absl::Duration how_long) {
ExecCtx exec_ctx;
auto n = std::make_shared<Notification>();
- serializer.Run(
+ serializer->Run(
[how_long, n]() {
absl::SleepFor(how_long);
n->Notify();
@@ -350,6 +367,9 @@ TEST(WorkSerializerTest, MetricsWork) {
.Percentile(0.5),
diff->histogram(GlobalStats::Histogram::kWorkSerializerWorkTimeMs)
.Percentile(0.5));
+
+ serializer.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
#ifndef NDEBUG
@@ -396,6 +416,9 @@ TEST(WorkSerializerTest, RunningInWorkSerializer) {
work_serializer2->Run([&done2]() { done2.Notify(); }, DEBUG_LOCATION);
done1.WaitForNotification();
done2.WaitForNotification();
+ work_serializer1.reset();
+ work_serializer2.reset();
+ WaitForSingleOwner(GetDefaultEventEngine());
}
#endif