henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "rtc_base/null_socket_server.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 12 | |
| 13 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 15 | #include <memory> |
| 16 | |
Evan Shrubsole | d959303 | 2025-01-17 13:19:45 | [diff] [blame] | 17 | #include "api/test/rtc_error_matchers.h" |
Markus Handell | 9a21c49 | 2022-08-25 11:40:13 | [diff] [blame] | 18 | #include "api/units/time_delta.h" |
Evan Shrubsole | d959303 | 2025-01-17 13:19:45 | [diff] [blame] | 19 | #include "rtc_base/socket_server.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 20 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "rtc_base/time_utils.h" |
Evan Shrubsole | d959303 | 2025-01-17 13:19:45 | [diff] [blame] | 22 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 23 | #include "test/gtest.h" |
Evan Shrubsole | d959303 | 2025-01-17 13:19:45 | [diff] [blame] | 24 | #include "test/wait_until.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 25 | |
| 26 | namespace rtc { |
| 27 | |
Danil Chapovalov | 1e6965a | 2022-09-05 09:27:57 | [diff] [blame] | 28 | TEST(NullSocketServerTest, WaitAndSet) { |
Evan Shrubsole | d959303 | 2025-01-17 13:19:45 | [diff] [blame] | 29 | AutoThread main_thread; |
Danil Chapovalov | 1e6965a | 2022-09-05 09:27:57 | [diff] [blame] | 30 | NullSocketServer ss; |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 31 | auto thread = Thread::Create(); |
| 32 | EXPECT_TRUE(thread->Start()); |
Danil Chapovalov | 1e6965a | 2022-09-05 09:27:57 | [diff] [blame] | 33 | thread->PostTask([&ss] { ss.WakeUp(); }); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 34 | // The process_io will be ignored. |
| 35 | const bool process_io = true; |
Evan Shrubsole | d959303 | 2025-01-17 13:19:45 | [diff] [blame] | 36 | EXPECT_THAT( |
| 37 | webrtc::WaitUntil( |
| 38 | [&] { return ss.Wait(SocketServer::kForever, process_io); }, |
| 39 | ::testing::IsTrue(), {.timeout = webrtc::TimeDelta::Millis(5'000)}), |
| 40 | webrtc::IsRtcOk()); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 41 | } |
| 42 | |
Danil Chapovalov | 1e6965a | 2022-09-05 09:27:57 | [diff] [blame] | 43 | TEST(NullSocketServerTest, TestWait) { |
| 44 | NullSocketServer ss; |
Honghai Zhang | 82d7862 | 2016-05-06 18:29:15 | [diff] [blame] | 45 | int64_t start = TimeMillis(); |
Danil Chapovalov | 1e6965a | 2022-09-05 09:27:57 | [diff] [blame] | 46 | ss.Wait(webrtc::TimeDelta::Millis(200), true); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 47 | // The actual wait time is dependent on the resolution of the timer used by |
| 48 | // the Event class. Allow for the event to signal ~20ms early. |
| 49 | EXPECT_GE(TimeSince(start), 180); |
| 50 | } |
| 51 | |
| 52 | } // namespace rtc |