1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_TEST_TIMEOUTS_H_ 6 #define BASE_TEST_TEST_TIMEOUTS_H_ 7 8 #include "base/check.h" 9 #include "base/time/time.h" 10 11 // Returns common timeouts to use in tests. Makes it possible to adjust 12 // the timeouts for different environments (like TSan). 13 class TestTimeouts { 14 public: 15 TestTimeouts() = delete; 16 TestTimeouts(const TestTimeouts&) = delete; 17 TestTimeouts& operator=(const TestTimeouts&) = delete; 18 19 // Initializes the timeouts. Non thread-safe. Should be called exactly once 20 // by the test suite. 21 static void Initialize(); 22 23 // Timeout for actions that are expected to finish "almost instantly". This 24 // is used in various tests to post delayed tasks and usually functions more 25 // like a delay value than a timeout. tiny_timeout()26 static base::TimeDelta tiny_timeout() { 27 DCHECK(initialized_); 28 return tiny_timeout_; 29 } 30 31 // Timeout to wait for something to happen. If you are not sure 32 // which timeout to use, this is the one you want. action_timeout()33 static base::TimeDelta action_timeout() { 34 DCHECK(initialized_); 35 return action_timeout_; 36 } 37 38 // Timeout longer than the above, suitable to wait on success conditions which 39 // can take a while to achieve but still should expire on failure before 40 // |test_launcher_timeout()| terminates the process. Note that 41 // test_launcher_timeout() can be reached nonetheless when multiple such 42 // actions are compounded in the same test. action_max_timeout()43 static base::TimeDelta action_max_timeout() { 44 DCHECK(initialized_); 45 return action_max_timeout_; 46 } 47 48 // Timeout for a single test launched used built-in test launcher. 49 // Do not use outside of the test launcher. test_launcher_timeout()50 static base::TimeDelta test_launcher_timeout() { 51 DCHECK(initialized_); 52 return test_launcher_timeout_; 53 } 54 55 private: 56 static bool initialized_; 57 58 static base::TimeDelta tiny_timeout_; 59 static base::TimeDelta action_timeout_; 60 static base::TimeDelta action_max_timeout_; 61 static base::TimeDelta test_launcher_timeout_; 62 }; 63 64 #endif // BASE_TEST_TEST_TIMEOUTS_H_ 65