{"thread":{"id":"55057","subject":"[PATCH] test-lib: prevent '--stress-jobs=X' from being ignored","startedAt":"2021-01-26T22:20:02Z","lastAt":"2021-01-26T22:20:02Z","messageCount":1,"participants":["SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"415366","messageId":"20210126220533.1452453-1-szeder.dev@gmail.com","threadId":"55057","inReplyTo":null,"subject":"[PATCH] test-lib: prevent '--stress-jobs=X' from being ignored","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-01-26T22:05:33Z","receivedAt":"2021-01-26T22:20:02Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"'./t1234-foo.sh --stress-jobs=X ...' is supposed to run that test\nscript in X parallel jobs, but the number of jobs specified on the\ncommand line is entirely ignored if other '--stress'-related options\nfollow.  I.e. both './t1234-foo.sh --stress-jobs=X --stress-limit=Y'\nand './t1234-foo.sh --stress-jobs=X --stress' fall back to using twice\nthe number of CPUs parallel jobs instead.\n\nThe former has been broken since commit de69e6f6c9 (tests: let\n--stress-limit=<N> imply --stress, 2019-03-03) [1], which started to\nunconditionally overwrite the $stress variable holding the specified\nnumber of jobs in its effort to imply '--stress'.  The latter has been\nbroken since f545737144 (tests: introduce --stress-jobs=<N>,\n2019-03-03), because it didn't consider that handling '--stress' will\noverwrite that variable as well.\n\nWe could fix this by being more careful about (over)writing that\n$stress variable and checking first whether it has already been set.\nBut I think it's cleaner to use a dedicated variable to hold the\nnumber of specified parallel jobs, so let's do that instead.\n\n[1] In de69e6f6c9 there was no '--stress-jobs=X' option yet, the\n    number of parallel jobs had to be specified via '--stress=X', so,\n    strictly speaking, de69e6f6c9 broke './t1234-foo.sh --stress=X\n    --stress-limit=Y'.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n t/test-lib.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 9fa7c1d0f6..a1634ba69d 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -163,8 +163,8 @@ parse_option () {\n \t\t;;\n \t--stress-jobs=*)\n \t\tstress=t;\n-\t\tstress=${opt#--*=}\n-\t\tcase \"$stress\" in\n+\t\tstress_jobs=${opt#--*=}\n+\t\tcase \"$stress_jobs\" in\n \t\t*[!0-9]*|0*|\"\")\n \t\t\techo \"error: --stress-jobs=<N> requires the number of jobs to run\" >&2\n \t\t\texit 1\n@@ -262,9 +262,9 @@ then\n \t: # Don't stress test again.\n elif test -n \"$stress\"\n then\n-\tif test \"$stress\" != t\n+\tif test -n \"$stress_jobs\"\n \tthen\n-\t\tjob_count=$stress\n+\t\tjob_count=$stress_jobs\n \telif test -n \"$GIT_TEST_STRESS_LOAD\"\n \tthen\n \t\tjob_count=\"$GIT_TEST_STRESS_LOAD\"\n-- \n2.30.0.615.g3128ec9b6c\n\n"}]}