Add SystemClock (#8239)

This PR adds a `SystemClock` trait for abstracting away the system
clock.

This allows us to swap out the real system clock with a
`FakeSystemClock` in the tests, thus allowing the fake passage of time.

We're using this in `Telemetry` to better mock the clock for testing
purposes.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-02-22 22:28:08 -05:00 committed by GitHub
parent cc8e3c2286
commit 0de8672044
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 213 additions and 55 deletions

View file

@ -10,6 +10,7 @@ use channel::{ChannelBuffer, ChannelStore};
use client::{
self, proto::PeerId, Client, Connection, Credentials, EstablishConnectionError, UserStore,
};
use clock::FakeSystemClock;
use collab_ui::channel_view::ChannelView;
use collections::{HashMap, HashSet};
use fs::FakeFs;
@ -163,6 +164,7 @@ impl TestServer {
client::init_settings(cx);
});
let clock = Arc::new(FakeSystemClock::default());
let http = FakeHttpClient::with_404_response();
let user_id = if let Ok(Some(user)) = self.app_state.db.get_user_by_github_login(name).await
{
@ -185,7 +187,7 @@ impl TestServer {
.user_id
};
let client_name = name.to_string();
let mut client = cx.update(|cx| Client::new(http.clone(), cx));
let mut client = cx.update(|cx| Client::new(clock, http.clone(), cx));
let server = self.server.clone();
let db = self.app_state.db.clone();
let connection_killers = self.connection_killers.clone();