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