2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
21 #include <folly/io/async/test/TimeUtil.h>
22 #include <folly/test/TestUtils.h>
23 #include <gtest/gtest.h>
26 * Check how long a timeout took to fire.
28 * This method verifies:
29 * - that the timeout did not fire too early (never less than expectedMS)
30 * - that the timeout fired within a reasonable period of the expected
31 * duration. It must fire within the specified tolerance, excluding time
32 * that this process spent waiting to be scheduled.
34 * @param start A TimePoint object set just before the timeout
36 * @param end A TimePoint object set when the timeout fired.
37 * @param expectedMS The timeout duration, in milliseconds
38 * @param tolerance The tolerance, in milliseconds.
40 #define T_CHECK_TIMEOUT(start, end, expectedMS, ...) \
41 if (!::folly::checkTimeout((start), (end), \
42 (expectedMS), false, \
44 SKIP() << "T_CHECK_TIMEOUT lapsed"; \
48 * Verify that an event took less than a specified amount of time.
50 * This is similar to T_CHECK_TIMEOUT, but does not fail if the event took less
51 * than the allowed time.
53 #define T_CHECK_TIME_LT(start, end, expectedMS, ...) \
54 if (!::folly::checkTimeout((start), (end), \
57 SKIP() << "T_CHECK_TIMEOUT_LT lapsed"; \