Skip to content

Commit b1ce826

Browse files
committed
Replace sleep by wait for specific notification
1 parent ecffe01 commit b1ce826

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/gitui.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ impl Gitui {
169169
.unwrap();
170170
}
171171

172+
#[cfg(test)]
173+
fn wait_for_async_git_notification(
174+
&self,
175+
expected: AsyncGitNotification,
176+
) {
177+
loop {
178+
let actual = self
179+
.rx_git
180+
.recv_timeout(std::time::Duration::from_millis(100))
181+
.unwrap();
182+
183+
if actual == expected {
184+
break;
185+
}
186+
}
187+
}
188+
172189
#[cfg(test)]
173190
fn update(&mut self) {
174191
self.app.update().unwrap();
@@ -177,7 +194,7 @@ impl Gitui {
177194

178195
#[cfg(test)]
179196
mod tests {
180-
use std::{path::PathBuf, thread::sleep, time::Duration};
197+
use std::path::PathBuf;
181198

182199
use asyncgit::{sync::RepoPath, AsyncGitNotification};
183200
use crossterm::event::{KeyCode, KeyModifiers};
@@ -225,16 +242,12 @@ mod tests {
225242

226243
gitui.draw(&mut terminal).unwrap();
227244

228-
sleep(Duration::from_millis(500));
229-
230245
assert_snapshot!("app_loading", terminal.backend());
231246

232247
let event =
233248
AsyncNotification::Git(AsyncGitNotification::Status);
234249
gitui.update_async(event);
235250

236-
sleep(Duration::from_millis(500));
237-
238251
gitui.draw(&mut terminal).unwrap();
239252

240253
assert_snapshot!("app_loading_finished", terminal.backend());
@@ -245,7 +258,9 @@ mod tests {
245258
key_config.keys.tab_log.modifiers,
246259
);
247260

248-
sleep(Duration::from_millis(500));
261+
gitui.wait_for_async_git_notification(
262+
AsyncGitNotification::Log,
263+
);
249264

250265
gitui.update();
251266

0 commit comments

Comments
 (0)