Skip to content

Commit 82d765b

Browse files
committed
tests: extract bootstrap() helper
Factor bootstrapping logic (RPC system spawn, Init construct, thread creation) into a reusable async helper. This simplifies writing new integration tests that connect to a running Bitcoin Core IPC socket. Also drops the now-unnecessary `mut` from `let rpc_system` in the integration test.
1 parent af5570e commit 82d765b

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

tests/test.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,41 @@ async fn connect_unix_stream(
3939
VatNetwork::new(buf_reader, buf_writer, Side::Client, Default::default())
4040
}
4141

42+
/// Bootstrap an Init client, spawn the RPC system, and create a thread handle.
43+
async fn bootstrap(
44+
mut rpc_system: RpcSystem<capnp_rpc::rpc_twoparty_capnp::Side>,
45+
) -> (init::Client, thread::Client) {
46+
let client: init::Client = rpc_system.bootstrap(Side::Server);
47+
tokio::task::spawn_local(rpc_system);
48+
let create_client_response = client
49+
.construct_request()
50+
.send()
51+
.promise
52+
.await
53+
.expect("could not create initial request");
54+
let thread_map: thread_map::Client = create_client_response
55+
.get()
56+
.unwrap()
57+
.get_thread_map()
58+
.unwrap();
59+
let thread_reponse = thread_map
60+
.make_thread_request()
61+
.send()
62+
.promise
63+
.await
64+
.unwrap();
65+
let thread: thread::Client = thread_reponse.get().unwrap().get_result().unwrap();
66+
(client, thread)
67+
}
68+
4269
#[tokio::test]
4370
async fn integration() {
4471
let path = unix_socket_path();
4572
let rpc_network = connect_unix_stream(path).await;
46-
let mut rpc_system = RpcSystem::new(Box::new(rpc_network), None);
73+
let rpc_system = RpcSystem::new(Box::new(rpc_network), None);
4774
LocalSet::new()
4875
.run_until(async move {
49-
let client: init::Client = rpc_system.bootstrap(Side::Server);
50-
tokio::task::spawn_local(rpc_system);
51-
let create_client_response = client
52-
.construct_request()
53-
.send()
54-
.promise
55-
.await
56-
.expect("could not create initial request");
57-
let thread_map: thread_map::Client = create_client_response
58-
.get()
59-
.unwrap()
60-
.get_thread_map()
61-
.unwrap();
62-
let thread_reponse = thread_map
63-
.make_thread_request()
64-
.send()
65-
.promise
66-
.await
67-
.unwrap();
68-
let thread: thread::Client = thread_reponse.get().unwrap().get_result().unwrap();
76+
let (client, thread) = bootstrap(rpc_system).await;
6977
let mut echo = client.make_echo_request();
7078
echo.get().get_context().unwrap().set_thread(thread.clone());
7179
let echo_client_request = echo.send().promise.await.unwrap();

0 commit comments

Comments
 (0)