Attempt to fix errors during test teardown

[?]
Dec 8, 2021, 6:31 PM
OSIBECOEJH25QAXCZ76PY7OTP3STBNWEUC36WRTNYAN3IIJP5ZQQC

Dependencies

  • [2] YIZWKGFI tests: add jobsdir and testdir to ctx hash
  • [3] I7UFBBQG Setup.pm: specify NIX_ env vars for running yath
  • [4] PVKBPA7Z Document the use_external_destination_store test_init param
  • [5] 3JD6P6FH t/lib/Setup.pm: nix_config: default to empty string
  • [6] LYRHVDS2 TT: add helpers for linking to jobs, jobsets, and projects, and for generating colon separated names.
  • [7] HE3GX5IP Optimize fetch-git.
  • [8] 4WLW4VHS Test setup: support arbitrary hydra config
  • [9] C66VQYWT Run the tests with a remote dest store
  • [10] 4QI6G7YB tests: replace the flat list of contexts with a hash
  • [11] U2PHPVGD t/Setup.pm: sort NIX_ env vars
  • [12] UIA3ULNU Give each test its own Nix directories
  • [13] OWRS526H Create an ephemeral PostgreSQL database per test
  • [14] HX4QYOYA add first evaluations tests
  • [15] CSNQ6TCF Drop references to NIX_MANFIESTS_DIR and NIX_BUILD_HOOK
  • [16] 2I3HFWBK tests: Make the external destination store optional
  • [17] HXEZUCTD Add test to verify includes work
  • [18] DNOLOMX7 hydra-send-stats: add a failing test asserting it can run
  • [19] 7I2U2MHU perlcritic: use strict, use warnings
  • [20] ZY6CMDJY fixup: TT.t: move the :'s to the next line
  • [21] 3AKZKWCR RunCommand: Test
  • [22] FAIJDQKZ
  • [23] 6HYCG3DC tests: allow specifying some nix config
  • [24] 5TJXSY4C TT.t: fixup $_, since _ is a special variable, not a throwaway
  • [*] 2JJP7673 tests: move to t, allow `yath test` from root

