You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2016 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #if defined(WEBRTC_WIN)
  11. // clang-format off
  12. #include <windows.h> // Must come first.
  13. #include <mmsystem.h>
  14. // clang-format on
  15. #endif
  16. #include <stdint.h>
  17. #include <memory>
  18. #include <utility>
  19. #include <vector>
  20. #include "absl/memory/memory.h"
  21. #include "rtc_base/bind.h"
  22. #include "rtc_base/event.h"
  23. #include "rtc_base/task_queue_for_test.h"
  24. #include "rtc_base/time_utils.h"
  25. #include "test/gtest.h"
  26. namespace rtc {
  27. namespace {
  28. // Noop on all platforms except Windows, where it turns on high precision
  29. // multimedia timers which increases the precision of TimeMillis() while in
  30. // scope.
  31. class EnableHighResTimers {
  32. public:
  33. #if !defined(WEBRTC_WIN)
  34. EnableHighResTimers() {}
  35. #else
  36. EnableHighResTimers() : enabled_(timeBeginPeriod(1) == TIMERR_NOERROR) {}
  37. ~EnableHighResTimers() {
  38. if (enabled_)
  39. timeEndPeriod(1);
  40. }
  41. private:
  42. const bool enabled_;
  43. #endif
  44. };
  45. void CheckCurrent(Event* signal, TaskQueue* queue) {
  46. EXPECT_TRUE(queue->IsCurrent());
  47. if (signal)
  48. signal->Set();
  49. }
  50. } // namespace
  51. // This task needs to be run manually due to the slowness of some of our bots.
  52. // TODO(tommi): Can we run this on the perf bots?
  53. TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) {
  54. EnableHighResTimers high_res_scope;
  55. static const char kQueueName[] = "PostDelayedHighRes";
  56. Event event;
  57. webrtc::TaskQueueForTest queue(kQueueName, TaskQueue::Priority::HIGH);
  58. uint32_t start = Time();
  59. queue.PostDelayedTask(Bind(&CheckCurrent, &event, &queue), 3);
  60. EXPECT_TRUE(event.Wait(1000));
  61. uint32_t end = TimeMillis();
  62. // These tests are a little relaxed due to how "powerful" our test bots can
  63. // be. Most recently we've seen windows bots fire the callback after 94-99ms,
  64. // which is why we have a little bit of leeway backwards as well.
  65. EXPECT_GE(end - start, 3u);
  66. EXPECT_NEAR(end - start, 3, 3u);
  67. }
  68. } // namespace rtc