blob: 58a6211abad2ea81bb4a10e033d698e3f43cda29 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 09:11:00 -080011#include "rtc_base/null_socket_server.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012
13#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <memory>
16
Markus Handell9a21c492022-08-25 11:40:13 +000017#include "api/units/time_delta.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/time_utils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000022
23namespace rtc {
24
Danil Chapovalov1e6965a2022-09-05 11:27:57 +020025TEST(NullSocketServerTest, WaitAndSet) {
26 NullSocketServer ss;
tommie7251592017-07-14 14:44:46 -070027 auto thread = Thread::Create();
28 EXPECT_TRUE(thread->Start());
Danil Chapovalov1e6965a2022-09-05 11:27:57 +020029 thread->PostTask([&ss] { ss.WakeUp(); });
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000030 // The process_io will be ignored.
31 const bool process_io = true;
Danil Chapovalov1e6965a2022-09-05 11:27:57 +020032 EXPECT_TRUE_WAIT(ss.Wait(SocketServer::kForever, process_io), 5'000);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000033}
34
Danil Chapovalov1e6965a2022-09-05 11:27:57 +020035TEST(NullSocketServerTest, TestWait) {
36 NullSocketServer ss;
Honghai Zhang82d78622016-05-06 11:29:15 -070037 int64_t start = TimeMillis();
Danil Chapovalov1e6965a2022-09-05 11:27:57 +020038 ss.Wait(webrtc::TimeDelta::Millis(200), true);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000039 // 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