MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / full_request_response_roundtrip

Function full_request_response_roundtrip

nodedb/src/control/server/session.rs:763–858  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

761 /// End-to-end test: client -> session -> dispatcher -> core_loop -> response -> client.
762 #[tokio::test]
763 async fn full_request_response_roundtrip() {
764 // Set up infrastructure.
765 let dir = tempfile::tempdir().unwrap();
766 let wal_path = dir.path().join("test.wal");
767 let wal = Arc::new(WalManager::open_for_testing(&wal_path).unwrap());
768
769 let (dispatcher, data_sides) = Dispatcher::new(1, 64);
770 let shared = SharedState::new(dispatcher, wal);
771
772 // Start a Data Plane core in a background thread.
773 let data_side = data_sides.into_iter().next().unwrap();
774 let core_dir = dir.path().to_path_buf();
775 let (core_stop_tx, core_stop_rx) = std::sync::mpsc::channel::<()>();
776 let core_handle = tokio::task::spawn_blocking(move || {
777 let mut core = CoreLoop::open(
778 0,
779 data_side.request_rx,
780 data_side.response_tx,
781 &core_dir,
782 std::sync::Arc::new(nodedb_types::OrdinalClock::new()),
783 )
784 .unwrap();
785 while matches!(
786 core_stop_rx.try_recv(),
787 Err(std::sync::mpsc::TryRecvError::Empty)
788 ) {
789 core.tick();
790 std::thread::sleep(Duration::from_millis(1));
791 }
792 });
793
794 // Start response poller.
795 let shared_poller = Arc::clone(&shared);
796 let (poller_stop_tx, mut poller_stop_rx) = tokio::sync::watch::channel(false);
797 let poller_handle = tokio::spawn(async move {
798 loop {
799 shared_poller.poll_and_route_responses();
800 tokio::select! {
801 _ = tokio::time::sleep(Duration::from_millis(1)) => {}
802 _ = poller_stop_rx.changed() => break,
803 }
804 }
805 });
806
807 // Bind a test listener.
808 let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
809 let addr = listener.local_addr().unwrap();
810
811 // Spawn session handler.
812 let shared_session = Arc::clone(&shared);
813 let session_handle = tokio::spawn(async move {
814 let (stream, peer_addr) = listener.accept().await.unwrap();
815 let session = Session::new(
816 stream,
817 peer_addr,
818 shared_session,
819 crate::config::auth::AuthMode::Trust,
820 );

Callers

nothing calls this directly

Calls 14

joinMethod · 0.80
acceptMethod · 0.80
openFunction · 0.50
spawnFunction · 0.50
pathMethod · 0.45
nextMethod · 0.45
tickMethod · 0.45
local_addrMethod · 0.45
runMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected