xref: /llvm-project/llvm/unittests/Support/ExponentialBackoffTest.cpp (revision edff3ff4d37a9e051e33146393b064ce987af252)
1*edff3ff4SMichael Spencer //===- unittests/ExponentialBackoffTest.cpp -------------------------------===//
2*edff3ff4SMichael Spencer //
3*edff3ff4SMichael Spencer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*edff3ff4SMichael Spencer // See https://llvm.org/LICENSE.txt for license information.
5*edff3ff4SMichael Spencer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*edff3ff4SMichael Spencer //
7*edff3ff4SMichael Spencer //===----------------------------------------------------------------------===//
8*edff3ff4SMichael Spencer 
9*edff3ff4SMichael Spencer #include "llvm/Support/ExponentialBackoff.h"
10*edff3ff4SMichael Spencer #include "gtest/gtest.h"
11*edff3ff4SMichael Spencer #include <chrono>
12*edff3ff4SMichael Spencer 
13*edff3ff4SMichael Spencer using namespace llvm;
14*edff3ff4SMichael Spencer using namespace std::chrono_literals;
15*edff3ff4SMichael Spencer 
16*edff3ff4SMichael Spencer namespace {
17*edff3ff4SMichael Spencer 
TEST(ExponentialBackoffTest,Timeout)18*edff3ff4SMichael Spencer TEST(ExponentialBackoffTest, Timeout) {
19*edff3ff4SMichael Spencer   auto Start = std::chrono::steady_clock::now();
20*edff3ff4SMichael Spencer   // Use short enough times that this test runs quickly.
21*edff3ff4SMichael Spencer   ExponentialBackoff Backoff(100ms, 1ms, 10ms);
22*edff3ff4SMichael Spencer   do {
23*edff3ff4SMichael Spencer   } while (Backoff.waitForNextAttempt());
24*edff3ff4SMichael Spencer   auto Duration = std::chrono::steady_clock::now() - Start;
25*edff3ff4SMichael Spencer   EXPECT_GE(Duration, 100ms);
26*edff3ff4SMichael Spencer }
27*edff3ff4SMichael Spencer 
28*edff3ff4SMichael Spencer // Testing individual wait duration is omitted as those tests would be
29*edff3ff4SMichael Spencer // non-deterministic.
30*edff3ff4SMichael Spencer 
31*edff3ff4SMichael Spencer } // end anonymous namespace
32