Change contents

  • edit in t/View/TT.t at line 5
    [6.4538]
    [6.4538]
    use Test2::V0;
  • replacement in t/View/TT.t at line 7
    [6.4539][6.4539:4562]()
    my %ctx = test_init();
    [6.4539]
    [6.4562]
    my $ctx = test_context();
  • edit in t/View/TT.t at line 9
    [6.4563][6.4563:4629]()
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
  • replacement in t/View/TT.t at line 10
    [6.4660][6.4660:4661]()
    [6.4660]
    [6.4661]
    require Hydra::View::TT;
    require Catalyst::Test;
  • replacement in t/View/TT.t at line 13
    [6.4662][6.4662:4712]()
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    [6.4662]
    [6.4712]
    my $db = $ctx->db;
  • edit in t/View/TT.t at line 15
    [6.4713][6.4713:4738]()
    require Hydra::View::TT;
  • edit in t/View/TT.t at line 18
    [6.4838][6.4838:4862]()
    require Catalyst::Test;
  • replacement in t/View/TT.t at line 23
    [6.5033][6.5033:5103]()
    my $jobset = createBaseJobset("example", "bogus.nix", $ctx{jobsdir});
    [6.5033]
    [6.5103]
    my $jobset = createBaseJobset("example", "bogus.nix", $ctx->jobsdir);
  • edit in t/evaluate-basic.t at line 5
    [7.65][7.65:66](),[7.66][7.24:47](),[7.47][7.106:157](),[7.106][7.106:157]()
    my %ctx = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
  • replacement in t/evaluate-basic.t at line 7
    [7.173][7.173:223]()
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    [7.173]
    [7.223]
    my $ctx = test_context();
    my $db = $ctx->db;
  • replacement in t/evaluate-basic.t at line 13
    [7.368][2.87:155]()
    my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
    [7.368]
    [7.421]
    my $jobset = createBaseJobset("basic", "basic.nix", $ctx->jobsdir);
  • file addition: HydraTestContext.pm (----------)
    [26.2459]
    use strict;
    use warnings;
    package HydraTestContext;
    use File::Path qw(make_path);
    use File::Basename;
    use Cwd qw(abs_path getcwd);
    # Set up the environment for running tests.
    #
    # Hash Parameters:
    #
    # * hydra_config: configuration for the Hydra processes for your test.
    # * nix_config: text to include in the test's nix.conf
    # * use_external_destination_store: Boolean indicating whether hydra should
    # use a destination store different from the evaluation store.
    # True by default.
    #
    # This clears several environment variables and sets them to ephemeral
    # values: a temporary database, temporary Nix store, temporary Hydra
    # data directory, etc.
    #
    # Note: This function must run _very_ early, before nearly any Hydra
    # libraries are loaded. To use this, you very likely need to `use Setup`
    # and then run `test_init`, and then `require` the Hydra libraries you
    # need.
    #
    # It returns a tuple: a handle to a temporary directory and a handle to
    # the postgres service. If either of these variables go out of scope,
    # those resources are released and the test environment becomes invalid.
    #
    # Look at the top of an existing `.t` file to see how this should be used
    # in practice.
    sub new {
    my ($class, %opts) = @_;
    my $dir = File::Temp->newdir();
    $ENV{'HYDRA_DATA'} = "$dir/hydra-data";
    mkdir $ENV{'HYDRA_DATA'};
    $ENV{'NIX_CONF_DIR'} = "$dir/nix/etc/nix";
    make_path($ENV{'NIX_CONF_DIR'});
    my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf";
    my $nix_config = "sandbox = false\n" . ($opts{'nix_config'} || "");
    write_file($nixconf, $nix_config);
    $ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf";
    my $hydra_config = $opts{'hydra_config'} || "";
    if ($opts{'use_external_destination_store'} // 1) {
    $hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config;
    }
    write_file($ENV{'HYDRA_CONFIG'}, $hydra_config);
    $ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix";
    $ENV{'NIX_REMOTE_SYSTEMS'} = '';
    $ENV{'NIX_REMOTE'} = '';
    $ENV{'NIX_STATE_DIR'} = "$dir/nix/var/nix";
    $ENV{'NIX_STORE_DIR'} = "$dir/nix/store";
    my $pgsql = Test::PostgreSQL->new(
    extra_initdb_args => "--locale C.UTF-8"
    );
    $ENV{'HYDRA_DBI'} = $pgsql->dsn;
    system("hydra-init") == 0 or die;
    my $self = {
    _db => undef,
    db_handle => $pgsql,
    tmpdir => $dir,
    testdir => abs_path(dirname(__FILE__) . "/.."),
    jobsdir => abs_path(dirname(__FILE__) . "/../jobs")
    };
    return bless $self, $class;
    }
    sub db {
    my ($self, $setup) = @_;
    if (!defined $self->{_db}) {
    require Hydra::Schema;
    require Hydra::Model::DB;
    $self->{_db} = Hydra::Model::DB->new();
    if (!(defined $setup && $setup == 0)) {
    $self->{_db}->resultset('Users')->create({
    username => "root",
    emailaddress => 'root@invalid.org',
    password => ''
    });
    }
    }
    return $self->{_db};
    }
    sub tmpdir {
    my ($self) = @_;
    return $self->{tmpdir};
    }
    sub testdir {
    my ($self) = @_;
    return $self->{testdir};
    }
    sub jobsdir {
    my ($self) = @_;
    return $self->{jobsdir};
    }
    sub DESTROY
    {
    my ($self) = @_;
    $self->db(0)->schema->storage->disconnect();
    }
    sub write_file {
    my ($path, $text) = @_;
    open(my $fh, '>', $path) or die "Could not open file '$path' $!";
    print $fh $text || "";
    close $fh;
    }
    1;
  • replacement in t/lib/Setup.pm at line 13
    [7.587][7.485:575]()
    our @EXPORT = qw(test_init hydra_setup write_file nrBuildsForJobset queuedBuildsForJobset
    [7.587]
    [7.79]
    our @EXPORT = qw(test_context test_init hydra_setup write_file nrBuildsForJobset queuedBuildsForJobset
  • replacement in t/lib/Setup.pm at line 20
    [7.46][7.46:65]()
    # Hash Parameters:
    [7.46]
    [7.65]
    # See HydraTestContext::new for documentation
    sub test_context {
    require HydraTestContext;
    return HydraTestContext->new(@_);
    }
    # Set up the environment for running tests.
  • replacement in t/lib/Setup.pm at line 28
    [7.67][7.67:139](),[7.139][7.0:56](),[7.56][4.0:171](),[7.56][7.139:835](),[4.171][7.139:835](),[7.139][7.139:835]()
    # * hydra_config: configuration for the Hydra processes for your test.
    # * nix_config: text to include in the test's nix.conf
    # * use_external_destination_store: Boolean indicating whether hydra should
    # use a destination store different from the evaluation store.
    # True by default.
    #
    # This clears several environment variables and sets them to ephemeral
    # values: a temporary database, temporary Nix store, temporary Hydra
    # data directory, etc.
    #
    # Note: This function must run _very_ early, before nearly any Hydra
    # libraries are loaded. To use this, you very likely need to `use Setup`
    # and then run `test_init`, and then `require` the Hydra libraries you
    # need.
    #
    # It returns a tuple: a handle to a temporary directory and a handle to
    # the postgres service. If either of these variables go out of scope,
    # those resources are released and the test environment becomes invalid.
    #
    # Look at the top of an existing `.t` file to see how this should be used
    # in practice.
    [7.67]
    [7.835]
    # See HydraTestContext::new for documentation
  • replacement in t/lib/Setup.pm at line 30
    [7.851][7.851:871](),[7.871][7.1521:1767](),[7.1521][7.1521:1767](),[7.1767][5.0:72](),[5.72][7.640:679](),[7.640][7.640:679](),[7.679][7.873:919](),[7.873][7.873:919]()
    my %opts = @_;
    my $dir = File::Temp->newdir();
    $ENV{'HYDRA_DATA'} = "$dir/hydra-data";
    mkdir $ENV{'HYDRA_DATA'};
    $ENV{'NIX_CONF_DIR'} = "$dir/nix/etc/nix";
    make_path($ENV{'NIX_CONF_DIR'});
    my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf";
    my $nix_config = "sandbox = false\n" . ($opts{'nix_config'} || "");
    write_file($nixconf, $nix_config);
    $ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf";
    [7.851]
    [7.1893]
    require HydraTestContext;
    my $ctx = HydraTestContext->new(@_);
  • edit in t/lib/Setup.pm at line 33
    [7.1894][7.680:732](),[7.732][7.0:56](),[7.1026][7.0:56](),[7.56][7.733:815](),[7.815][7.115:121](),[7.115][7.115:121](),[7.121][7.816:870](),[7.870][7.1084:1085](),[7.1084][7.1084:1085](),[7.1085][7.0:50](),[7.50][3.0:66](),[7.50][7.1894:1942](),[3.66][7.1894:1942](),[7.1085][7.1894:1942](),[7.1894][7.1894:1942](),[7.2005][7.2005:2051](),[7.2101][7.2101:2196](),[7.2196][7.821:896](),[7.821][7.821:896]()
    my $hydra_config = $opts{'hydra_config'} || "";
    if ($opts{'use_external_destination_store'} // 1) {
    $hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config;
    }
    write_file($ENV{'HYDRA_CONFIG'}, $hydra_config);
    $ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix";
    $ENV{'NIX_REMOTE_SYSTEMS'} = '';
    $ENV{'NIX_REMOTE'} = '';
    $ENV{'NIX_STATE_DIR'} = "$dir/nix/var/nix";
    $ENV{'NIX_STORE_DIR'} = "$dir/nix/store";
    my $pgsql = Test::PostgreSQL->new(
    extra_initdb_args => "--locale C.UTF-8"
    );
    $ENV{'HYDRA_DBI'} = $pgsql->dsn;
    system("hydra-init") == 0 or die;
  • replacement in t/lib/Setup.pm at line 34
    [7.85][2.1331:1353](),[2.1353][7.85:109](),[7.85][7.85:109](),[7.109][2.1354:1470](),[2.1470][7.130:137](),[7.130][7.130:137]()
    db => $pgsql,
    tmpdir => $dir,
    testdir => abs_path(dirname(__FILE__) . "/.."),
    jobsdir => abs_path(dirname(__FILE__) . "/../jobs")
    );
    [7.85]
    [7.871]
    context => $ctx,
    tmpdir => $ctx->tmpdir,
    testdir => $ctx->testdir,
    jobsdir => $ctx->jobsdir
    )