test_timeouts.h 2.1 KB

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