use std::sync::Arc;
use tokio_util::sync::CancellationToken;
use crate::flow_log::{FlowLogSink, FlowLogVerbosity, TrajectoryBuilder};
pub struct FlowCtx {
pub span: tracing::Span,
pub log: Arc<dyn FlowLogSink>,
pub cancel: CancellationToken,
pub accept_cancel: CancellationToken,
pub verbosity: FlowLogVerbosity,
pub trajectory: TrajectoryBuilder,
}
#[cfg(test)]
mod tests {
use parking_lot::Mutex;
use super::*;
use crate::conn_context::ConnId;
use crate::flow_log::FlowLogEvent;
use crate::ir::NodeId;
struct NullSink {
count: Mutex<u32>,
}
impl FlowLogSink for NullSink {
fn emit(&self, _event: FlowLogEvent) {
*self.count.lock() += 1;
}
}
#[test]
fn flow_ctx_accepts_arc_dyn_sink_and_owned_fields() {
let sink: Arc<dyn FlowLogSink> = Arc::new(NullSink { count: Mutex::new(0) });
let span = tracing::Span::none();
let cancel = CancellationToken::new();
let ctx = FlowCtx {
span,
log: sink,
cancel,
accept_cancel: CancellationToken::new(),
verbosity: FlowLogVerbosity::Trajectory,
trajectory: TrajectoryBuilder::new(ConnId(0), NodeId::new(0), 0),
};
let _ = &ctx.span;
let _ = &ctx.log;
let _ = &ctx.cancel;
let _ = &ctx.accept_cancel;
let _ = &ctx.verbosity;
let _ = &ctx.trajectory;
}
}