mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00
Replace legacy rtc::TaskQueue with TaskQueueBase in test Network helper
rtc::TaskQueue wrapper provide no extra feature there. Bug: webrtc:14169 Change-Id: I91ec99e10400627f1fb6f534cc679e3b11534c0b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/333481 Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41484}
This commit is contained in:
parent
1d6bf3156b
commit
0a96289bcb
5 changed files with 26 additions and 19 deletions
|
@ -47,6 +47,7 @@ rtc_library("emulated_network") {
|
||||||
"../../api:simulated_network_api",
|
"../../api:simulated_network_api",
|
||||||
"../../api:time_controller",
|
"../../api:time_controller",
|
||||||
"../../api/numerics",
|
"../../api/numerics",
|
||||||
|
"../../api/task_queue",
|
||||||
"../../api/task_queue:pending_task_safety_flag",
|
"../../api/task_queue:pending_task_safety_flag",
|
||||||
"../../api/test/network_emulation",
|
"../../api/test/network_emulation",
|
||||||
"../../api/transport:stun_types",
|
"../../api/transport:stun_types",
|
||||||
|
@ -67,7 +68,6 @@ rtc_library("emulated_network") {
|
||||||
"../../rtc_base:random",
|
"../../rtc_base:random",
|
||||||
"../../rtc_base:rtc_base_tests_utils",
|
"../../rtc_base:rtc_base_tests_utils",
|
||||||
"../../rtc_base:rtc_event",
|
"../../rtc_base:rtc_event",
|
||||||
"../../rtc_base:rtc_task_queue",
|
|
||||||
"../../rtc_base:safe_minmax",
|
"../../rtc_base:safe_minmax",
|
||||||
"../../rtc_base:socket",
|
"../../rtc_base:socket",
|
||||||
"../../rtc_base:socket_address",
|
"../../rtc_base:socket_address",
|
||||||
|
@ -87,6 +87,7 @@ rtc_library("emulated_network") {
|
||||||
]
|
]
|
||||||
absl_deps = [
|
absl_deps = [
|
||||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||||
|
"//third_party/abseil-cpp/absl/base:nullability",
|
||||||
"//third_party/abseil-cpp/absl/memory",
|
"//third_party/abseil-cpp/absl/memory",
|
||||||
"//third_party/abseil-cpp/absl/strings",
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
"//third_party/abseil-cpp/absl/types:optional",
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct TrafficCounterFixture {
|
||||||
EmulatedEndpointConfig(),
|
EmulatedEndpointConfig(),
|
||||||
EmulatedNetworkStatsGatheringMode::kDefault,
|
EmulatedNetworkStatsGatheringMode::kDefault,
|
||||||
},
|
},
|
||||||
/*is_enabled=*/true, &task_queue_, &clock};
|
/*is_enabled=*/true, task_queue_.Get(), &clock};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/base/nullability.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "api/numerics/samples_stats_counter.h"
|
#include "api/numerics/samples_stats_counter.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
||||||
#include "api/test/network_emulation_manager.h"
|
#include "api/test/network_emulation_manager.h"
|
||||||
#include "api/units/data_size.h"
|
#include "api/units/data_size.h"
|
||||||
|
@ -330,7 +332,7 @@ void LinkEmulation::OnPacketReceived(EmulatedIpPacket packet) {
|
||||||
return;
|
return;
|
||||||
Timestamp current_time = clock_->CurrentTime();
|
Timestamp current_time = clock_->CurrentTime();
|
||||||
process_task_ = RepeatingTaskHandle::DelayedStart(
|
process_task_ = RepeatingTaskHandle::DelayedStart(
|
||||||
task_queue_->Get(),
|
task_queue_,
|
||||||
std::max(TimeDelta::Zero(),
|
std::max(TimeDelta::Zero(),
|
||||||
Timestamp::Micros(*next_time_us) - current_time),
|
Timestamp::Micros(*next_time_us) - current_time),
|
||||||
[this]() {
|
[this]() {
|
||||||
|
@ -383,7 +385,7 @@ void LinkEmulation::Process(Timestamp at_time) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRouterNode::NetworkRouterNode(rtc::TaskQueue* task_queue)
|
NetworkRouterNode::NetworkRouterNode(absl::Nonnull<TaskQueueBase*> task_queue)
|
||||||
: task_queue_(task_queue) {}
|
: task_queue_(task_queue) {}
|
||||||
|
|
||||||
void NetworkRouterNode::OnPacketReceived(EmulatedIpPacket packet) {
|
void NetworkRouterNode::OnPacketReceived(EmulatedIpPacket packet) {
|
||||||
|
@ -459,7 +461,7 @@ void NetworkRouterNode::SetFilter(
|
||||||
|
|
||||||
EmulatedNetworkNode::EmulatedNetworkNode(
|
EmulatedNetworkNode::EmulatedNetworkNode(
|
||||||
Clock* clock,
|
Clock* clock,
|
||||||
rtc::TaskQueue* task_queue,
|
absl::Nonnull<TaskQueueBase*> task_queue,
|
||||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
||||||
EmulatedNetworkStatsGatheringMode stats_gathering_mode)
|
EmulatedNetworkStatsGatheringMode stats_gathering_mode)
|
||||||
: router_(task_queue),
|
: router_(task_queue),
|
||||||
|
@ -510,10 +512,11 @@ EmulatedEndpointImpl::Options::Options(
|
||||||
config.allow_receive_packets_with_different_dest_ip),
|
config.allow_receive_packets_with_different_dest_ip),
|
||||||
log_name(ip.ToString() + " (" + config.name.value_or("") + ")") {}
|
log_name(ip.ToString() + " (" + config.name.value_or("") + ")") {}
|
||||||
|
|
||||||
EmulatedEndpointImpl::EmulatedEndpointImpl(const Options& options,
|
EmulatedEndpointImpl::EmulatedEndpointImpl(
|
||||||
bool is_enabled,
|
const Options& options,
|
||||||
rtc::TaskQueue* task_queue,
|
bool is_enabled,
|
||||||
Clock* clock)
|
absl::Nonnull<TaskQueueBase*> task_queue,
|
||||||
|
Clock* clock)
|
||||||
: options_(options),
|
: options_(options),
|
||||||
is_enabled_(is_enabled),
|
is_enabled_(is_enabled),
|
||||||
clock_(clock),
|
clock_(clock),
|
||||||
|
|
|
@ -19,10 +19,12 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/base/nullability.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
#include "api/numerics/samples_stats_counter.h"
|
#include "api/numerics/samples_stats_counter.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
||||||
#include "api/test/network_emulation_manager.h"
|
#include "api/test/network_emulation_manager.h"
|
||||||
#include "api/test/simulated_network.h"
|
#include "api/test/simulated_network.h"
|
||||||
|
@ -145,7 +147,7 @@ class EmulatedNetworkNodeStatsBuilder {
|
||||||
class LinkEmulation : public EmulatedNetworkReceiverInterface {
|
class LinkEmulation : public EmulatedNetworkReceiverInterface {
|
||||||
public:
|
public:
|
||||||
LinkEmulation(Clock* clock,
|
LinkEmulation(Clock* clock,
|
||||||
rtc::TaskQueue* task_queue,
|
absl::Nonnull<TaskQueueBase*> task_queue,
|
||||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
||||||
EmulatedNetworkReceiverInterface* receiver,
|
EmulatedNetworkReceiverInterface* receiver,
|
||||||
EmulatedNetworkStatsGatheringMode stats_gathering_mode)
|
EmulatedNetworkStatsGatheringMode stats_gathering_mode)
|
||||||
|
@ -168,7 +170,7 @@ class LinkEmulation : public EmulatedNetworkReceiverInterface {
|
||||||
void Process(Timestamp at_time) RTC_RUN_ON(task_queue_);
|
void Process(Timestamp at_time) RTC_RUN_ON(task_queue_);
|
||||||
|
|
||||||
Clock* const clock_;
|
Clock* const clock_;
|
||||||
rtc::TaskQueue* const task_queue_;
|
const absl::Nonnull<TaskQueueBase*> task_queue_;
|
||||||
const std::unique_ptr<NetworkBehaviorInterface> network_behavior_
|
const std::unique_ptr<NetworkBehaviorInterface> network_behavior_
|
||||||
RTC_GUARDED_BY(task_queue_);
|
RTC_GUARDED_BY(task_queue_);
|
||||||
EmulatedNetworkReceiverInterface* const receiver_;
|
EmulatedNetworkReceiverInterface* const receiver_;
|
||||||
|
@ -186,7 +188,7 @@ class LinkEmulation : public EmulatedNetworkReceiverInterface {
|
||||||
// the packet will be silently dropped.
|
// the packet will be silently dropped.
|
||||||
class NetworkRouterNode : public EmulatedNetworkReceiverInterface {
|
class NetworkRouterNode : public EmulatedNetworkReceiverInterface {
|
||||||
public:
|
public:
|
||||||
explicit NetworkRouterNode(rtc::TaskQueue* task_queue);
|
explicit NetworkRouterNode(absl::Nonnull<TaskQueueBase*> task_queue);
|
||||||
|
|
||||||
void OnPacketReceived(EmulatedIpPacket packet) override;
|
void OnPacketReceived(EmulatedIpPacket packet) override;
|
||||||
void SetReceiver(const rtc::IPAddress& dest_ip,
|
void SetReceiver(const rtc::IPAddress& dest_ip,
|
||||||
|
@ -200,7 +202,7 @@ class NetworkRouterNode : public EmulatedNetworkReceiverInterface {
|
||||||
void SetFilter(std::function<bool(const EmulatedIpPacket&)> filter);
|
void SetFilter(std::function<bool(const EmulatedIpPacket&)> filter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rtc::TaskQueue* const task_queue_;
|
const absl::Nonnull<TaskQueueBase*> task_queue_;
|
||||||
absl::optional<EmulatedNetworkReceiverInterface*> default_receiver_
|
absl::optional<EmulatedNetworkReceiverInterface*> default_receiver_
|
||||||
RTC_GUARDED_BY(task_queue_);
|
RTC_GUARDED_BY(task_queue_);
|
||||||
std::map<rtc::IPAddress, EmulatedNetworkReceiverInterface*> routing_
|
std::map<rtc::IPAddress, EmulatedNetworkReceiverInterface*> routing_
|
||||||
|
@ -224,7 +226,7 @@ class EmulatedNetworkNode : public EmulatedNetworkReceiverInterface {
|
||||||
// they are ready.
|
// they are ready.
|
||||||
EmulatedNetworkNode(
|
EmulatedNetworkNode(
|
||||||
Clock* clock,
|
Clock* clock,
|
||||||
rtc::TaskQueue* task_queue,
|
absl::Nonnull<TaskQueueBase*> task_queue,
|
||||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
||||||
EmulatedNetworkStatsGatheringMode stats_gathering_mode);
|
EmulatedNetworkStatsGatheringMode stats_gathering_mode);
|
||||||
~EmulatedNetworkNode() override;
|
~EmulatedNetworkNode() override;
|
||||||
|
@ -283,7 +285,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint {
|
||||||
|
|
||||||
EmulatedEndpointImpl(const Options& options,
|
EmulatedEndpointImpl(const Options& options,
|
||||||
bool is_enabled,
|
bool is_enabled,
|
||||||
rtc::TaskQueue* task_queue,
|
absl::Nonnull<TaskQueueBase*> task_queue,
|
||||||
Clock* clock);
|
Clock* clock);
|
||||||
~EmulatedEndpointImpl() override;
|
~EmulatedEndpointImpl() override;
|
||||||
|
|
||||||
|
@ -341,7 +343,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint {
|
||||||
const Options options_;
|
const Options options_;
|
||||||
bool is_enabled_ RTC_GUARDED_BY(enabled_state_checker_);
|
bool is_enabled_ RTC_GUARDED_BY(enabled_state_checker_);
|
||||||
Clock* const clock_;
|
Clock* const clock_;
|
||||||
rtc::TaskQueue* const task_queue_;
|
const absl::Nonnull<TaskQueueBase*> task_queue_;
|
||||||
std::unique_ptr<rtc::Network> network_;
|
std::unique_ptr<rtc::Network> network_;
|
||||||
NetworkRouterNode router_;
|
NetworkRouterNode router_;
|
||||||
|
|
||||||
|
|
|
@ -79,8 +79,9 @@ EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
||||||
|
|
||||||
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
||||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior) {
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior) {
|
||||||
auto node = std::make_unique<EmulatedNetworkNode>(
|
auto node = std::make_unique<EmulatedNetworkNode>(clock_, task_queue_.Get(),
|
||||||
clock_, &task_queue_, std::move(network_behavior), stats_gathering_mode_);
|
std::move(network_behavior),
|
||||||
|
stats_gathering_mode_);
|
||||||
EmulatedNetworkNode* out = node.get();
|
EmulatedNetworkNode* out = node.get();
|
||||||
task_queue_.PostTask([this, node = std::move(node)]() mutable {
|
task_queue_.PostTask([this, node = std::move(node)]() mutable {
|
||||||
network_nodes_.push_back(std::move(node));
|
network_nodes_.push_back(std::move(node));
|
||||||
|
@ -115,7 +116,7 @@ EmulatedEndpointImpl* NetworkEmulationManagerImpl::CreateEndpoint(
|
||||||
auto node = std::make_unique<EmulatedEndpointImpl>(
|
auto node = std::make_unique<EmulatedEndpointImpl>(
|
||||||
EmulatedEndpointImpl::Options(next_node_id_++, *ip, config,
|
EmulatedEndpointImpl::Options(next_node_id_++, *ip, config,
|
||||||
stats_gathering_mode_),
|
stats_gathering_mode_),
|
||||||
config.start_as_enabled, &task_queue_, clock_);
|
config.start_as_enabled, task_queue_.Get(), clock_);
|
||||||
EmulatedEndpointImpl* out = node.get();
|
EmulatedEndpointImpl* out = node.get();
|
||||||
endpoints_.push_back(std::move(node));
|
endpoints_.push_back(std::move(node));
|
||||||
return out;
|
return out;
|
||||||
|
|
Loading…
Reference in a new issue