Skip to content
Snippets Groups Projects
Unverified Commit 2e175a01 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone Committed by GitHub
Browse files

Merge pull request #306 from PrivateStorageio/multiprocess-coverage-hacks

Use trial multiprocess feature even when collecting coverage
parents 1b25173f bf44f510
No related branches found
No related tags found
No related merge requests found
...@@ -201,7 +201,13 @@ jobs: ...@@ -201,7 +201,13 @@ jobs:
# #
# Further, we want the "doc" output built as well because that's # Further, we want the "doc" output built as well because that's
# where the coverage data ends up. # where the coverage data ends up.
nix-build tests.nix \ #
# Also explicitly specify the number of cores to use such that it
# only slightly exceeds what CircleCI advertises for the resource
# class (defined above) we're using. The CircleCI environment
# looks like it has many more cores than are actually usable by
# our build.
nix-build --cores 5 tests.nix \
--argstr hypothesisProfile ci \ --argstr hypothesisProfile ci \
--arg collectCoverage true \ --arg collectCoverage true \
--argstr tahoe-lafs-source << parameters.tahoe-lafs-source >> \ --argstr tahoe-lafs-source << parameters.tahoe-lafs-source >> \
......
...@@ -21,43 +21,61 @@ let ...@@ -21,43 +21,61 @@ let
inherit (privatestorage) pkgs mach-nix zkapauthorizer; inherit (privatestorage) pkgs mach-nix zkapauthorizer;
inherit (pkgs) lib; inherit (pkgs) lib;
hypothesisProfile' = if hypothesisProfile == null then "default" else hypothesisProfile; hypothesisProfile' = if hypothesisProfile == null then "default" else hypothesisProfile;
defaultTrialArgs = [ "--rterrors" ] ++ (lib.optional (! collectCoverage) "--jobs=$(($NIX_BUILD_CORES > 8 ? 8 : $NIX_BUILD_CORES))"); defaultTrialArgs = [ "--rterrors" "--jobs=$NIX_BUILD_CORES" ];
trialArgs' = if trialArgs == null then defaultTrialArgs else trialArgs; trialArgs' = if trialArgs == null then defaultTrialArgs else trialArgs;
extraTrialArgs = builtins.concatStringsSep " " trialArgs'; extraTrialArgs = builtins.concatStringsSep " " trialArgs';
testSuite' = if testSuite == null then "_zkapauthorizer" else testSuite; testSuite' = if testSuite == null then "_zkapauthorizer" else testSuite;
coveragerc = builtins.path {
name = "coveragerc";
path = ./.coveragerc;
};
coverage-env = lib.optionalString collectCoverage "COVERAGE_PROCESS_START=${coveragerc}";
coverage-cmd = lib.optionalString collectCoverage "coverage run --debug=config --rcfile=${coveragerc} --module";
python = mach-nix.mkPython { python = mach-nix.mkPython {
inherit (zkapauthorizer.meta.mach-nix) python providers; inherit (zkapauthorizer.meta.mach-nix) python providers;
requirements = requirements = ''
builtins.readFile ./requirements/test.in; ${builtins.readFile ./requirements/test.in}
${if collectCoverage then "coverage_enable_subprocess" else ""}
'';
packagesExtra = [ zkapauthorizer ]; packagesExtra = [ zkapauthorizer ];
_.hypothesis.postUnpack = ""; _.hypothesis.postUnpack = "";
}; };
tests = pkgs.runCommand "zkapauthorizer-tests" { lint = pkgs.runCommand "zkapauthorizer-lint" {
passthru = { passthru = {
inherit python; inherit python;
}; };
} '' } ''
mkdir -p $out
pushd ${zkapauthorizer.src} pushd ${zkapauthorizer.src}
${python}/bin/flake8 src ${python}/bin/flake8 src
popd popd
ZKAPAUTHORIZER_HYPOTHESIS_PROFILE=${hypothesisProfile'} ${python}/bin/python -m ${if collectCoverage touch $out
then "coverage run --debug=config --rcfile=${zkapauthorizer.src}/.coveragerc --module" '';
else ""
} twisted.trial ${extraTrialArgs} ${testSuite'} tests = pkgs.runCommand "zkapauthorizer-tests" {
passthru = {
inherit python;
};
} ''
mkdir -p $out
export ZKAPAUTHORIZER_HYPOTHESIS_PROFILE=${hypothesisProfile'}
${coverage-env} ${python}/bin/python -m ${coverage-cmd} twisted.trial ${extraTrialArgs} ${testSuite'}
${lib.optionalString collectCoverage ${lib.optionalString collectCoverage
'' ''
mkdir -p "$out/coverage" mkdir -p "$out/coverage"
cp -v .coverage.* "$out/coverage" cp -v .coverage.* "$out/coverage"
${python}/bin/python -m coverage combine
cp -v .coverage "$out/coverage"
${python}/bin/python -m coverage html -d "$out/htmlcov"
'' ''
} }
''; '';
in in
{ {
inherit privatestorage tests; inherit privatestorage lint tests;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment