]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/tests/unit/timer_test.cc
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) 2014 Cloudius Systems, Ltd.
22 #include <seastar/core/app-template.hh>
23 #include <seastar/core/reactor.hh>
24 #include <seastar/core/print.hh>
28 using namespace seastar
;
29 using namespace std::chrono_literals
;
32 std::cerr << "ERROR @ " << __FILE__ << ":" << __LINE__ << std::endl; \
33 throw std::runtime_error("test failed"); \
37 std::cerr << "OK @ " << __FILE__ << ":" << __LINE__ << std::endl; \
40 template <typename Clock
>
51 t1
.set_callback([this] {
53 fmt::print(" 500ms timer expired\n");
62 t2
.set_callback([] { OK(); fmt::print(" 900ms timer expired\n"); });
63 t3
.set_callback([] { OK(); fmt::print("1000ms timer expired\n"); });
64 t4
.set_callback([] { OK(); fmt::print(" BAD cancelled timer expired\n"); });
65 t5
.set_callback([this] { OK(); fmt::print("1600ms rearmed timer expired\n"); pr1
.set_value(); });
73 return pr1
.get_future().then([this] { return test_timer_cancelling(); });
76 future
<> test_timer_cancelling() {
77 timer
<Clock
>& t1
= *new timer
<Clock
>();
78 t1
.set_callback([] { BUG(); });
85 t1
.set_callback([this] { OK(); pr2
.set_value(); });
87 return pr2
.get_future().then([&t1
] { delete &t1
; });
91 int main(int ac
, char** av
) {
93 timer_test
<steady_clock_type
> t1
;
94 timer_test
<lowres_clock
> t2
;
95 return app
.run_deprecated(ac
, av
, [&t1
, &t2
] {
96 fmt::print("=== Start High res clock test\n");
97 return t1
.run().then([&t2
] {
98 fmt::print("=== Start Low res clock test\n");
101 fmt::print("Done\n");