Skip to content

Commit

Permalink
CI fixes and correction to make test work
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Oct 31, 2024
1 parent 52d4775 commit c875d60
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion common/client-core/src/client/base_client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022-2023 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: Apache-2.0

use super::metrics::{MetricsSender, MetricsController};
use super::metrics::{MetricsController, MetricsSender};
use super::received_buffer::ReceivedBufferMessage;
use super::topology_control::geo_aware_provider::GeoAwareTopologyProvider;
use crate::client::base_client::storage::helpers::store_client_keys;
Expand Down
9 changes: 5 additions & 4 deletions common/client-core/src/client/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,15 @@ mod test {
#[tokio::test]
async fn test_metrics_controller() {
let _ = pretty_env_logger::try_init();
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();

log::info!("print me please");
let (metrics_controller, metrics_sender) = MetricsController::new();
let m = Arc::new(Mutex::new(metrics_controller));
let m1 = Arc::clone(&m);
tokio::spawn(async move {
let mut mc = m1.lock().await;
mc.run_with_shutdown(nym_task::TaskClient::dummy()).await;
shutdown_tx.send(()).unwrap();
});

for _ in 0..10 {
Expand All @@ -314,10 +315,10 @@ mod test {
metrics_sender.report(MetricsEvents::APIMetricsEvent(
APIMetricsEvent::RealPacketSent(3),
));
tokio::time::sleep(Duration::from_secs(3)).await;
tokio::time::sleep(Duration::from_millis(500)).await;
}

// assert_eq!(&m.lock().await.stats.get(&MetricsType::APIStatistics).unwrap().marshall().unwrap(), "PacketStatistics { sent: 3, received: 0 }");
m.lock().await.report_all();
drop(metrics_sender);
shutdown_rx.await.unwrap();
}
}
16 changes: 4 additions & 12 deletions common/client-core/src/client/metrics/api_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ impl APIMetrics {
(
format!("packets sent: {}", self.real_packets_sent,),
String::new(),
// format!(
// "packets received: {}, (real: {}, cover: {}, acks: {}, acks for cover: {})",
// self.real_packets_received + self.cover_packets_received,
// self.real_packets_received,
// self.cover_packets_received,
// self.real_acks_received,
// self.cover_acks_received,
// ),
)
}
}
Expand Down Expand Up @@ -77,15 +69,15 @@ impl super::MetricsObj for APIMetricsControl {
}

fn handle_event(&mut self, event: MetricsEvents) {
match event {
match event {
MetricsEvents::APIMetricsEvent(ev) => self.stats.handle(ev),
_ => log::error!("Received unusable event: {:?}", event.metrics_type()),
}
}

fn snapshot(&mut self) {
// pass
}
fn snapshot(&mut self) {
// pass
}

fn periodic_reset(&mut self) {
self.stats = APIMetrics::default();
Expand Down
3 changes: 2 additions & 1 deletion common/client-core/src/client/metrics/packet_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ impl super::MetricsObj for PacketStatisticsControl {
}

fn periodic_reset(&mut self) {
self.stats = PacketStatistics::default();
// // pass - this stats object is not meant to be reset - causes overflowing subtract
// self.stats = PacketStatistics::default();
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/client-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub mod cover_traffic_stream;
pub(crate) mod helpers;
pub mod inbound_messages;
pub mod key_manager;
pub mod mix_traffic;
pub(crate) mod metrics;
pub mod mix_traffic;
pub mod real_messages_control;
pub mod received_buffer;
pub mod replies;
Expand Down
10 changes: 3 additions & 7 deletions common/client-core/src/client/received_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::client::{
metrics::{ packet_statistics::PacketStatisticsEvent, MetricsSender},
metrics::{packet_statistics::PacketStatisticsEvent, MetricsSender},
replies::{reply_controller::ReplyControllerSender, reply_storage::SentReplyKeys},
};
use crate::spawn_future;
Expand Down Expand Up @@ -61,16 +61,12 @@ impl<R: MessageReceiver> ReceivedMessagesBufferInner<R> {
// received and sent packets due to the sphinx layers being removed by the exit gateway
// before it reaches the mixnet client.
self.stats_tx
.report(PacketStatisticsEvent::CoverPacketReceived(
fragment_data_size,
).into());
.report(PacketStatisticsEvent::CoverPacketReceived(fragment_data_size).into());
return None;
}

self.stats_tx
.report(PacketStatisticsEvent::RealPacketReceived(
fragment_data_size,
).into());
.report(PacketStatisticsEvent::RealPacketReceived(fragment_data_size).into());

let fragment = match self.message_receiver.recover_fragment(fragment_data) {
Err(err) => {
Expand Down

0 comments on commit c875d60

Please sign in to comment.