Skip to content

Commit cb53532

Browse files
committed
fix(asyncgit/test): use correct hook path and add non zero timeout test
1 parent 50f55f4 commit cb53532

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

asyncgit/src/sync/hooks.rs

+32-6
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,45 @@ mod tests {
287287
let root = repo.path().parent().unwrap();
288288

289289
let hook = b"#!/usr/bin/env sh
290-
sleep 1
290+
sleep 0.21
291291
";
292292

293293
git2_hooks::create_hook(
294294
&repo,
295-
git2_hooks::HOOK_COMMIT_MSG,
295+
git2_hooks::HOOK_PRE_COMMIT,
296296
hook,
297297
);
298298

299299
let res = hooks_pre_commit(
300300
&root.to_str().unwrap().into(),
301-
Duration::ZERO,
301+
Duration::from_millis(200),
302+
)
303+
.unwrap();
304+
305+
assert_eq!(
306+
res,
307+
HookResult::NotOk("hook timed out".to_string())
308+
);
309+
}
310+
311+
#[test]
312+
fn test_hooks_faster_than_timeout() {
313+
let (_td, repo) = repo_init().unwrap();
314+
let root = repo.path().parent().unwrap();
315+
316+
let hook = b"#!/usr/bin/env sh
317+
sleep 0.1
318+
";
319+
320+
git2_hooks::create_hook(
321+
&repo,
322+
git2_hooks::HOOK_PRE_COMMIT,
323+
hook,
324+
);
325+
326+
let res = hooks_pre_commit(
327+
&root.to_str().unwrap().into(),
328+
Duration::from_millis(110),
302329
)
303330
.unwrap();
304331

@@ -316,13 +343,12 @@ mod tests {
316343

317344
git2_hooks::create_hook(
318345
&repo,
319-
git2_hooks::HOOK_COMMIT_MSG,
346+
git2_hooks::HOOK_POST_COMMIT,
320347
hook,
321348
);
322349

323-
let res = hooks_commit_msg(
350+
let res = hooks_post_commit(
324351
&root.to_str().unwrap().into(),
325-
&mut String::new(),
326352
Duration::ZERO,
327353
)
328354
.unwrap();

0 commit comments

Comments
 (0)