]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/tests/unit/abort_source_test.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / seastar / tests / unit / abort_source_test.cc
1 /*
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.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2017 ScyllaDB
20 */
21
22 #include <seastar/testing/test_case.hh>
23
24 #include <seastar/core/gate.hh>
25 #include <seastar/core/sleep.hh>
26
27 using namespace seastar;
28 using namespace std::chrono_literals;
29
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] {
34 signalled = true;
35 });
36 BOOST_REQUIRE_EQUAL(true, bool(st_opt));
37 as.request_abort();
38 BOOST_REQUIRE_EQUAL(true, signalled);
39 return make_ready_future<>();
40 }
41
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] {
46 signalled = true;
47 });
48 BOOST_REQUIRE_EQUAL(true, bool(st_opt));
49 st_opt = { };
50 as.request_abort();
51 BOOST_REQUIRE_EQUAL(false, signalled);
52 return make_ready_future<>();
53 }
54
55 SEASTAR_TEST_CASE(test_abort_source_rejects_subscription) {
56 auto as = abort_source();
57 as.request_abort();
58 auto st_opt = as.subscribe([] { });
59 BOOST_REQUIRE_EQUAL(false, bool(st_opt));
60 return make_ready_future<>();
61 }
62
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) {
66 try {
67 f.get();
68 BOOST_FAIL("should have failed");
69 } catch (const sleep_aborted& e) {
70 // expected
71 } catch (...) {
72 BOOST_FAIL("unexpected exception");
73 }
74 });
75 as->request_abort();
76 return f.finally([as = std::move(as)] { });
77 }