summaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/cancellation
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2026-01-26 04:33:13 +0300
committerrobot-piglet <[email protected]>2026-01-26 04:46:51 +0300
commit1f29108384ee8ca6307a257c6ef67bb75967135c (patch)
treeadb6f8be66ab3282bdd252783a767137b86f5c3f /library/cpp/threading/cancellation
parent92b20e43d02c35280520dfbf7fd635d5d96c32e4 (diff)
Intermediate changes
commit_hash:4373219e5a3e59d3b6020a500b3953d735a28ef0
Diffstat (limited to 'library/cpp/threading/cancellation')
-rw-r--r--library/cpp/threading/cancellation/ut.cpp56
-rw-r--r--library/cpp/threading/cancellation/ut/ya.make7
-rw-r--r--library/cpp/threading/cancellation/ya.make2
3 files changed, 65 insertions, 0 deletions
diff --git a/library/cpp/threading/cancellation/ut.cpp b/library/cpp/threading/cancellation/ut.cpp
new file mode 100644
index 00000000000..c744795a081
--- /dev/null
+++ b/library/cpp/threading/cancellation/ut.cpp
@@ -0,0 +1,56 @@
+#include "cancellation_token.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+using namespace NThreading;
+
+Y_UNIT_TEST_SUITE(Cancellation) {
+ Y_UNIT_TEST(IsCancellationRequested) {
+ TCancellationTokenSource source;
+ auto const token = source.Token();
+ UNIT_ASSERT(!source.IsCancellationRequested());
+ UNIT_ASSERT(!token.IsCancellationRequested());
+ source.Cancel();
+ UNIT_ASSERT(source.IsCancellationRequested());
+ UNIT_ASSERT(token.IsCancellationRequested());
+ }
+
+ Y_UNIT_TEST(ThrowIfCancellationRequested) {
+ TCancellationTokenSource source;
+ auto const token = source.Token();
+ UNIT_ASSERT_NO_EXCEPTION(token.ThrowIfCancellationRequested());
+ source.Cancel();
+ UNIT_ASSERT_EXCEPTION(token.ThrowIfCancellationRequested(), TOperationCancelledException);
+ }
+
+ Y_UNIT_TEST(Wait) {
+ TCancellationTokenSource source;
+ auto const token = source.Token();
+ UNIT_ASSERT(!token.Wait(TDuration::MilliSeconds(10)));
+ source.Cancel();
+ UNIT_ASSERT(token.Wait(TDuration::MilliSeconds(10)));
+ }
+
+ Y_UNIT_TEST(Future) {
+ TCancellationTokenSource source;
+ auto const future = source.Token().Future();
+ UNIT_ASSERT(!future.HasValue());
+ UNIT_ASSERT(!future.HasException());
+ source.Cancel();
+ UNIT_ASSERT(future.HasValue());
+ }
+
+ Y_UNIT_TEST(Default) {
+ auto const& token = TCancellationToken::Default();
+ UNIT_ASSERT(!token.IsCancellationRequested());
+ }
+
+ Y_UNIT_TEST(ThrowIfDeadlineReached) {
+ TCancellationTokenSource source;
+ auto token = source.Token();
+ UNIT_ASSERT_NO_EXCEPTION(token.ThrowIfCancellationRequested());
+ token.SetDeadline(TInstant::Now() - TDuration::Minutes(1));
+ UNIT_ASSERT_NO_EXCEPTION(token.ThrowIfCancellationRequested());
+ UNIT_ASSERT_EXCEPTION(token.ThrowIfDeadlineReached(), TOperationCancelledException);
+ }
+}
diff --git a/library/cpp/threading/cancellation/ut/ya.make b/library/cpp/threading/cancellation/ut/ya.make
new file mode 100644
index 00000000000..75f2f942f6d
--- /dev/null
+++ b/library/cpp/threading/cancellation/ut/ya.make
@@ -0,0 +1,7 @@
+UNITTEST_FOR(library/cpp/threading/cancellation)
+
+SRCS(
+ ut.cpp
+)
+
+END()
diff --git a/library/cpp/threading/cancellation/ya.make b/library/cpp/threading/cancellation/ya.make
index e9988f0f08b..89373871af7 100644
--- a/library/cpp/threading/cancellation/ya.make
+++ b/library/cpp/threading/cancellation/ya.make
@@ -9,3 +9,5 @@ SRCS(
)
END()
+
+RECURSE_FOR_TESTS(ut)