Fix tests

This commit is contained in:
Joseph T. Lyons 2024-01-06 16:10:40 -05:00
parent 800c9958a3
commit 520c433af5
3 changed files with 20 additions and 4 deletions

View File

@ -343,12 +343,13 @@ async fn test_channel_messages(cx: &mut TestAppContext) {
} }
fn init_test(cx: &mut AppContext) -> Model<ChannelStore> { fn init_test(cx: &mut AppContext) -> Model<ChannelStore> {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
let http = FakeHttpClient::with_404_response(); let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone(), cx); let client = Client::new(http.clone(), cx);
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
client::init(&client, cx); client::init(&client, cx);
crate::init(&client, user_store, cx); crate::init(&client, user_store, cx);

View File

@ -1404,11 +1404,13 @@ mod tests {
use gpui::{BackgroundExecutor, Context, TestAppContext}; use gpui::{BackgroundExecutor, Context, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use settings::SettingsStore;
use std::future; use std::future;
use util::http::FakeHttpClient; use util::http::FakeHttpClient;
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
async fn test_reconnection(cx: &mut TestAppContext) { async fn test_reconnection(cx: &mut TestAppContext) {
init_test(cx);
let user_id = 5; let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await; let server = FakeServer::for_client(user_id, &client, cx).await;
@ -1443,6 +1445,7 @@ mod tests {
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
async fn test_connection_timeout(executor: BackgroundExecutor, cx: &mut TestAppContext) { async fn test_connection_timeout(executor: BackgroundExecutor, cx: &mut TestAppContext) {
init_test(cx);
let user_id = 5; let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let mut status = client.status(); let mut status = client.status();
@ -1514,6 +1517,7 @@ mod tests {
cx: &mut TestAppContext, cx: &mut TestAppContext,
executor: BackgroundExecutor, executor: BackgroundExecutor,
) { ) {
init_test(cx);
let auth_count = Arc::new(Mutex::new(0)); let auth_count = Arc::new(Mutex::new(0));
let dropped_auth_count = Arc::new(Mutex::new(0)); let dropped_auth_count = Arc::new(Mutex::new(0));
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
@ -1562,6 +1566,7 @@ mod tests {
#[gpui::test] #[gpui::test]
async fn test_subscribing_to_entity(cx: &mut TestAppContext) { async fn test_subscribing_to_entity(cx: &mut TestAppContext) {
init_test(cx);
let user_id = 5; let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await; let server = FakeServer::for_client(user_id, &client, cx).await;
@ -1615,6 +1620,7 @@ mod tests {
#[gpui::test] #[gpui::test]
async fn test_subscribing_after_dropping_subscription(cx: &mut TestAppContext) { async fn test_subscribing_after_dropping_subscription(cx: &mut TestAppContext) {
init_test(cx);
let user_id = 5; let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await; let server = FakeServer::for_client(user_id, &client, cx).await;
@ -1643,6 +1649,7 @@ mod tests {
#[gpui::test] #[gpui::test]
async fn test_dropping_subscription_in_handler(cx: &mut TestAppContext) { async fn test_dropping_subscription_in_handler(cx: &mut TestAppContext) {
init_test(cx);
let user_id = 5; let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await; let server = FakeServer::for_client(user_id, &client, cx).await;
@ -1671,4 +1678,11 @@ mod tests {
id: usize, id: usize,
subscription: Option<Subscription>, subscription: Option<Subscription>,
} }
fn init_test(cx: &mut TestAppContext) {
cx.update(|cx| {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
});
}
} }

View File

@ -271,11 +271,12 @@ mod tests {
fn init_test(cx: &mut TestAppContext) -> Arc<LanguageRegistry> { fn init_test(cx: &mut TestAppContext) -> Arc<LanguageRegistry> {
cx.update(|cx| { cx.update(|cx| {
let settings = SettingsStore::test(cx);
cx.set_global(settings);
let http = FakeHttpClient::with_404_response(); let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone(), cx); let client = Client::new(http.clone(), cx);
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
let settings = SettingsStore::test(cx);
cx.set_global(settings);
theme::init(theme::LoadThemes::JustBase, cx); theme::init(theme::LoadThemes::JustBase, cx);
language::init(cx); language::init(cx);
editor::init(cx); editor::init(cx);