Skip to content

Commit

Permalink
applying CR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
zajko committed Jan 24, 2025
1 parent 6dee528 commit 08fc39b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions event_sidecar/src/event_stream_server/sse_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ use futures::{future, Stream, StreamExt};
use http::StatusCode;
use hyper::Body;
#[cfg(test)]
use once_cell::sync::Lazy;
#[cfg(test)]
use regex::Regex;
#[cfg(test)]
use serde::Serialize;
#[cfg(test)]
use serde_json::Value;
Expand Down Expand Up @@ -90,6 +94,12 @@ const SIGNATURES_FILTER: [EventFilter; 2] =
[EventFilter::ApiVersion, EventFilter::FinalitySignature];
/// The filter associated with `/events/sidecar` path.
const SIDECAR_FILTER: [EventFilter; 1] = [EventFilter::SidecarVersion];

#[cfg(test)]
static ENDS_WITH_ID_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\nid:\d*$").unwrap());
#[cfg(test)]
static STARTS_WITH_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^data:").unwrap());

/// The "id" field of the events sent on the event stream to clients.
pub type Id = u32;
pub type IsLegacyFilter = bool;
Expand Down Expand Up @@ -684,7 +694,6 @@ mod tests {
use super::*;
use casper_types::{testing::TestRng, TransactionHash};
use rand::Rng;
use regex::Regex;
use std::iter;
#[cfg(feature = "additional-metrics")]
use tokio::sync::mpsc::channel;
Expand Down Expand Up @@ -946,9 +955,6 @@ mod tests {
))
.collect();

let ends_with_id = Regex::new(r"\nid:\d*$").unwrap();
let starts_with_data = Regex::new(r"^data:").unwrap();

// Run three cases; where only a single event is duplicated, where five are duplicated, and
// where the whole initial stream (except the `ApiVersion`) is duplicated.
for duplicate_count in &[1, 5, NUM_INITIAL_EVENTS] {
Expand Down Expand Up @@ -1019,12 +1025,12 @@ mod tests {
if let Some(id) = deduplicated_event.id {
assert!(received_event_str.ends_with(format!("\nid:{}", id).as_str()));
} else {
assert!(!ends_with_id.is_match(received_event_str.as_str()));
assert!(!ENDS_WITH_ID_REGEX.is_match(received_event_str.as_str()));
};
received_event_str = ends_with_id
received_event_str = ENDS_WITH_ID_REGEX
.replace_all(received_event_str.as_str(), "")
.into_owned();
received_event_str = starts_with_data
received_event_str = STARTS_WITH_REGEX
.replace_all(received_event_str.as_str(), "")
.into_owned();
if is_legacy_endpoint {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
channel = "1.84.0"
components = [ "rustfmt", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
profile = "minimal"

0 comments on commit 08fc39b

Please sign in to comment.