Create an ephemeral PostgreSQL database per test

[?]
Feb 22, 2021, 6:47 PM
OWRS526HCBSKWK5KFWO34YSZRNRXWBBG74KLW7BZSRIIZUNSELBQC

Dependencies

Change contents

  • edit in src/libhydra/db.hh at line 16
    [4.57][3.11392:11463](),[2.10956][4.119:215](),[3.11463][4.119:215](),[4.119][4.119:215](),[4.215][4.444:615](),[4.444][4.444:615]()
    auto s = getEnv("HYDRA_DBI").value_or("dbi:Pg:dbname=hydra;");
    std::string prefix = "dbi:Pg:";
    if (std::string(s, 0, prefix.size()) != prefix)
    throw Error("$HYDRA_DBI does not denote a PostgreSQL database");
    return concatStringsSep(" ", tokenizeString<Strings>(string(s, prefix.size()), ";"));
  • resolve order conflict in src/libhydra/db.hh at line 16
    [2.10956]
  • edit in src/libhydra/db.hh at line 16
    [0.1]
    [4.615]
    std::string lower_prefix = "dbi:Pg:";
    std::string upper_prefix = "DBI:Pg:";
    if ((std::string(s, 0, lower_prefix.size()) == lower_prefix) ||
    (std::string(s, 0, upper_prefix.size()) == upper_prefix)) {
    return concatStringsSep(" ", tokenizeString<Strings>(string(s, lower_prefix.size()), ";"));
    }
    throw Error("$HYDRA_DBI does not denote a PostgreSQL database");
  • edit in tests/evaluation.t at line 2
    [4.851][4.851:870](),[4.870][4.175:197]()
    use Hydra::Schema;
    use Hydra::Model::DB;
  • replacement in tests/evaluation.t at line 5
    [4.946][4.198:230]()
    my $db = Hydra::Model::DB->new;
    [4.946]
    [4.968]
    my $pgsql = dbinit();
    my $dsn = $pgsql->dsn;
    require Hydra::Schema;
    require Hydra::Model::DB;
  • edit in tests/evaluation.t at line 13
    [4.999]
    [4.999]
    my $db = Hydra::Model::DB->new;
  • replacement in tests/lib/Setup.pm at line 5
    [4.561][4.184:208](),[4.208][4.0:22]()
    use Hydra::Helper::Nix;
    use Hydra::Model::DB;
    [4.561]
    [4.238]
    use Test::PostgreSQL;
  • replacement in tests/lib/Setup.pm at line 9
    [4.587][4.4151:4327]()
    our @EXPORT = qw(hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
    [4.587]
    [4.618]
    our @EXPORT = qw(dbinit hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
    sub dbinit() {
    my $pgsql = Test::PostgreSQL->new();
    $ENV{'HYDRA_DBI'} = $pgsql->dsn;
    system("hydra-init") == 0 or die;
    return $pgsql;
    }
    sub captureStdoutStderr {
    # "Lazy"-load Hydra::Helper::Nix to avoid the compile-time
    # import of Hydra::Model::DB. Early loading of the DB class
    # causes fixation of the DSN, and we need to fixate it after
    # the temporary DB is setup.
    require Hydra::Helper::Nix;
    return Hydra::Helper::Nix::captureStdoutStderr(@_)
    }