MCPcopy Create free account
hub / github.com/catboost/catboost / TestCancelWithException

Method TestCancelWithException

library/cpp/coroutine/engine/coroutine_ut.cpp:1018–1050  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1016}
1017
1018void TCoroTest::TestCancelWithException() {
1019 TContExecutor exec(32000);
1020
1021 TString excText = "test exception";
1022 THolder<std::exception> excep = MakeHolder<yexception>(yexception() << excText);
1023 std::exception* excPtr = excep.Get();
1024
1025 exec.CreateOwned([&](TCont* cont){
1026 TCont *cont1 = cont->Executor()->CreateOwned([&](TCont* c) {
1027 int result = c->SleepD(TDuration::MilliSeconds(200).ToDeadLine());
1028 UNIT_ASSERT_EQUAL(result, ECANCELED);
1029 UNIT_ASSERT_EQUAL(c->Cancelled(), true);
1030 THolder<std::exception> exc = c->TakeException();
1031 UNIT_ASSERT_EQUAL(exc.Get(), excPtr);
1032 UNIT_ASSERT_EQUAL(exc->what(), excText);
1033 UNIT_ASSERT(dynamic_cast<yexception*>(exc.Get()) != nullptr);
1034 }, "cancelExc");
1035 cont1->Cancel(std::move(excep));
1036
1037 TCont* cont2 = cont->Executor()->CreateOwned([&](TCont* c) {
1038 int result = c->SleepD(TDuration::MilliSeconds(200).ToDeadLine());
1039 UNIT_ASSERT_EQUAL(result, ECANCELED);
1040 UNIT_ASSERT_EQUAL(c->Cancelled(), true);
1041 THolder<std::exception> exc = c->TakeException();
1042 UNIT_ASSERT_EQUAL(exc.Get(), nullptr);
1043 }, "cancelTwice");
1044 cont2->Cancel();
1045 THolder<std::exception> e = MakeHolder<yexception>(yexception() << "another exception");
1046 cont2->Cancel(std::move(e));
1047 }, "coro");
1048
1049 exec.Execute();
1050}
1051UNIT_TEST_SUITE_REGISTRATION(TCoroTest);

Callers

nothing calls this directly

Calls 13

yexceptionClass · 0.85
MilliSecondsFunction · 0.85
CreateOwnedMethod · 0.80
SleepDMethod · 0.80
ToDeadLineMethod · 0.80
CancelledMethod · 0.80
TakeExceptionMethod · 0.80
moveFunction · 0.50
GetMethod · 0.45
ExecutorMethod · 0.45
whatMethod · 0.45
CancelMethod · 0.45

Tested by

no test coverage detected