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

@ -853,10 +853,13 @@ impl Project {
root_paths: impl IntoIterator<Item = &Path>,
cx: &mut gpui::TestAppContext,
) -> Model<Project> {
use clock::FakeSystemClock;
let mut languages = LanguageRegistry::test();
languages.set_executor(cx.executor());
let clock = Arc::new(FakeSystemClock::default());
let http_client = util::http::FakeHttpClient::with_404_response();
let client = cx.update(|cx| client::Client::new(http_client.clone(), cx));
let client = cx.update(|cx| client::Client::new(clock, http_client.clone(), cx));
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
let project = cx.update(|cx| {
Project::local(