| 1016 | } |
| 1017 | |
| 1018 | void 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 | } |
| 1051 | UNIT_TEST_SUITE_REGISTRATION(TCoroTest); |
nothing calls this directly
no test coverage detected