Introduce test-only APIs for configuring how Client reconnects

This commit is contained in:
Max Brunsfeld 2021-09-08 18:19:59 -07:00
parent b6eac57f63
commit edbd424b75
3 changed files with 86 additions and 10 deletions

View file

@ -203,16 +203,42 @@ pub struct FakeServer {
}
impl FakeServer {
pub async fn for_client(user_id: u64, client: &Arc<Client>, cx: &TestAppContext) -> Arc<Self> {
pub async fn for_client(
client_user_id: u64,
client: &mut Arc<Client>,
cx: &TestAppContext,
) -> Arc<Self> {
let result = Arc::new(Self {
peer: Peer::new(),
incoming: Default::default(),
connection_id: Default::default(),
});
Arc::get_mut(client)
.unwrap()
.set_login_and_connect_callbacks(
move |cx| {
cx.spawn(|_| async move {
let access_token = "the-token".to_string();
Ok((client_user_id, access_token))
})
},
{
let server = result.clone();
move |user_id, access_token, cx| {
assert_eq!(user_id, client_user_id);
assert_eq!(access_token, "the-token");
cx.spawn({
let server = server.clone();
move |cx| async move { Ok(server.connect(&cx).await) }
})
}
},
);
let conn = result.connect(&cx.to_async()).await;
client
.set_connection(user_id, conn, &cx.to_async())
.set_connection(client_user_id, conn, &cx.to_async())
.await
.unwrap();
result