test_server.rs

  1use crate::{
  2    db::{tests::TestDb, NewUserParams, UserId},
  3    executor::Executor,
  4    rpc::{Server, CLEANUP_TIMEOUT, RECONNECT_TIMEOUT},
  5    AppState, Config,
  6};
  7use anyhow::anyhow;
  8use call::ActiveCall;
  9use channel::{ChannelBuffer, ChannelStore};
 10use client::{
 11    self, proto::PeerId, Client, Connection, Credentials, EstablishConnectionError, UserStore,
 12};
 13use collections::{HashMap, HashSet};
 14use fs::FakeFs;
 15use futures::{channel::oneshot, StreamExt as _};
 16use gpui::{BackgroundExecutor, Context, Model, TestAppContext, View, VisualTestContext};
 17use language::LanguageRegistry;
 18use node_runtime::FakeNodeRuntime;
 19
 20use notifications::NotificationStore;
 21use parking_lot::Mutex;
 22use project::{Project, WorktreeId};
 23use rpc::{
 24    proto::{self, ChannelRole},
 25    RECEIVE_TIMEOUT,
 26};
 27use serde_json::json;
 28use settings::SettingsStore;
 29use std::{
 30    cell::{Ref, RefCell, RefMut},
 31    env,
 32    ops::{Deref, DerefMut},
 33    path::Path,
 34    sync::{
 35        atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst},
 36        Arc,
 37    },
 38};
 39use util::http::FakeHttpClient;
 40use workspace::{Workspace, WorkspaceStore};
 41
 42pub struct TestServer {
 43    pub app_state: Arc<AppState>,
 44    pub test_live_kit_server: Arc<live_kit_client::TestServer>,
 45    server: Arc<Server>,
 46    next_github_user_id: i32,
 47    connection_killers: Arc<Mutex<HashMap<PeerId, Arc<AtomicBool>>>>,
 48    forbid_connections: Arc<AtomicBool>,
 49    _test_db: TestDb,
 50}
 51
 52pub struct TestClient {
 53    pub username: String,
 54    pub app_state: Arc<workspace::AppState>,
 55    channel_store: Model<ChannelStore>,
 56    notification_store: Model<NotificationStore>,
 57    state: RefCell<TestClientState>,
 58}
 59
 60#[derive(Default)]
 61struct TestClientState {
 62    local_projects: Vec<Model<Project>>,
 63    remote_projects: Vec<Model<Project>>,
 64    buffers: HashMap<Model<Project>, HashSet<Model<language::Buffer>>>,
 65    channel_buffers: HashSet<Model<ChannelBuffer>>,
 66}
 67
 68pub struct ContactsSummary {
 69    pub current: Vec<String>,
 70    pub outgoing_requests: Vec<String>,
 71    pub incoming_requests: Vec<String>,
 72}
 73
 74impl TestServer {
 75    pub async fn start(deterministic: BackgroundExecutor) -> Self {
 76        static NEXT_LIVE_KIT_SERVER_ID: AtomicUsize = AtomicUsize::new(0);
 77
 78        let use_postgres = env::var("USE_POSTGRES").ok();
 79        let use_postgres = use_postgres.as_deref();
 80        let test_db = if use_postgres == Some("true") || use_postgres == Some("1") {
 81            TestDb::postgres(deterministic.clone())
 82        } else {
 83            TestDb::sqlite(deterministic.clone())
 84        };
 85        let live_kit_server_id = NEXT_LIVE_KIT_SERVER_ID.fetch_add(1, SeqCst);
 86        let live_kit_server = live_kit_client::TestServer::create(
 87            format!("http://livekit.{}.test", live_kit_server_id),
 88            format!("devkey-{}", live_kit_server_id),
 89            format!("secret-{}", live_kit_server_id),
 90            deterministic.clone(),
 91        )
 92        .unwrap();
 93        let app_state = Self::build_app_state(&test_db, &live_kit_server).await;
 94        let epoch = app_state
 95            .db
 96            .create_server(&app_state.config.zed_environment)
 97            .await
 98            .unwrap();
 99        let server = Server::new(
100            epoch,
101            app_state.clone(),
102            Executor::Deterministic(deterministic.clone()),
103        );
104        server.start().await.unwrap();
105        // Advance clock to ensure the server's cleanup task is finished.
106        deterministic.advance_clock(CLEANUP_TIMEOUT);
107        Self {
108            app_state,
109            server,
110            connection_killers: Default::default(),
111            forbid_connections: Default::default(),
112            next_github_user_id: 0,
113            _test_db: test_db,
114            test_live_kit_server: live_kit_server,
115        }
116    }
117
118    pub async fn start2(
119        cx_a: &mut TestAppContext,
120        cx_b: &mut TestAppContext,
121    ) -> (TestServer, TestClient, TestClient, u64) {
122        let mut server = Self::start(cx_a.executor()).await;
123        let client_a = server.create_client(cx_a, "user_a").await;
124        let client_b = server.create_client(cx_b, "user_b").await;
125        let channel_id = server
126            .make_channel("a", None, (&client_a, cx_a), &mut [(&client_b, cx_b)])
127            .await;
128        cx_a.run_until_parked();
129
130        (server, client_a, client_b, channel_id)
131    }
132
133    pub async fn start1<'a>(cx: &'a mut TestAppContext) -> TestClient {
134        let mut server = Self::start(cx.executor().clone()).await;
135        server.create_client(cx, "user_a").await
136    }
137
138    pub async fn reset(&self) {
139        self.app_state.db.reset();
140        let epoch = self
141            .app_state
142            .db
143            .create_server(&self.app_state.config.zed_environment)
144            .await
145            .unwrap();
146        self.server.reset(epoch);
147    }
148
149    pub async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient {
150        cx.update(|cx| {
151            if cx.has_global::<SettingsStore>() {
152                panic!("Same cx used to create two test clients")
153            }
154            let settings = SettingsStore::test(cx);
155            cx.set_global(settings);
156            release_channel::init("0.0.0", cx);
157            client::init_settings(cx);
158        });
159
160        let http = FakeHttpClient::with_404_response();
161        let user_id = if let Ok(Some(user)) = self.app_state.db.get_user_by_github_login(name).await
162        {
163            user.id
164        } else {
165            let github_user_id = self.next_github_user_id;
166            self.next_github_user_id += 1;
167            self.app_state
168                .db
169                .create_user(
170                    &format!("{name}@example.com"),
171                    false,
172                    NewUserParams {
173                        github_login: name.into(),
174                        github_user_id,
175                    },
176                )
177                .await
178                .expect("creating user failed")
179                .user_id
180        };
181        let client_name = name.to_string();
182        let mut client = cx.update(|cx| Client::new(http.clone(), cx));
183        let server = self.server.clone();
184        let db = self.app_state.db.clone();
185        let connection_killers = self.connection_killers.clone();
186        let forbid_connections = self.forbid_connections.clone();
187
188        Arc::get_mut(&mut client)
189            .unwrap()
190            .set_id(user_id.to_proto())
191            .override_authenticate(move |cx| {
192                cx.spawn(|_| async move {
193                    let access_token = "the-token".to_string();
194                    Ok(Credentials {
195                        user_id: user_id.to_proto(),
196                        access_token,
197                    })
198                })
199            })
200            .override_establish_connection(move |credentials, cx| {
201                assert_eq!(credentials.user_id, user_id.0 as u64);
202                assert_eq!(credentials.access_token, "the-token");
203
204                let server = server.clone();
205                let db = db.clone();
206                let connection_killers = connection_killers.clone();
207                let forbid_connections = forbid_connections.clone();
208                let client_name = client_name.clone();
209                cx.spawn(move |cx| async move {
210                    if forbid_connections.load(SeqCst) {
211                        Err(EstablishConnectionError::other(anyhow!(
212                            "server is forbidding connections"
213                        )))
214                    } else {
215                        let (client_conn, server_conn, killed) =
216                            Connection::in_memory(cx.background_executor().clone());
217                        let (connection_id_tx, connection_id_rx) = oneshot::channel();
218                        let user = db
219                            .get_user_by_id(user_id)
220                            .await
221                            .expect("retrieving user failed")
222                            .unwrap();
223                        cx.background_executor()
224                            .spawn(server.handle_connection(
225                                server_conn,
226                                client_name,
227                                user,
228                                None,
229                                Some(connection_id_tx),
230                                Executor::Deterministic(cx.background_executor().clone()),
231                            ))
232                            .detach();
233                        let connection_id = connection_id_rx.await.unwrap();
234                        connection_killers
235                            .lock()
236                            .insert(connection_id.into(), killed);
237                        Ok(client_conn)
238                    }
239                })
240            });
241
242        let fs = FakeFs::new(cx.executor());
243        let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
244        let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
245        let mut language_registry = LanguageRegistry::test();
246        language_registry.set_executor(cx.executor());
247        let app_state = Arc::new(workspace::AppState {
248            client: client.clone(),
249            user_store: user_store.clone(),
250            workspace_store,
251            languages: Arc::new(language_registry),
252            fs: fs.clone(),
253            build_window_options: |_, _, _| Default::default(),
254            node_runtime: FakeNodeRuntime::new(),
255        });
256
257        cx.update(|cx| {
258            theme::init(theme::LoadThemes::JustBase, cx);
259            Project::init(&client, cx);
260            client::init(&client, cx);
261            language::init(cx);
262            editor::init(cx);
263            workspace::init(app_state.clone(), cx);
264            call::init(client.clone(), user_store.clone(), cx);
265            channel::init(&client, user_store.clone(), cx);
266            notifications::init(client.clone(), user_store, cx);
267            collab_ui::init(&app_state, cx);
268            file_finder::init(cx);
269            menu::init();
270            settings::KeymapFile::load_asset("keymaps/default.json", cx).unwrap();
271        });
272
273        client
274            .authenticate_and_connect(false, &cx.to_async())
275            .await
276            .unwrap();
277
278        let client = TestClient {
279            app_state,
280            username: name.to_string(),
281            channel_store: cx.read(ChannelStore::global).clone(),
282            notification_store: cx.read(NotificationStore::global).clone(),
283            state: Default::default(),
284        };
285        client.wait_for_current_user(cx).await;
286        client
287    }
288
289    pub fn disconnect_client(&self, peer_id: PeerId) {
290        self.connection_killers
291            .lock()
292            .remove(&peer_id)
293            .unwrap()
294            .store(true, SeqCst);
295    }
296
297    pub fn simulate_long_connection_interruption(
298        &self,
299        peer_id: PeerId,
300        deterministic: BackgroundExecutor,
301    ) {
302        self.forbid_connections();
303        self.disconnect_client(peer_id);
304        deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
305        self.allow_connections();
306        deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
307        deterministic.run_until_parked();
308    }
309
310    pub fn forbid_connections(&self) {
311        self.forbid_connections.store(true, SeqCst);
312    }
313
314    pub fn allow_connections(&self) {
315        self.forbid_connections.store(false, SeqCst);
316    }
317
318    pub async fn make_contacts(&self, clients: &mut [(&TestClient, &mut TestAppContext)]) {
319        for ix in 1..clients.len() {
320            let (left, right) = clients.split_at_mut(ix);
321            let (client_a, cx_a) = left.last_mut().unwrap();
322            for (client_b, cx_b) in right {
323                client_a
324                    .app_state
325                    .user_store
326                    .update(*cx_a, |store, cx| {
327                        store.request_contact(client_b.user_id().unwrap(), cx)
328                    })
329                    .await
330                    .unwrap();
331                cx_a.executor().run_until_parked();
332                client_b
333                    .app_state
334                    .user_store
335                    .update(*cx_b, |store, cx| {
336                        store.respond_to_contact_request(client_a.user_id().unwrap(), true, cx)
337                    })
338                    .await
339                    .unwrap();
340            }
341        }
342    }
343
344    pub async fn make_channel(
345        &self,
346        channel: &str,
347        parent: Option<u64>,
348        admin: (&TestClient, &mut TestAppContext),
349        members: &mut [(&TestClient, &mut TestAppContext)],
350    ) -> u64 {
351        let (_, admin_cx) = admin;
352        let channel_id = admin_cx
353            .read(ChannelStore::global)
354            .update(admin_cx, |channel_store, cx| {
355                channel_store.create_channel(channel, parent, cx)
356            })
357            .await
358            .unwrap();
359
360        for (member_client, member_cx) in members {
361            admin_cx
362                .read(ChannelStore::global)
363                .update(admin_cx, |channel_store, cx| {
364                    channel_store.invite_member(
365                        channel_id,
366                        member_client.user_id().unwrap(),
367                        ChannelRole::Member,
368                        cx,
369                    )
370                })
371                .await
372                .unwrap();
373
374            admin_cx.executor().run_until_parked();
375
376            member_cx
377                .read(ChannelStore::global)
378                .update(*member_cx, |channels, cx| {
379                    channels.respond_to_channel_invite(channel_id, true, cx)
380                })
381                .await
382                .unwrap();
383        }
384
385        channel_id
386    }
387
388    pub async fn make_public_channel(
389        &self,
390        channel: &str,
391        client: &TestClient,
392        cx: &mut TestAppContext,
393    ) -> u64 {
394        let channel_id = self
395            .make_channel(channel, None, (client, cx), &mut [])
396            .await;
397
398        client
399            .channel_store()
400            .update(cx, |channel_store, cx| {
401                channel_store.set_channel_visibility(
402                    channel_id,
403                    proto::ChannelVisibility::Public,
404                    cx,
405                )
406            })
407            .await
408            .unwrap();
409
410        channel_id
411    }
412
413    pub async fn make_channel_tree(
414        &self,
415        channels: &[(&str, Option<&str>)],
416        creator: (&TestClient, &mut TestAppContext),
417    ) -> Vec<u64> {
418        let mut observed_channels = HashMap::default();
419        let mut result = Vec::new();
420        for (channel, parent) in channels {
421            let id;
422            if let Some(parent) = parent {
423                if let Some(parent_id) = observed_channels.get(parent) {
424                    id = self
425                        .make_channel(channel, Some(*parent_id), (creator.0, creator.1), &mut [])
426                        .await;
427                } else {
428                    panic!(
429                        "Edge {}->{} referenced before {} was created",
430                        parent, channel, parent
431                    )
432                }
433            } else {
434                id = self
435                    .make_channel(channel, None, (creator.0, creator.1), &mut [])
436                    .await;
437            }
438
439            observed_channels.insert(channel, id);
440            result.push(id);
441        }
442
443        result
444    }
445
446    pub async fn create_room(&self, clients: &mut [(&TestClient, &mut TestAppContext)]) {
447        self.make_contacts(clients).await;
448
449        let (left, right) = clients.split_at_mut(1);
450        let (_client_a, cx_a) = &mut left[0];
451        let active_call_a = cx_a.read(ActiveCall::global);
452
453        for (client_b, cx_b) in right {
454            let user_id_b = client_b.current_user_id(*cx_b).to_proto();
455            active_call_a
456                .update(*cx_a, |call, cx| call.invite(user_id_b, None, cx))
457                .await
458                .unwrap();
459
460            cx_b.executor().run_until_parked();
461            let active_call_b = cx_b.read(ActiveCall::global);
462            active_call_b
463                .update(*cx_b, |call, cx| call.accept_incoming(cx))
464                .await
465                .unwrap();
466        }
467    }
468
469    pub async fn build_app_state(
470        test_db: &TestDb,
471        fake_server: &live_kit_client::TestServer,
472    ) -> Arc<AppState> {
473        Arc::new(AppState {
474            db: test_db.db().clone(),
475            live_kit_client: Some(Arc::new(fake_server.create_api_client())),
476            config: Config {
477                http_port: 0,
478                database_url: "".into(),
479                database_max_connections: 0,
480                api_token: "".into(),
481                invite_link_prefix: "".into(),
482                live_kit_server: None,
483                live_kit_key: None,
484                live_kit_secret: None,
485                rust_log: None,
486                log_json: None,
487                zed_environment: "test".into(),
488            },
489        })
490    }
491}
492
493impl Deref for TestServer {
494    type Target = Server;
495
496    fn deref(&self) -> &Self::Target {
497        &self.server
498    }
499}
500
501impl Drop for TestServer {
502    fn drop(&mut self) {
503        self.server.teardown();
504        self.test_live_kit_server.teardown().unwrap();
505    }
506}
507
508impl Deref for TestClient {
509    type Target = Arc<Client>;
510
511    fn deref(&self) -> &Self::Target {
512        &self.app_state.client
513    }
514}
515
516impl TestClient {
517    pub fn fs(&self) -> &FakeFs {
518        self.app_state.fs.as_fake()
519    }
520
521    pub fn channel_store(&self) -> &Model<ChannelStore> {
522        &self.channel_store
523    }
524
525    pub fn notification_store(&self) -> &Model<NotificationStore> {
526        &self.notification_store
527    }
528
529    pub fn user_store(&self) -> &Model<UserStore> {
530        &self.app_state.user_store
531    }
532
533    pub fn language_registry(&self) -> &Arc<LanguageRegistry> {
534        &self.app_state.languages
535    }
536
537    pub fn client(&self) -> &Arc<Client> {
538        &self.app_state.client
539    }
540
541    pub fn current_user_id(&self, cx: &TestAppContext) -> UserId {
542        UserId::from_proto(
543            self.app_state
544                .user_store
545                .read_with(cx, |user_store, _| user_store.current_user().unwrap().id),
546        )
547    }
548
549    pub async fn wait_for_current_user(&self, cx: &TestAppContext) {
550        let mut authed_user = self
551            .app_state
552            .user_store
553            .read_with(cx, |user_store, _| user_store.watch_current_user());
554        while authed_user.next().await.unwrap().is_none() {}
555    }
556
557    pub async fn clear_contacts(&self, cx: &mut TestAppContext) {
558        self.app_state
559            .user_store
560            .update(cx, |store, _| store.clear_contacts())
561            .await;
562    }
563
564    pub fn local_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
565        Ref::map(self.state.borrow(), |state| &state.local_projects)
566    }
567
568    pub fn remote_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
569        Ref::map(self.state.borrow(), |state| &state.remote_projects)
570    }
571
572    pub fn local_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
573        RefMut::map(self.state.borrow_mut(), |state| &mut state.local_projects)
574    }
575
576    pub fn remote_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
577        RefMut::map(self.state.borrow_mut(), |state| &mut state.remote_projects)
578    }
579
580    pub fn buffers_for_project<'a>(
581        &'a self,
582        project: &Model<Project>,
583    ) -> impl DerefMut<Target = HashSet<Model<language::Buffer>>> + 'a {
584        RefMut::map(self.state.borrow_mut(), |state| {
585            state.buffers.entry(project.clone()).or_default()
586        })
587    }
588
589    pub fn buffers<'a>(
590        &'a self,
591    ) -> impl DerefMut<Target = HashMap<Model<Project>, HashSet<Model<language::Buffer>>>> + 'a
592    {
593        RefMut::map(self.state.borrow_mut(), |state| &mut state.buffers)
594    }
595
596    pub fn channel_buffers<'a>(
597        &'a self,
598    ) -> impl DerefMut<Target = HashSet<Model<ChannelBuffer>>> + 'a {
599        RefMut::map(self.state.borrow_mut(), |state| &mut state.channel_buffers)
600    }
601
602    pub fn summarize_contacts(&self, cx: &TestAppContext) -> ContactsSummary {
603        self.app_state
604            .user_store
605            .read_with(cx, |store, _| ContactsSummary {
606                current: store
607                    .contacts()
608                    .iter()
609                    .map(|contact| contact.user.github_login.clone())
610                    .collect(),
611                outgoing_requests: store
612                    .outgoing_contact_requests()
613                    .iter()
614                    .map(|user| user.github_login.clone())
615                    .collect(),
616                incoming_requests: store
617                    .incoming_contact_requests()
618                    .iter()
619                    .map(|user| user.github_login.clone())
620                    .collect(),
621            })
622    }
623
624    pub async fn build_local_project(
625        &self,
626        root_path: impl AsRef<Path>,
627        cx: &mut TestAppContext,
628    ) -> (Model<Project>, WorktreeId) {
629        let project = self.build_empty_local_project(cx);
630        let (worktree, _) = project
631            .update(cx, |p, cx| {
632                p.find_or_create_local_worktree(root_path, true, cx)
633            })
634            .await
635            .unwrap();
636        worktree
637            .read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
638            .await;
639        (project, worktree.read_with(cx, |tree, _| tree.id()))
640    }
641
642    pub async fn build_test_project(&self, cx: &mut TestAppContext) -> Model<Project> {
643        self.fs()
644            .insert_tree(
645                "/a",
646                json!({
647                    "1.txt": "one\none\none",
648                    "2.js": "function two() { return 2; }",
649                    "3.rs": "mod test",
650                }),
651            )
652            .await;
653        self.build_local_project("/a", cx).await.0
654    }
655
656    pub async fn host_workspace(
657        &self,
658        workspace: &View<Workspace>,
659        channel_id: u64,
660        cx: &mut VisualTestContext,
661    ) {
662        cx.update(|cx| {
663            let active_call = ActiveCall::global(cx);
664            active_call.update(cx, |call, cx| call.join_channel(channel_id, cx))
665        })
666        .await
667        .unwrap();
668        cx.update(|cx| {
669            let active_call = ActiveCall::global(cx);
670            let project = workspace.read(cx).project().clone();
671            active_call.update(cx, |call, cx| call.share_project(project, cx))
672        })
673        .await
674        .unwrap();
675        cx.executor().run_until_parked();
676    }
677
678    pub async fn join_workspace<'a>(
679        &'a self,
680        channel_id: u64,
681        cx: &'a mut TestAppContext,
682    ) -> (View<Workspace>, &'a mut VisualTestContext) {
683        cx.update(|cx| workspace::join_channel(channel_id, self.app_state.clone(), None, cx))
684            .await
685            .unwrap();
686        cx.run_until_parked();
687
688        self.active_workspace(cx)
689    }
690
691    pub fn build_empty_local_project(&self, cx: &mut TestAppContext) -> Model<Project> {
692        cx.update(|cx| {
693            Project::local(
694                self.client().clone(),
695                self.app_state.node_runtime.clone(),
696                self.app_state.user_store.clone(),
697                self.app_state.languages.clone(),
698                self.app_state.fs.clone(),
699                cx,
700            )
701        })
702    }
703
704    pub async fn build_remote_project(
705        &self,
706        host_project_id: u64,
707        guest_cx: &mut TestAppContext,
708    ) -> Model<Project> {
709        let active_call = guest_cx.read(ActiveCall::global);
710        let room = active_call.read_with(guest_cx, |call, _| call.room().unwrap().clone());
711        room.update(guest_cx, |room, cx| {
712            room.join_project(
713                host_project_id,
714                self.app_state.languages.clone(),
715                self.app_state.fs.clone(),
716                cx,
717            )
718        })
719        .await
720        .unwrap()
721    }
722
723    pub fn build_workspace<'a>(
724        &'a self,
725        project: &Model<Project>,
726        cx: &'a mut TestAppContext,
727    ) -> (View<Workspace>, &'a mut VisualTestContext) {
728        cx.add_window_view(|cx| {
729            cx.activate_window();
730            Workspace::new(0, project.clone(), self.app_state.clone(), cx)
731        })
732    }
733
734    pub async fn build_test_workspace<'a>(
735        &'a self,
736        cx: &'a mut TestAppContext,
737    ) -> (View<Workspace>, &'a mut VisualTestContext) {
738        let project = self.build_test_project(cx).await;
739        cx.add_window_view(|cx| {
740            cx.activate_window();
741            Workspace::new(0, project.clone(), self.app_state.clone(), cx)
742        })
743    }
744
745    pub fn active_workspace<'a>(
746        &'a self,
747        cx: &'a mut TestAppContext,
748    ) -> (View<Workspace>, &'a mut VisualTestContext) {
749        let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
750
751        let view = window.root_view(cx).unwrap();
752        let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
753        // it might be nice to try and cleanup these at the end of each test.
754        (view, cx)
755    }
756}
757
758impl Drop for TestClient {
759    fn drop(&mut self) {
760        self.app_state.client.teardown();
761    }
762}