Skip to content

Commit 421a15c

Browse files
committed
review comments
1 parent 3dc9840 commit 421a15c

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

grpc/src/client/load_balancing/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ use crate::client::{
5353

5454
pub mod child_manager;
5555
pub mod pick_first;
56+
#[cfg(test)]
57+
pub mod test_utils;
5658

5759
pub(crate) mod registry;
5860
use super::{service_config::LbConfig, subchannel::SubchannelStateWatcher};

grpc/src/client/load_balancing/test_utils.rs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,15 @@
2222
*
2323
*/
2424

25-
use crate::client::{
26-
load_balancing::{
27-
ChannelController, ExternalSubchannel, ForwardingSubchannel, LbState, Subchannel,
28-
WorkScheduler,
29-
},
30-
name_resolution::Address,
25+
use crate::client::load_balancing::{
26+
ChannelController, ExternalSubchannel, ForwardingSubchannel, LbState, Subchannel, WorkScheduler,
3127
};
28+
use crate::client::name_resolution::Address;
3229
use crate::service::{Message, Request, Response, Service};
33-
use std::{
34-
fmt::Display,
35-
hash::{Hash, Hasher},
36-
ops::Add,
37-
sync::Arc,
38-
};
39-
use tokio::{
40-
sync::{mpsc, Notify},
41-
task::AbortHandle,
42-
};
30+
use std::hash::{Hash, Hasher};
31+
use std::{fmt::Display, ops::Add, sync::Arc};
32+
use tokio::sync::{mpsc, Notify};
33+
use tokio::task::AbortHandle;
4334

4435
pub(crate) struct EmptyMessage {}
4536
impl Message for EmptyMessage {}
@@ -90,13 +81,13 @@ impl Hash for TestSubchannel {
9081

9182
impl PartialEq for TestSubchannel {
9283
fn eq(&self, other: &Self) -> bool {
93-
self.address == other.address
84+
std::ptr::eq(self, other)
9485
}
9586
}
9687
impl Eq for TestSubchannel {}
9788

9889
pub(crate) enum TestEvent {
99-
NewSubchannel(Address, Arc<dyn Subchannel>),
90+
NewSubchannel(Arc<dyn Subchannel>),
10091
UpdatePicker(LbState),
10192
RequestResolution,
10293
Connect(Address),
@@ -106,7 +97,7 @@ pub(crate) enum TestEvent {
10697
impl Display for TestEvent {
10798
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10899
match self {
109-
Self::NewSubchannel(addr, _) => write!(f, "NewSubchannel({})", addr),
100+
Self::NewSubchannel(sc) => write!(f, "NewSubchannel({})", sc.address()),
110101
Self::UpdatePicker(state) => write!(f, "UpdatePicker({})", state.connectivity_state),
111102
Self::RequestResolution => write!(f, "RequestResolution"),
112103
Self::Connect(addr) => write!(f, "Connect({})", addr.address.to_string()),
@@ -115,11 +106,11 @@ impl Display for TestEvent {
115106
}
116107
}
117108

118-
// A test channel controller that forwards calls to a channel. This allows
119-
// tests to verify when a channel controller is asked to create subchannels or
120-
// update the picker.
109+
/// A test channel controller that forwards calls to a channel. This allows
110+
/// tests to verify when a channel controller is asked to create subchannels or
111+
/// update the picker.
121112
pub(crate) struct TestChannelController {
122-
pub tx_events: mpsc::UnboundedSender<TestEvent>,
113+
pub(crate) tx_events: mpsc::UnboundedSender<TestEvent>,
123114
}
124115

125116
impl ChannelController for TestChannelController {
@@ -129,10 +120,7 @@ impl ChannelController for TestChannelController {
129120
let subchannel: Arc<dyn Subchannel> =
130121
Arc::new(TestSubchannel::new(address.clone(), self.tx_events.clone()));
131122
self.tx_events
132-
.send(TestEvent::NewSubchannel(
133-
address.clone(),
134-
subchannel.clone(),
135-
))
123+
.send(TestEvent::NewSubchannel(subchannel.clone()))
136124
.unwrap();
137125
subchannel
138126
}
@@ -148,7 +136,7 @@ impl ChannelController for TestChannelController {
148136
}
149137

150138
pub(crate) struct TestWorkScheduler {
151-
pub tx_events: mpsc::UnboundedSender<TestEvent>,
139+
pub(crate) tx_events: mpsc::UnboundedSender<TestEvent>,
152140
}
153141

154142
impl WorkScheduler for TestWorkScheduler {

0 commit comments

Comments
 (0)