Skip to content

Commit

Permalink
feat(s2n-quic-platform): emit socket events
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Oct 25, 2024
1 parent ed9db08 commit 5032286
Show file tree
Hide file tree
Showing 28 changed files with 1,236 additions and 294 deletions.
90 changes: 81 additions & 9 deletions dc/s2n-quic-dc/src/event/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,55 @@ pub mod testing {
use super::*;
use core::sync::atomic::{AtomicU32, Ordering};
use std::sync::Mutex;
pub mod endpoint {
use super::*;
pub struct Subscriber {
location: Option<Location>,
output: Mutex<Vec<String>>,
}
impl Drop for Subscriber {
fn drop(&mut self) {
if std::thread::panicking() {
return;
}
if let Some(location) = self.location.as_ref() {
location.snapshot(&self.output.lock().unwrap());
}
}
}
impl Subscriber {
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
#[track_caller]
pub fn snapshot() -> Self {
let mut sub = Self::no_snapshot();
sub.location = Location::try_new();
sub
}
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
#[track_caller]
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
let mut sub = Self::no_snapshot();
sub.location = Some(Location::from_name(name));
sub
}
#[doc = r" Creates a subscriber with snapshot assertions disabled"]
pub fn no_snapshot() -> Self {
Self {
location: None,
output: Default::default(),
}
}
}
impl super::super::Subscriber for Subscriber {
type ConnectionContext = ();
fn create_connection_context(
&self,
_meta: &api::ConnectionMeta,
_info: &api::ConnectionInfo,
) -> Self::ConnectionContext {
}
}
}
#[derive(Clone, Debug)]
pub struct Subscriber {
location: Option<Location>,
Expand All @@ -462,6 +511,13 @@ pub mod testing {
sub.location = Location::try_new();
sub
}
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
#[track_caller]
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
let mut sub = Self::no_snapshot();
sub.location = Some(Location::from_name(name));
sub
}
#[doc = r" Creates a subscriber with snapshot assertions disabled"]
pub fn no_snapshot() -> Self {
Self {
Expand Down Expand Up @@ -508,6 +564,13 @@ pub mod testing {
sub.location = Location::try_new();
sub
}
#[doc = r" Creates a publisher with snapshot assertions enabled"]
#[track_caller]
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
let mut sub = Self::no_snapshot();
sub.location = Some(Location::from_name(name));
sub
}
#[doc = r" Creates a publisher with snapshot assertions disabled"]
pub fn no_snapshot() -> Self {
Self {
Expand Down Expand Up @@ -548,26 +611,35 @@ pub mod testing {
}
}
#[derive(Clone, Debug)]
struct Location(&'static core::panic::Location<'static>);
struct Location {
location: &'static core::panic::Location<'static>,
name: String,
}
impl Location {
#[track_caller]
#[allow(clippy::manual_map)]
fn try_new() -> Option<Self> {
let thread = std::thread::current();
if thread.name().map_or(false, |name| name != "main") {
Some(Self(core::panic::Location::caller()))
if let Some(name) = thread.name().filter(|name| *name != "main") {
Some(Self::from_name(name))
} else {
None
}
}
#[track_caller]
fn from_name<Name: core::fmt::Display>(name: Name) -> Self {
let location = core::panic::Location::caller();
let name = name.to_string();
Self { location, name }
}
fn snapshot(&self, output: &[String]) {
if cfg!(miri) {
return;
}
use std::path::{Component, Path};
let value = output.join("\n");
let thread = std::thread::current();
let function_name = thread.name().unwrap();
let test_path = Path::new(self.0.file().trim_end_matches(".rs"));
let name = &self.name;
let test_path = Path::new(self.location.file().trim_end_matches(".rs"));
let module_path = test_path
.components()
.filter_map(|comp| match comp {
Expand All @@ -582,10 +654,10 @@ pub mod testing {
insta::_macro_support::AutoName.into(),
&value,
current_dir.to_str().unwrap(),
function_name,
name,
&module_path,
self.0.file(),
self.0.line(),
self.location.file(),
self.location.line(),
"",
)
.unwrap()
Expand Down
Loading

0 comments on commit 5032286

Please sign in to comment.