• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2012 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 
11 #include "rtc_base/null_socket_server.h"
12 
13 #include <stdint.h>
14 
15 #include <memory>
16 
17 #include "api/units/time_delta.h"
18 #include "rtc_base/gunit.h"
19 #include "rtc_base/thread.h"
20 #include "rtc_base/time_utils.h"
21 #include "test/gtest.h"
22 
23 namespace rtc {
24 
TEST(NullSocketServerTest,WaitAndSet)25 TEST(NullSocketServerTest, WaitAndSet) {
26   NullSocketServer ss;
27   auto thread = Thread::Create();
28   EXPECT_TRUE(thread->Start());
29   thread->PostTask([&ss] { ss.WakeUp(); });
30   // The process_io will be ignored.
31   const bool process_io = true;
32   EXPECT_TRUE_WAIT(ss.Wait(SocketServer::kForever, process_io), 5'000);
33 }
34 
TEST(NullSocketServerTest,TestWait)35 TEST(NullSocketServerTest, TestWait) {
36   NullSocketServer ss;
37   int64_t start = TimeMillis();
38   ss.Wait(webrtc::TimeDelta::Millis(200), true);
39   // The actual wait time is dependent on the resolution of the timer used by
40   // the Event class. Allow for the event to signal ~20ms early.
41   EXPECT_GE(TimeSince(start), 180);
42 }
43 
44 }  // namespace rtc
45