2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/null_socket_server.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
2022-08-25 11:40:13 +00:00
|
|
|
#include "api/units/time_delta.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/thread.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
2022-09-05 11:27:57 +02:00
|
|
|
TEST(NullSocketServerTest, WaitAndSet) {
|
|
|
|
|
NullSocketServer ss;
|
2017-07-14 14:44:46 -07:00
|
|
|
auto thread = Thread::Create();
|
|
|
|
|
EXPECT_TRUE(thread->Start());
|
2022-09-05 11:27:57 +02:00
|
|
|
thread->PostTask([&ss] { ss.WakeUp(); });
|
2014-05-13 18:00:26 +00:00
|
|
|
// The process_io will be ignored.
|
|
|
|
|
const bool process_io = true;
|
2022-09-05 11:27:57 +02:00
|
|
|
EXPECT_TRUE_WAIT(ss.Wait(SocketServer::kForever, process_io), 5'000);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-05 11:27:57 +02:00
|
|
|
TEST(NullSocketServerTest, TestWait) {
|
|
|
|
|
NullSocketServer ss;
|
2016-05-06 11:29:15 -07:00
|
|
|
int64_t start = TimeMillis();
|
2022-09-05 11:27:57 +02:00
|
|
|
ss.Wait(webrtc::TimeDelta::Millis(200), true);
|
2014-05-13 18:00:26 +00:00
|
|
|
// The actual wait time is dependent on the resolution of the timer used by
|
|
|
|
|
// the Event class. Allow for the event to signal ~20ms early.
|
|
|
|
|
EXPECT_GE(TimeSince(start), 180);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|