2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2017 ScyllaDB
22 #include <seastar/testing/test_case.hh>
24 #include <seastar/core/gate.hh>
25 #include <seastar/core/sleep.hh>
27 using namespace seastar
;
28 using namespace std::chrono_literals
;
30 SEASTAR_TEST_CASE(test_abort_source_notifies_subscriber
) {
31 bool signalled
= false;
32 auto as
= abort_source();
33 auto st_opt
= as
.subscribe([&signalled
] {
36 BOOST_REQUIRE_EQUAL(true, bool(st_opt
));
38 BOOST_REQUIRE_EQUAL(true, signalled
);
39 return make_ready_future
<>();
42 SEASTAR_TEST_CASE(test_abort_source_subscription_unregister
) {
43 bool signalled
= false;
44 auto as
= abort_source();
45 auto st_opt
= as
.subscribe([&signalled
] {
48 BOOST_REQUIRE_EQUAL(true, bool(st_opt
));
51 BOOST_REQUIRE_EQUAL(false, signalled
);
52 return make_ready_future
<>();
55 SEASTAR_TEST_CASE(test_abort_source_rejects_subscription
) {
56 auto as
= abort_source();
58 auto st_opt
= as
.subscribe([] { });
59 BOOST_REQUIRE_EQUAL(false, bool(st_opt
));
60 return make_ready_future
<>();
63 SEASTAR_TEST_CASE(test_sleep_abortable
) {
64 auto as
= std::make_unique
<abort_source
>();
65 auto f
= sleep_abortable(100s
, *as
).then_wrapped([] (auto&& f
) {
68 BOOST_FAIL("should have failed");
69 } catch (const sleep_aborted
& e
) {
72 BOOST_FAIL("unexpected exception");
76 return f
.finally([as
= std::move(as
)] { });