git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 11/11] test-lib: clear watchman watches at test completion

From
Derrick Stolee <stolee@gmail.com>
Date
Dec 9, 2019, 14:12 UTC
Message-ID
<93325ecb-0bbe-e7fb-3b60-8fff81768f8f@gmail.com>
In-Reply-To
<20191122010645.GX23183@szeder.dev>
On 11/21/2019 8:06 PM, SZEDER Gábor wrote:
Thanks for this message. Sorry I'm so late getting back to it.
Show 45 quoted lines
> On Thu, Nov 21, 2019 at 10:20:26PM +0000, Derrick Stolee via GitGitGadget wrote:
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
>> ---
>>  t/test-lib-functions.sh | 15 +++++++++++++++
>>  t/test-lib.sh           |  2 ++
>>  2 files changed, 17 insertions(+)
>>
>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
>> index e0b3f28d3a..03573caf42 100644
>> --- a/t/test-lib-functions.sh
>> +++ b/t/test-lib-functions.sh
>> @@ -1475,3 +1475,18 @@ test_set_port () {
>>  	port=$(($port + ${GIT_TEST_STRESS_JOB_NR:-0}))
>>  	eval $var=$port
>>  }
>> +
>> +test_clear_watchman () {
>> +	if test $GIT_TEST_FSMONITOR -ne ""
> 
> In the rare cases when this function is invoked (see below) this
> condition triggers an error from the shell running test script:
> 
>   - when the variable is not set, because of the lack of quotes around
>     the variable name:
> 
>       $ ./t5570-git-daemon.sh 
>       [....]
>       ok 21 - hostname interpolation works after LF-stripping
>       ./t5570-git-daemon.sh: 1482: test: -ne: unexpected operator
>       # passed all 21 test(s)
>       1..21
> 
>   - when the variable is set, because the '-ne' operator does integer
>     comparison:
> 
>       $ GIT_TEST_FSMONITOR="$PWD"/t7519/fsmonitor-none ./t5570-git-daemon.sh
>       [...]
>       ok 21 - hostname interpolation works after LF-stripping
>       ./t5570-git-daemon.sh: 1482: test: Illegal number: /home/szeder/src/git/t/t7519/fsmonitor-none
>       # failed 1 among 21 test(s)
>       1..21
> 
> Please use 'if test -n "$GIT_TEST_FSMONITOR"' instead.
Thanks for the pointers.
Show 14 quoted lines
>> +	then
>> +		watchman watch-list |
> 
> Then with the above fixed, trying to run 'watchman' triggers another
> error if it's not installed:
> 
>   $ GIT_TEST_FSMONITOR="$PWD"/t7519/fsmonitor-none ./t5570-git-daemon.sh 
>   [...]
>   ok 21 - hostname interpolation works after LF-stripping
>   ./t5570-git-daemon.sh: 1484: ./t5570-git-daemon.sh: watchman: not found
>   # failed 1 among 21 test(s)
> 
> I think we need an additional condition to run this only if
> 't7519/fsmonitor-watchman' is used in the tests.

The intention is to enable a test-suite-wide run using GIT_TEST_FSMONITOR, and that can only use watchman (currently). Barring wanting to unset the variable if it was set on purpose in a test script, the other options do not actually return correct values to make use of the feature.

Show 26 quoted lines
>> +			grep "$TRASH_DIRECTORY" |
>> +			sed "s/\t\"//g" |
>> +			sed "s/\",//g" >repo-list
>> +
>> +		for repo in $(cat repo-list)
>> +		do
>> +			watchman watch-del "$repo"
>> +		done
>> +	fi
>> +}
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index 30b07e310f..067a432ea5 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -1072,6 +1072,8 @@ test_atexit_handler () {
>>  	# sure that the registered cleanup commands are run only once.
>>  	test : != "$test_atexit_cleanup" || return 0
>>  
>> +	test_clear_watchman
> 
> I'm not sure where to put this call, but this is definitely not the
> right place for it.  See that 'return 0' above in the context?  That's
> where the test_atexit_handler function returns early when no atexit
> handler commands are set, i.e. in all test scripts that don't involve
> some kind of daemons, thus this call is not invoked in the majority of
> test scripts.
Ah, I misunderstood the point of test_atexit_handler.
Show 15 quoted lines
> Simply moving this call before that early return is not good, because
> then it would be invoked twice.
> 
> An option would be to register this call as an atexit command
> somewhere late in 'test-lib.sh' (around where GIT_TEST_GETTEXT_POISON
> is restored, perhaps).  That way it would be invoked most of the time,
> and it would be invoked only once, but I'm not sure how it would work
> out with test scripts that unset GIT_TEST_FSMONITOR somewhere in the
> middle for the remainder of the test script.  However, register the
> atexit command only if GIT_TEST_FSMONITOR is set (to something
> watchman-specific), so it won't be invoked at all if
> GIT_TEST_FSMONITOR is not set, and thus it won't generate additional
> test output and trace.
> 
> I don't have a better idea.

Shouldn't it be sufficient to add it into test_done? If the test fails, then we could leave watches open, but that's no worse than we had without this test_clear_watchman method.

Thanks, -Stolee

Previous: SZEDER GáborNext: SZEDER Gábor
Message 15 of 41 in “Improve testability with GIT_TEST_FSMONITOR”
  1. 00/11 Improve testability with GIT_TEST_FSMONITORDerrick Stolee via GitGitGadget, Nov 21, 2019
  2. 01/11 fsmonitor: disable in a bare repoDerrick Stolee via GitGitGadget, Nov 21, 2019
  3. Denton LiuNov 21, 2019
  4. Derrick StoleeNov 22, 2019
  5. 02/11 fsmonitor: do not output to stderr for testsDerrick Stolee via GitGitGadget, Nov 21, 2019
  6. 03/11 t1301-shared-repo.sh: disable FSMONITORDerrick Stolee via GitGitGadget, Nov 21, 2019
  7. 04/11 t1510-repo-setup.sh: disable fsmonitor if no .git dirDerrick Stolee via GitGitGadget, Nov 21, 2019
  8. 05/11 fsmonitor: disable fsmonitor with worktreesDerrick Stolee via GitGitGadget, Nov 21, 2019
  9. 07/11 t3600-rm.sh: disable fsmonitor when deleting populated submoduleDerrick Stolee via GitGitGadget, Nov 21, 2019
  10. 06/11 t3030-merge-recursive.sh: disable fsmonitor when tweaking GIT_WORK_TREEDerrick Stolee via GitGitGadget, Nov 21, 2019
  11. 09/11 t7063: disable fsmonitor with status cacheDerrick Stolee via GitGitGadget, Nov 21, 2019
  12. 08/11 tests: disable fsmonitor in submodule testsDerrick Stolee via GitGitGadget, Nov 21, 2019
  13. 11/11 test-lib: clear watchman watches at test completionDerrick Stolee via GitGitGadget, Nov 21, 2019
  14. SZEDER GáborNov 22, 2019
  15. Derrick StoleeDec 9, 2019
  16. SZEDER GáborDec 9, 2019
  17. Derrick StoleeDec 10, 2019
  18. 10/11 t7519: disable external GIT_TEST_FSMONITOR variableDerrick Stolee via GitGitGadget, Nov 21, 2019
  19. 0/8 Improve testability with GIT_TEST_FSMONITORDerrick Stolee via GitGitGadget, Dec 9, 2019
  20. 1/8 fsmonitor: disable in a bare repoDerrick Stolee via GitGitGadget, Dec 9, 2019
  21. SZEDER GáborDec 10, 2019
  22. 2/8 fsmonitor: do not output to stderr for testsDerrick Stolee via GitGitGadget, Dec 9, 2019
  23. 3/8 t1301-shared-repo.sh: disable FSMONITORDerrick Stolee via GitGitGadget, Dec 9, 2019
  24. SZEDER GáborDec 10, 2019
  25. 4/8 t3030-merge-recursive.sh: disable fsmonitor when tweaking GIT_WORK_TREEDerrick Stolee via GitGitGadget, Dec 9, 2019
  26. SZEDER GáborDec 10, 2019
  27. Derrick StoleeDec 10, 2019
  28. SZEDER GáborDec 10, 2019
  29. SZEDER GáborDec 10, 2019
  30. Derrick StoleeJan 23, 2020
  31. 7/8 t7519: disable external GIT_TEST_FSMONITOR variableDerrick Stolee via GitGitGadget, Dec 9, 2019
  32. 8/8 test-lib: clear watchman watches at test completionDerrick Stolee via GitGitGadget, Dec 9, 2019
  33. Junio C HamanoDec 9, 2019
  34. Derrick StoleeDec 10, 2019
  35. Junio C HamanoDec 10, 2019
  36. Derrick StoleeDec 10, 2019
  37. Johannes SchindelinDec 10, 2019
  38. 6/8 t7063: disable fsmonitor with status cacheDerrick Stolee via GitGitGadget, Dec 9, 2019
  39. 5/8 tests: disable fsmonitor in submodule testsDerrick Stolee via GitGitGadget, Dec 9, 2019
  40. SZEDER GáborDec 10, 2019
  41. Derrick StoleeDec 10, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.