Skip to content

Commit 5032286

Browse files
committed
feat(s2n-quic-platform): emit socket events
1 parent ed9db08 commit 5032286

28 files changed

+1236
-294
lines changed

dc/s2n-quic-dc/src/event/generated.rs

+81-9
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,55 @@ pub mod testing {
438438
use super::*;
439439
use core::sync::atomic::{AtomicU32, Ordering};
440440
use std::sync::Mutex;
441+
pub mod endpoint {
442+
use super::*;
443+
pub struct Subscriber {
444+
location: Option<Location>,
445+
output: Mutex<Vec<String>>,
446+
}
447+
impl Drop for Subscriber {
448+
fn drop(&mut self) {
449+
if std::thread::panicking() {
450+
return;
451+
}
452+
if let Some(location) = self.location.as_ref() {
453+
location.snapshot(&self.output.lock().unwrap());
454+
}
455+
}
456+
}
457+
impl Subscriber {
458+
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
459+
#[track_caller]
460+
pub fn snapshot() -> Self {
461+
let mut sub = Self::no_snapshot();
462+
sub.location = Location::try_new();
463+
sub
464+
}
465+
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
466+
#[track_caller]
467+
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
468+
let mut sub = Self::no_snapshot();
469+
sub.location = Some(Location::from_name(name));
470+
sub
471+
}
472+
#[doc = r" Creates a subscriber with snapshot assertions disabled"]
473+
pub fn no_snapshot() -> Self {
474+
Self {
475+
location: None,
476+
output: Default::default(),
477+
}
478+
}
479+
}
480+
impl super::super::Subscriber for Subscriber {
481+
type ConnectionContext = ();
482+
fn create_connection_context(
483+
&self,
484+
_meta: &api::ConnectionMeta,
485+
_info: &api::ConnectionInfo,
486+
) -> Self::ConnectionContext {
487+
}
488+
}
489+
}
441490
#[derive(Clone, Debug)]
442491
pub struct Subscriber {
443492
location: Option<Location>,
@@ -462,6 +511,13 @@ pub mod testing {
462511
sub.location = Location::try_new();
463512
sub
464513
}
514+
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
515+
#[track_caller]
516+
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
517+
let mut sub = Self::no_snapshot();
518+
sub.location = Some(Location::from_name(name));
519+
sub
520+
}
465521
#[doc = r" Creates a subscriber with snapshot assertions disabled"]
466522
pub fn no_snapshot() -> Self {
467523
Self {
@@ -508,6 +564,13 @@ pub mod testing {
508564
sub.location = Location::try_new();
509565
sub
510566
}
567+
#[doc = r" Creates a publisher with snapshot assertions enabled"]
568+
#[track_caller]
569+
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
570+
let mut sub = Self::no_snapshot();
571+
sub.location = Some(Location::from_name(name));
572+
sub
573+
}
511574
#[doc = r" Creates a publisher with snapshot assertions disabled"]
512575
pub fn no_snapshot() -> Self {
513576
Self {
@@ -548,26 +611,35 @@ pub mod testing {
548611
}
549612
}
550613
#[derive(Clone, Debug)]
551-
struct Location(&'static core::panic::Location<'static>);
614+
struct Location {
615+
location: &'static core::panic::Location<'static>,
616+
name: String,
617+
}
552618
impl Location {
553619
#[track_caller]
620+
#[allow(clippy::manual_map)]
554621
fn try_new() -> Option<Self> {
555622
let thread = std::thread::current();
556-
if thread.name().map_or(false, |name| name != "main") {
557-
Some(Self(core::panic::Location::caller()))
623+
if let Some(name) = thread.name().filter(|name| *name != "main") {
624+
Some(Self::from_name(name))
558625
} else {
559626
None
560627
}
561628
}
629+
#[track_caller]
630+
fn from_name<Name: core::fmt::Display>(name: Name) -> Self {
631+
let location = core::panic::Location::caller();
632+
let name = name.to_string();
633+
Self { location, name }
634+
}
562635
fn snapshot(&self, output: &[String]) {
563636
if cfg!(miri) {
564637
return;
565638
}
566639
use std::path::{Component, Path};
567640
let value = output.join("\n");
568-
let thread = std::thread::current();
569-
let function_name = thread.name().unwrap();
570-
let test_path = Path::new(self.0.file().trim_end_matches(".rs"));
641+
let name = &self.name;
642+
let test_path = Path::new(self.location.file().trim_end_matches(".rs"));
571643
let module_path = test_path
572644
.components()
573645
.filter_map(|comp| match comp {
@@ -582,10 +654,10 @@ pub mod testing {
582654
insta::_macro_support::AutoName.into(),
583655
&value,
584656
current_dir.to_str().unwrap(),
585-
function_name,
657+
name,
586658
&module_path,
587-
self.0.file(),
588-
self.0.line(),
659+
self.location.file(),
660+
self.location.line(),
589661
"",
590662
)
591663
.unwrap()

0 commit comments

Comments
 (0)