Skip to content
  • Gábor Szeder's avatar
    git p4 test: clean up the p4d cleanup functions · 07353d90
    Gábor Szeder authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Confusingly, the 'git p4' tests used two cleanup functions:
    
      - 'kill_p4d' was run in the last test before 'test_done', and it not
        only killed 'p4d', but it killed the watchdog process, and cleaned
        up after 'p4d' as well by removing all directories used by the P4
        daemon and client.
    
        This cleanup is not necessary right before 'test_done', because
        the whole trash directory is about to get removed anyway, but it
        is necessary in 't9801-git-p4-branch.sh', which uses 'kill_p4d' to
        stop 'p4d' before re-starting it in the middle of the test script.
    
      - 'cleanup' was run in the trap on EXIT, and it killed 'p4d', but,
        it didn't kill the watchdog process, and, contrarily to its name,
        didn't perform any cleanup whatsoever.
    
    Make it clearer what's going on by renaming and simplifying the
    cleanup functions, so in the end we'll have:
    
      - 'stop_p4d_and_watchdog' replaces 'cleanup' as it will try to live
        up to its name and stop both the 'p4d' and the watchdog processes,
        and as the sole function registered with 'test_atexit' it will be
        responsible for no leaving any stray processes behind after 'git p4'
        tests were finished or interrupted.
    
      - 'stop_and_cleanup_p4d' replaces 'kill_p4d' as it will stop 'p4d'
        (and the watchdog) and remove all directories used by the P4
        daemon and cliean, so it can be used mid-script to stop and then
        re-start 'p4d'.
    
    Note that while 'cleanup' sent a single SIGKILL to 'p4d', 'kill_p4d'
    was quite brutal, as it first sent SIGTERM to the daemon repeatedly,
    either until its pid disappeared or until a given timeout was up, and
    then it sent SIGKILL repeatedly, for good measure.  This is overkill
    (pardon the pun): a single SIGKILL should be able to take down any
    process in a sensible state, and if a process were to somehow end up
    stuck in the dreaded uninterruptible sleep state then even repeated
    SIGKILLs won't bring immediate help.  So ditch all the repeated
    SIGTERM/SIGKILL parts, and use a single SIGKILL to stop 'p4d', and
    make sure that there are no races between asynchron signal delivery
    and subsequent restart of 'p4d' by waiting for it to die.
    
    With this change the 'retry_until_fail' helper has no callers left,
    remove it.
    
    Signed-off-by: default avatarSZEDER Gábor <szeder.dev@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    07353d90