blob: d6366be17d8a7e5c8749a1aa498db211b66327d4 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
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 Anton10542f22019-01-11 17:11:0011#include "rtc_base/null_socket_server.h"
Yves Gerey3e707812018-11-28 15:47:4912
13#include <stdint.h>
Jonas Olssona4d87372019-07-05 17:08:3314
Yves Gerey3e707812018-11-28 15:47:4915#include <memory>
16
Evan Shrubsoled9593032025-01-17 13:19:4517#include "api/test/rtc_error_matchers.h"
Markus Handell9a21c492022-08-25 11:40:1318#include "api/units/time_delta.h"
Evan Shrubsoled9593032025-01-17 13:19:4519#include "rtc_base/socket_server.h"
Yves Gerey3e707812018-11-28 15:47:4920#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 17:11:0021#include "rtc_base/time_utils.h"
Evan Shrubsoled9593032025-01-17 13:19:4522#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4923#include "test/gtest.h"
Evan Shrubsoled9593032025-01-17 13:19:4524#include "test/wait_until.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2625
26namespace rtc {
27
Danil Chapovalov1e6965a2022-09-05 09:27:5728TEST(NullSocketServerTest, WaitAndSet) {
Evan Shrubsoled9593032025-01-17 13:19:4529 AutoThread main_thread;
Danil Chapovalov1e6965a2022-09-05 09:27:5730 NullSocketServer ss;
tommie7251592017-07-14 21:44:4631 auto thread = Thread::Create();
32 EXPECT_TRUE(thread->Start());
Danil Chapovalov1e6965a2022-09-05 09:27:5733 thread->PostTask([&ss] { ss.WakeUp(); });
henrike@webrtc.orgf0488722014-05-13 18:00:2634 // The process_io will be ignored.
35 const bool process_io = true;
Evan Shrubsoled9593032025-01-17 13:19:4536 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.orgf0488722014-05-13 18:00:2641}
42
Danil Chapovalov1e6965a2022-09-05 09:27:5743TEST(NullSocketServerTest, TestWait) {
44 NullSocketServer ss;
Honghai Zhang82d78622016-05-06 18:29:1545 int64_t start = TimeMillis();
Danil Chapovalov1e6965a2022-09-05 09:27:5746 ss.Wait(webrtc::TimeDelta::Millis(200), true);
henrike@webrtc.orgf0488722014-05-13 18:00:2647 // 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