tests/input-types: split out scminputs into individual tests

[?]
Mar 4, 2021, 8:38 PM
F7WJVMRVVVHGPWTF67Y6YVZ6JNMH3PBK74VHQ24QRZD3RLUTYRSQC

Dependencies

  • [2] IH26BRUJ Run tests with yath
  • [3] NYLYQIFH input-types.t: don't litter ./tests/
  • [4] LZVO64YG Merge in the first bits of the API work
  • [5] S5KKIQ3F * Remove accidentally commited foo/bar.
  • [6] G2ZB6464 first test, not yet in buildprocess
  • [7] HRBL4HYR input-types: use is() for test comparisons
  • [8] IRZYSVNO tests: delete set-up.pl / tear-down.pl
  • [9] ZTYKNDOL Move tests for SCM inputs in to its own .t
  • [10] 7VQ4ALFY Update "make check" for the new queue runner
  • [11] ANJBFPBE Added the InfluxDBNotification plugin including a NixOS test
  • [12] PXUP3HRC hydra: query-all-tables.pl.in, set executable
  • [13] UIA3ULNU Give each test its own Nix directories
  • [14] 3G475GRT Split out dependent tests in to its own .t
  • [15] HX4QYOYA add first evaluations tests
  • [16] UGA45FNC Add a plugin for backing up builds in s3
  • [17] CQI443CG Relocate the final evalutation tests to a build-products specific test.
  • [18] L4AI5YL6 Rename hydra_*.pl to hydra-*
  • [19] 3AKZKWCR RunCommand: Test
  • [20] XEQNMJ73 Increase depth 0
  • [21] M2MAIY22 Add bar with 1
  • [*] GBCPEGYC Add a .gitignore
  • [*] G7LMCJH5 Add some gitignores
  • [*] HE3GX5IP Optimize fetch-git.
  • [*] 3RL7VFKE Add tests for "git describe --long".
  • [*] ABB3BIS2 Add eval test for specific git revision
  • [*] LZYXZOLK * Add 'set -e' to all scm test setup scripts, to catch errors as early as possible

