Message ID | f7c20e0b5bd7857b2303aab762f24c503e50030d.1619104091.git.matheus.bernardino@usp.br (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Parallel Checkout (part 3) | expand |
On 4/22/2021 11:17 AM, Matheus Tavares wrote: > We already have tests for the basic parallel-checkout operations. But > this code can also run be executed by other commands, such as > git-read-tree and git-sparse-checkout, which are currently not tested > with multiple workers. To promote a wider test coverage without > duplicating tests: > > 1. Add the GIT_TEST_CHECKOUT_WORKERS environment variable, to optionally > force parallel-checkout execution during the whole test suite. > > 2. Set this variable (with a value of 2) in the second test round of our > linux-gcc CI job. This round runs `make test` again with some > optional GIT_TEST_* variables enabled, so there is no additional > overhead in exercising the parallel-checkout code here. > > Note that tests checking out less than two parallel-eligible entries > will fall back to the sequential mode. Nevertheless, it's still a good > exercise for the parallel-checkout framework as the fallback codepath > also writes the queued entries using the parallel-checkout functions > (only without spawning any worker). I agree that this is helpful additional testing. > Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> > --- > ci/run-build-and-tests.sh | 1 + > parallel-checkout.c | 14 ++++++++++++++ > t/README | 4 ++++ > t/lib-parallel-checkout.sh | 3 +++ > 4 files changed, 22 insertions(+) > > diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh > index a66b5e8c75..23b28e7391 100755 > --- a/ci/run-build-and-tests.sh > +++ b/ci/run-build-and-tests.sh > @@ -25,6 +25,7 @@ linux-gcc) > export GIT_TEST_ADD_I_USE_BUILTIN=1 > export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master > export GIT_TEST_WRITE_REV_INDEX=1 > + export GIT_TEST_CHECKOUT_WORKERS=2 > make test > ;; (Making a note to audit the entries here, as I believe some of these could be enabled by default or no longer do anything.) > void get_parallel_checkout_configs(int *num_workers, int *threshold) > { > + char *env_workers = getenv("GIT_TEST_CHECKOUT_WORKERS"); > + > + if (env_workers && *env_workers) { > + if (strtol_i(env_workers, 10, num_workers)) { I had to look up how strtol_i() differs from strtol(). It seems like we should use strtol_i() more often than we do. > + die("invalid value for GIT_TEST_CHECKOUT_WORKERS: '%s'", > + env_workers); > + } > + if (*num_workers < 1) > + *num_workers = online_cpus(); > + > + *threshold = 0; > + return; > + } LGTM. Thanks, -Stolee
diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index a66b5e8c75..23b28e7391 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -25,6 +25,7 @@ linux-gcc) export GIT_TEST_ADD_I_USE_BUILTIN=1 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_WRITE_REV_INDEX=1 + export GIT_TEST_CHECKOUT_WORKERS=2 make test ;; linux-clang) diff --git a/parallel-checkout.c b/parallel-checkout.c index 6fb3f1e6c9..6b1af32bb3 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -35,6 +35,20 @@ static const int DEFAULT_NUM_WORKERS = 1; void get_parallel_checkout_configs(int *num_workers, int *threshold) { + char *env_workers = getenv("GIT_TEST_CHECKOUT_WORKERS"); + + if (env_workers && *env_workers) { + if (strtol_i(env_workers, 10, num_workers)) { + die("invalid value for GIT_TEST_CHECKOUT_WORKERS: '%s'", + env_workers); + } + if (*num_workers < 1) + *num_workers = online_cpus(); + + *threshold = 0; + return; + } + if (git_config_get_int("checkout.workers", num_workers)) *num_workers = DEFAULT_NUM_WORKERS; else if (*num_workers < 1) diff --git a/t/README b/t/README index fd9375b146..a194488f27 100644 --- a/t/README +++ b/t/README @@ -436,6 +436,10 @@ and "sha256". GIT_TEST_WRITE_REV_INDEX=<boolean>, when true enables the 'pack.writeReverseIndex' setting. +GIT_TEST_CHECKOUT_WORKERS=<n> overrides the 'checkout.workers' setting +to <n> and 'checkout.thresholdForParallelism' to 0, forcing the +execution of the parallel-checkout code. + Naming Tests ------------ diff --git a/t/lib-parallel-checkout.sh b/t/lib-parallel-checkout.sh index 16ee18389b..0921a32b96 100644 --- a/t/lib-parallel-checkout.sh +++ b/t/lib-parallel-checkout.sh @@ -1,5 +1,8 @@ # Helpers for t208* tests +# Parallel checkout tests need full control of the number of workers +unset GIT_TEST_CHECKOUT_WORKERS + set_checkout_config () { if test $# -ne 2 then
We already have tests for the basic parallel-checkout operations. But this code can also run be executed by other commands, such as git-read-tree and git-sparse-checkout, which are currently not tested with multiple workers. To promote a wider test coverage without duplicating tests: 1. Add the GIT_TEST_CHECKOUT_WORKERS environment variable, to optionally force parallel-checkout execution during the whole test suite. 2. Set this variable (with a value of 2) in the second test round of our linux-gcc CI job. This round runs `make test` again with some optional GIT_TEST_* variables enabled, so there is no additional overhead in exercising the parallel-checkout code here. Note that tests checking out less than two parallel-eligible entries will fall back to the sequential mode. Nevertheless, it's still a good exercise for the parallel-checkout framework as the fallback codepath also writes the queued entries using the parallel-checkout functions (only without spawning any worker). Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> --- ci/run-build-and-tests.sh | 1 + parallel-checkout.c | 14 ++++++++++++++ t/README | 4 ++++ t/lib-parallel-checkout.sh | 3 +++ 4 files changed, 22 insertions(+)