From 52e773aa80b70d75af34b3731faf6082681331b4 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Mon, 27 Jul 2020 22:39:02 +0200 Subject: [PATCH 1/2] build: parallelize the e2e bats tests Running the e2e bats test sequentially took 15m on my laptop. We should run them all in parallel such that we don't have to wait so long on CI. --- e2e/bats/default.nix | 89 +++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/e2e/bats/default.nix b/e2e/bats/default.nix index cabdd4f049..15fa30f35a 100644 --- a/e2e/bats/default.nix +++ b/e2e/bats/default.nix @@ -4,47 +4,58 @@ , use_ic_ref ? false }: let - e2e = lib.noNixFiles (lib.gitOnlySource ../../. ./.); - lib = pkgs.lib; - sources = pkgs.sources; + inherit (pkgs) lib; - inputs = with pkgs; [ - bats - bash - coreutils - diffutils - curl - findutils - gnugrep - gnutar - gzip - jq - netcat - ps - python3 - procps - which - dfx.standalone - ] ++ lib.optional use_ic_ref ic-ref; -in + isBatsTest = fileName: type: lib.hasSuffix ".bash" fileName && type == "regular"; -builtins.derivation { - name = "e2e-tests"; - system = pkgs.stdenv.system; - PATH = pkgs.lib.makeSearchPath "bin" inputs; - BATSLIB = sources.bats-support; - builder = - pkgs.writeScript "builder.sh" '' - #!${pkgs.stdenv.shell} - set -eo pipefail + here = ./.; - # We want $HOME/.cache to be in a new temporary directory. - export HOME=$(mktemp -d -t dfx-e2e-home-XXXX) + mkBatsTest = fileName: + let + name = lib.removeSuffix ".bash" fileName; + in + lib.nameValuePair name ( + pkgs.runCommandNoCC name { + nativeBuildInputs = with pkgs; [ + bats + diffutils + curl + findutils + gnugrep + gnutar + gzip + jq + netcat + ps + python3 + procps + which + dfx.standalone + ] ++ lib.optional use_ic_ref ic-ref; + BATSLIB = pkgs.sources.bats-support; + USE_IC_REF = use_ic_ref; + } '' + # We want $HOME/.cache to be in a new temporary directory. + export HOME=$(mktemp -d -t dfx-e2e-home-XXXX) - export USE_IC_REF=${if use_ic_ref then "1" else ""} + ln -s ${./utils} utils + ln -s ${./assets} assets + ln -s ${here + "/${fileName}"} ${fileName} - # Timeout of 10 minutes is enough for now. Reminder; CI might be running with - # less resources than a dev's computer, so e2e might take longer. - timeout --preserve-status 3600 bats --recursive ${e2e}/* | tee $out - ''; -} // { meta = {}; } + # Timeout of 10 minutes is enough for now. Reminder; CI might be running with + # less resources than a dev's computer, so e2e might take longer. + timeout --preserve-status 3600 bats ${fileName} | tee $out + '' + ); +in +builtins.listToAttrs + ( + builtins.map mkBatsTest + ( + lib.attrNames + ( + lib.filterAttrs isBatsTest + (builtins.readDir here) + ) + ) + ) From 9c520d5a3e934dba452b8d6123f8ab271a04d78b Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Tue, 28 Jul 2020 09:31:18 +0200 Subject: [PATCH 2/2] e2e/bats: better name of the derivations --- e2e/bats/default.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/e2e/bats/default.nix b/e2e/bats/default.nix index 15fa30f35a..b468eebae4 100644 --- a/e2e/bats/default.nix +++ b/e2e/bats/default.nix @@ -15,7 +15,7 @@ let name = lib.removeSuffix ".bash" fileName; in lib.nameValuePair name ( - pkgs.runCommandNoCC name { + pkgs.runCommandNoCC "e2e-test-${name}${lib.optionalString use_ic_ref "-use_ic_ref"}" { nativeBuildInputs = with pkgs; [ bats diffutils @@ -34,17 +34,19 @@ let ] ++ lib.optional use_ic_ref ic-ref; BATSLIB = pkgs.sources.bats-support; USE_IC_REF = use_ic_ref; + utils = lib.gitOnlySource ../../. ./utils; + assets = lib.gitOnlySource ../../. ./assets; + test = here + "/${fileName}"; } '' - # We want $HOME/.cache to be in a new temporary directory. - export HOME=$(mktemp -d -t dfx-e2e-home-XXXX) + export HOME=$(pwd) - ln -s ${./utils} utils - ln -s ${./assets} assets - ln -s ${here + "/${fileName}"} ${fileName} + ln -s $utils utils + ln -s $assets assets + ln -s $test test # Timeout of 10 minutes is enough for now. Reminder; CI might be running with # less resources than a dev's computer, so e2e might take longer. - timeout --preserve-status 3600 bats ${fileName} | tee $out + timeout --preserve-status 3600 bats test | tee $out '' ); in