Skip to content

Commit ae55b09

Browse files
committed
fix(asyncgit/test): use correct hook path and add non zero timeout test
1 parent 08eaefe commit ae55b09

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,45 @@ mod tests {
337337
let root = repo.path().parent().unwrap();
338338

339339
let hook = b"#!/usr/bin/env sh
340-
sleep 1
340+
sleep 0.21
341341
";
342342

343343
git2_hooks::create_hook(
344344
&repo,
345-
git2_hooks::HOOK_COMMIT_MSG,
345+
git2_hooks::HOOK_PRE_COMMIT,
346346
hook,
347347
);
348348

349349
let res = hooks_pre_commit(
350350
&root.to_str().unwrap().into(),
351-
Duration::ZERO,
351+
Duration::from_millis(200),
352+
)
353+
.unwrap();
354+
355+
assert_eq!(
356+
res,
357+
HookResult::NotOk("hook timed out".to_string())
358+
);
359+
}
360+
361+
#[test]
362+
fn test_hooks_faster_than_timeout() {
363+
let (_td, repo) = repo_init().unwrap();
364+
let root = repo.path().parent().unwrap();
365+
366+
let hook = b"#!/usr/bin/env sh
367+
sleep 0.1
368+
";
369+
370+
git2_hooks::create_hook(
371+
&repo,
372+
git2_hooks::HOOK_PRE_COMMIT,
373+
hook,
374+
);
375+
376+
let res = hooks_pre_commit(
377+
&root.to_str().unwrap().into(),
378+
Duration::from_millis(110),
352379
)
353380
.unwrap();
354381

@@ -366,13 +393,12 @@ mod tests {
366393

367394
git2_hooks::create_hook(
368395
&repo,
369-
git2_hooks::HOOK_COMMIT_MSG,
396+
git2_hooks::HOOK_POST_COMMIT,
370397
hook,
371398
);
372399

373-
let res = hooks_commit_msg(
400+
let res = hooks_post_commit(
374401
&root.to_str().unwrap().into(),
375-
&mut String::new(),
376402
Duration::ZERO,
377403
)
378404
.unwrap();

0 commit comments

Comments
 (0)