Skip to content

Commit 39596a5

Browse files
committed
Capture calls to augment_electrical_component_bounds
Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
1 parent 7ea2e33 commit 39596a5

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ tonic = "0.14"
2323
tonic-prost = "0.14"
2424
tracing = { version = "0.1" }
2525
tracing-subscriber = { version = "0.3" }
26+
tokio-stream = { version = "0.1.17", features = ["sync"] }
2627

2728
[dev-dependencies]
2829
tracing-subscriber = { version = "0.3", features = ["std", "env-filter"] }
2930
tokio = { version = "1.48", features = ["test-util"] }
30-
tokio-stream = { version = "0.1.17", features = ["sync"] }
3131

3232

3333
[build-dependencies]

src/client/test_utils.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
mod tokio_synced_clock;
77
pub use tokio_synced_clock::TokioSyncedClock;
88

9+
use std::sync::Mutex;
910
use std::{sync::Arc, time::SystemTime};
10-
1111
use tokio_stream::wrappers::ReceiverStream;
1212
use tonic::Response;
1313

14+
use super::MicrogridApiClient;
1415
use crate::wall_clock_timer::Clock as _;
1516
use crate::{
1617
client::proto::{
1718
common::{
1819
metrics::{
19-
Bounds, Metric, MetricSample, MetricValueVariant, SimpleMetricValue, metric_value_variant,
20+
Bounds, Metric, MetricSample, MetricValueVariant, SimpleMetricValue,
21+
metric_value_variant,
2022
},
2123
microgrid::electrical_components::{
2224
ElectricalComponent, ElectricalComponentCategory,
2325
ElectricalComponentCategorySpecificInfo, ElectricalComponentConnection,
2426
ElectricalComponentStateCode, ElectricalComponentStateSnapshot,
25-
ElectricalComponentTelemetry, Inverter, InverterType,
27+
ElectricalComponentTelemetry, Inverter, InverterType, MetricConfigBounds,
2628
electrical_component_category_specific_info::Kind,
27-
MetricConfigBounds,
2829
},
2930
},
3031
google::protobuf,
@@ -38,7 +39,6 @@ use crate::{
3839
},
3940
quantity::{Current, Power, ReactivePower, Voltage},
4041
};
41-
use super::MicrogridApiClient;
4242

4343
/// A mock implementation of the `MicrogridApiClient` trait for testing purposes.
4444
///
@@ -52,6 +52,7 @@ pub struct MockMicrogridApiClient {
5252
/// share a clone with [`LogicalMeterActor`], and pass another in via
5353
/// [`MockMicrogridApiClient::new_with_clock`].
5454
clock: TokioSyncedClock,
55+
pub augment_bounds_calls: Arc<Mutex<Vec<AugmentElectricalComponentBoundsRequest>>>,
5556
}
5657

5758
/// One row per emitted telemetry frame: `(power, reactive_power, voltage,
@@ -182,13 +183,18 @@ impl MockComponent {
182183
self
183184
}
184185

185-
pub fn add_component_bounds(mut self, metric: i32, lower: Option<f32>, upper: Option<f32>) -> Self {
186-
self.component.metric_config_bounds.push(
187-
MetricConfigBounds {
186+
pub fn add_component_bounds(
187+
mut self,
188+
metric: i32,
189+
lower: Option<f32>,
190+
upper: Option<f32>,
191+
) -> Self {
192+
self.component
193+
.metric_config_bounds
194+
.push(MetricConfigBounds {
188195
metric,
189-
config_bounds: Some(Bounds {lower, upper}),
190-
}
191-
);
196+
config_bounds: Some(Bounds { lower, upper }),
197+
});
192198
self
193199
}
194200

@@ -298,6 +304,7 @@ impl MockMicrogridApiClient {
298304
components: vec![],
299305
connections: vec![],
300306
clock,
307+
augment_bounds_calls: Arc::new(Mutex::new(Vec::new())),
301308
};
302309

303310
fn traverse(node: &MockComponent, client: &mut MockMicrogridApiClient) {
@@ -315,6 +322,13 @@ impl MockMicrogridApiClient {
315322

316323
this_client
317324
}
325+
326+
/// Return a handle to captured augment bounds requests.
327+
pub fn augment_bounds_calls_handle(
328+
&self,
329+
) -> Arc<Mutex<Vec<AugmentElectricalComponentBoundsRequest>>> {
330+
self.augment_bounds_calls.clone()
331+
}
318332
}
319333

320334
#[async_trait::async_trait]
@@ -510,7 +524,13 @@ impl MicrogridApiClient for MockMicrogridApiClient {
510524
_request: impl tonic::IntoRequest<AugmentElectricalComponentBoundsRequest> + Send,
511525
) -> std::result::Result<tonic::Response<AugmentElectricalComponentBoundsResponse>, tonic::Status>
512526
{
513-
unimplemented!()
527+
// Capture calls for tests
528+
let req = _request.into_request().into_inner();
529+
self.augment_bounds_calls.lock().unwrap().push(req);
530+
531+
Ok(Response::new(AugmentElectricalComponentBoundsResponse {
532+
valid_until_time: None,
533+
}))
514534
}
515535
}
516536

0 commit comments

Comments
 (0)