Change contents

  • edit in .gitignore at line 32
    [24.102]
    [24.102]
    /tests/data
  • file deletion: input-types.t (----------)
    [4.73][4.3464:3501](),[4.3501][4.103:103]()
    use strict;
    use Cwd;
    use Setup;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    my $testdir = getcwd;
    my $scratchdir = "$datadir/scratch";
    mkdir $scratchdir;
    my $jobsBaseUri = "file://".$scratchdir;
    # Test scm inputs
    my @scminputs = (
    {
    name => "svn",
    nixexpr => "svn-input.nix",
    type => "svn",
    uri => "$jobsBaseUri/svn-repo",
    update => $testdir . "/jobs/svn-update.sh"
    },
    {
    name => "svn-checkout",
    nixexpr => "svn-checkout-input.nix",
    type => "svn-checkout",
    uri => "$jobsBaseUri/svn-checkout-repo",
    update => $testdir . "/jobs/svn-checkout-update.sh"
    },
    {
    name => "git",
    nixexpr => "git-input.nix",
    type => "git",
    uri => "$jobsBaseUri/git-repo",
    update => $testdir . "/jobs/git-update.sh"
    },
    {
    name => "git-rev",
    nixexpr => "git-rev-input.nix",
    type => "git",
    uri => "$jobsBaseUri/git-repo 7f60df502b96fd54bbfa64dd94b56d936a407701",
    update => $testdir . "/jobs/git-rev-update.sh"
    },
    {
    name => "deepgit",
    nixexpr => "deepgit-input.nix",
    type => "git",
    uri => "$jobsBaseUri/git-repo master 1",
    update => $testdir . "/jobs/git-update.sh"
    },
    {
    name => "bzr",
    nixexpr => "bzr-input.nix",
    type => "bzr",
    uri => "$jobsBaseUri/bzr-repo",
    update => $testdir . "/jobs/bzr-update.sh"
    },
    {
    name => "bzr-checkout",
    nixexpr => "bzr-checkout-input.nix",
    type => "bzr-checkout",
    uri => "$jobsBaseUri/bzr-checkout-repo",
    update => $testdir . "/jobs/bzr-checkout-update.sh"
    },
    {
    name => "hg",
    nixexpr => "hg-input.nix",
    type => "hg",
    uri => "$jobsBaseUri/hg-repo",
    update => $testdir . "/jobs/hg-update.sh"
    },
    {
    name => "darcs",
    nixexpr => "darcs-input.nix",
    type => "darcs",
    uri => "$jobsBaseUri/darcs-repo",
    update => $testdir . "/jobs/darcs-update.sh"
    }
    );
    foreach my $scm ( @scminputs ) {
    my $scmName = $scm->{"name"};
    subtest "With the SCM input named $scmName" => sub {
    my $nixexpr = $scm->{"nixexpr"};
    my $type = $scm->{"type"};
    my $uri = $scm->{"uri"};
    my $update = $scm->{"update"};
    my $jobset = createJobsetWithOneInput($scmName, $nixexpr, "src", $type, $uri);
    my $state = 0;
    my $q = 0;
    my ($loop, $updated) = updateRepository($scmName, $update, $scratchdir);
    while($loop) {
    subtest "Mutation number $state" => sub {
    # Verify that it can be fetched and possibly queued.
    ok(evalSucceeds($jobset), "Evaluating nix-expression.");
    # Verify that the evaluation has queued a new job and evaluate again to ...
    if ($updated) {
    $q++;
    is(nrQueuedBuildsForJobset($jobset), $q, "Expect $q jobs in the queue.");
    ok(evalSucceeds($jobset), "Evaluating nix-expression again.");
    }
    # ... check that it is deterministic and not queued again.
    is(nrQueuedBuildsForJobset($jobset), $q, "Expect deterministic evaluation.");
    $state++;
    ($loop, $updated) = updateRepository($scmName, $update, $scratchdir);
    };
    }
    };
    }
    done_testing;
  • file addition: input-types (d--r------)
    [4.73]
  • file addition: bzr-checkout.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a bzr checkout as input.
    testScmInput(
    type => 'bzr-checkout',
    expr => 'bzr-checkout-input.nix',
    uri => 'bzr-checkout-repo',
    update => 'jobs/bzr-checkout-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: bzr.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a bzr repo as input.
    testScmInput(
    type => 'bzr',
    expr => 'bzr-input.nix',
    uri => 'bzr-repo',
    update => 'jobs/bzr-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: darcs.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a darcs repo as input.
    testScmInput(
    type => 'darcs',
    expr => 'darcs-input.nix',
    uri => 'darcs-repo',
    update => 'jobs/darcs-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: deepgit.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a deep git clone as input.
    testScmInput(
    type => 'git',
    name => 'deepgit',
    expr => 'deepgit-input.nix',
    uri => 'git-repo master 1',
    update => 'jobs/git-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: git-rev.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a git revision as input.
    testScmInput(
    type => 'git',
    name => 'git-rev',
    expr => 'git-rev-input.nix',
    uri => 'git-repo 7f60df502b96fd54bbfa64dd94b56d936a407701',
    update => 'jobs/git-rev-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: git.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a git repo as input.
    testScmInput(
    type => 'git',
    expr => 'git-input.nix',
    uri => 'git-repo',
    update => 'jobs/git-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: hg.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a hg repo as input.
    testScmInput(
    type => 'hg',
    expr => 'hg-input.nix',
    uri => 'hg-repo',
    update => 'jobs/hg-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: svn-checkout.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a svn checkout as input.
    testScmInput(
    type => 'svn-checkout',
    expr => 'svn-checkout-input.nix',
    uri => 'svn-checkout-repo',
    update => 'jobs/svn-checkout-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • file addition: svn.t (----------)
    [0.14]
    use strict;
    use Cwd;
    use Setup;
    use TestScmInput;
    (my $datadir, my $pgsql) = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    # Tests the creation of a Hydra jobset using a svn repo as input.
    testScmInput(
    type => 'svn',
    expr => 'svn-input.nix',
    uri => 'svn-repo',
    update => 'jobs/svn-update.sh',
    # directories
    datadir => $datadir,
    testdir => getcwd,
    );
    done_testing;
  • edit in tests/jobs/bzr-checkout-update.sh at line 12
    [26.3098]
    [26.3098]
    export BZR_HOME; # Set by the Makefile
  • edit in tests/jobs/bzr-checkout-update.sh at line 15
    [26.3168]
    [26.3168]
    bzr init bzr-repo
    bzr whoami "build <build@invalid.org>" -d bzr-repo
    touch bzr-repo/bzr-file
    bzr add bzr-repo/bzr-file
    bzr commit -m "add bzr-file" bzr-repo/bzr-file
  • edit in tests/jobs/git-rev-update.sh at line 6
    [27.525]
    [27.525]
    export XDG_CONFIG_HOME=$(pwd)/.config
  • edit in tests/jobs/git-update.sh at line 7
    [28.36]
    [26.4243]
    export XDG_CONFIG_HOME=$(pwd)/.config
  • edit in tests/jobs/svn-checkout-update.sh at line 14
    [26.5851]
    [26.5851]
    svnadmin create svn-repo
    svn co file://$PWD/$repo svn-checkout
    touch svn-checkout/svn-file
    svn add svn-checkout/svn-file
    svn commit -m "add svn file" svn-checkout/svn-file
  • file addition: TestScmInput.pm (----------)
    [2.107]
    package TestScmInput;
    use warnings;
    use strict;
    use Exporter;
    use Test2::V0;
    use Setup;
    our @ISA = qw(Exporter);
    our @EXPORT = qw(testScmInput);
    # Generic test for the various SCM types Hydra supports.
    #
    # Takes input in the form of:
    #
    # (
    # type => "input type",
    # name => "jobset name", # defaults to the input's type
    # uri => "uri",
    # update => "script for updating the input",
    # datadir => "data dir", # returned from `test_init()` subroutine
    # testdir => "the hydra tests directory", # usually just `getcwd`
    # )
    #
    # and runs a test that constructs a jobset from the specified input.
    sub testScmInput {
    # Collect named args, dying if a required arg is missing
    my %args = @_;
    my $type = $args{type} // die "required arg 'type' missing";
    my $expr = $args{expr} // die "required arg 'expr' missing";
    # $name is optional and defaults to $type
    my $name = $args{name} // $type;
    # Get directories
    my $testdir = $args{testdir} // die "required arg 'testdir' missing";
    my $datadir = $args{datadir} // die "required arg 'datadir' missing";
    my $update = $args{update} // die "required arg 'update' missing";
    $update = "$testdir/$update";
    # Create scratch locations
    my $scratchdir = "$datadir/scratch";
    mkdir $scratchdir or die "mkdir($scratchdir): $!\n";
    # $uri and $update are constructed from the directories
    my $uri = $args{uri} // die "required arg 'uri' missing";
    $uri = "file://$scratchdir/$uri";
    subtest "With the SCM input named $name" => sub {
    my $jobset = createJobsetWithOneInput($name, $expr, 'src', $type, $uri);
    my ($mutations, $queueSize) = (0, 0);
    my ($loop, $updated) = updateRepository($name, $update, $scratchdir);
    while ($loop) {
    subtest "Mutation number $mutations" => sub {
    ok(evalSucceeds($jobset), "Evaluating nix-expression.");
    if ($updated) {
    $queueSize++;
    is(nrQueuedBuildsForJobset($jobset), $queueSize, "Expect $queueSize jobs in the queue.");
    ok(evalSucceeds($jobset), "Evaluating nix-expression again.");
    }
    is(nrQueuedBuildsForJobset($jobset), $queueSize, "Expect deterministic evaluation.");
    $mutations++;
    ($loop, $updated) = updateRepository($name, $update, $scratchdir);
    };
    }
    };
    }