postgresqlPackages.timescaledb: move test from VM to postgresqlTestExtension
This commit is contained in:
@@ -38,7 +38,6 @@ in
|
|||||||
anonymizer = importWithArgs ./anonymizer.nix;
|
anonymizer = importWithArgs ./anonymizer.nix;
|
||||||
pgjwt = importWithArgs ./pgjwt.nix;
|
pgjwt = importWithArgs ./pgjwt.nix;
|
||||||
pgvecto-rs = importWithArgs ./pgvecto-rs.nix;
|
pgvecto-rs = importWithArgs ./pgvecto-rs.nix;
|
||||||
timescaledb = importWithArgs ./timescaledb.nix;
|
|
||||||
tsja = importWithArgs ./tsja.nix;
|
tsja = importWithArgs ./tsja.nix;
|
||||||
wal2json = importWithArgs ./wal2json.nix;
|
wal2json = importWithArgs ./wal2json.nix;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
makeTest,
|
|
||||||
genTests,
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
|
|
||||||
test-sql = pkgs.writeText "postgresql-test" ''
|
|
||||||
CREATE EXTENSION timescaledb;
|
|
||||||
CREATE EXTENSION timescaledb_toolkit;
|
|
||||||
|
|
||||||
CREATE TABLE sth (
|
|
||||||
time TIMESTAMPTZ NOT NULL,
|
|
||||||
value DOUBLE PRECISION
|
|
||||||
);
|
|
||||||
|
|
||||||
SELECT create_hypertable('sth', 'time');
|
|
||||||
|
|
||||||
INSERT INTO sth (time, value) VALUES
|
|
||||||
('2003-04-12 04:05:06 America/New_York', 1.0),
|
|
||||||
('2003-04-12 04:05:07 America/New_York', 2.0),
|
|
||||||
('2003-04-12 04:05:08 America/New_York', 3.0),
|
|
||||||
('2003-04-12 04:05:09 America/New_York', 4.0),
|
|
||||||
('2003-04-12 04:05:10 America/New_York', 5.0)
|
|
||||||
;
|
|
||||||
|
|
||||||
WITH t AS (
|
|
||||||
SELECT
|
|
||||||
time_bucket('1 day'::interval, time) AS dt,
|
|
||||||
stats_agg(value) AS stats
|
|
||||||
FROM sth
|
|
||||||
GROUP BY time_bucket('1 day'::interval, time)
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
average(stats)
|
|
||||||
FROM t;
|
|
||||||
|
|
||||||
SELECT * FROM sth;
|
|
||||||
'';
|
|
||||||
|
|
||||||
makeTestFor =
|
|
||||||
package:
|
|
||||||
makeTest {
|
|
||||||
name = "timescaledb-${package.name}";
|
|
||||||
meta = with lib.maintainers; {
|
|
||||||
maintainers = [ typetetris ];
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes.machine =
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
services.postgresql = {
|
|
||||||
inherit package;
|
|
||||||
enable = true;
|
|
||||||
enableJIT = lib.hasInfix "-jit-" package.name;
|
|
||||||
extensions =
|
|
||||||
ps: with ps; [
|
|
||||||
timescaledb
|
|
||||||
timescaledb_toolkit
|
|
||||||
];
|
|
||||||
settings = {
|
|
||||||
shared_preload_libraries = "timescaledb, timescaledb_toolkit";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
def check_count(statement, lines):
|
|
||||||
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
|
|
||||||
statement, lines
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
machine.start()
|
|
||||||
machine.wait_for_unit("postgresql")
|
|
||||||
|
|
||||||
with subtest("Postgresql with extensions timescaledb and timescaledb_toolkit is available just after unit start"):
|
|
||||||
machine.succeed(
|
|
||||||
"sudo -u postgres psql -f ${test-sql}"
|
|
||||||
)
|
|
||||||
|
|
||||||
machine.fail(check_count("SELECT * FROM sth;", 3))
|
|
||||||
machine.succeed(check_count("SELECT * FROM sth;", 5))
|
|
||||||
machine.fail(check_count("SELECT * FROM sth;", 4))
|
|
||||||
|
|
||||||
machine.shutdown()
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in
|
|
||||||
# Not run by default, because this requires allowUnfree.
|
|
||||||
# To run these tests:
|
|
||||||
# NIXPKGS_ALLOW_UNFREE=1 nix-build -A nixosTests.postgresql.timescaledb
|
|
||||||
lib.dontRecurseIntoAttrs (genTests {
|
|
||||||
inherit makeTestFor;
|
|
||||||
filter = _: p: !p.pkgs.timescaledb.meta.broken;
|
|
||||||
})
|
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
openssl,
|
openssl,
|
||||||
postgresql,
|
postgresql,
|
||||||
postgresqlBuildExtension,
|
postgresqlBuildExtension,
|
||||||
|
postgresqlTestExtension,
|
||||||
stdenv,
|
stdenv,
|
||||||
|
|
||||||
enableUnfree ? true,
|
enableUnfree ? true,
|
||||||
@@ -50,7 +51,50 @@ postgresqlBuildExtension (finalAttrs: {
|
|||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
passthru.tests = nixosTests.postgresql.timescaledb.passthru.override postgresql;
|
passthru.tests.extension = postgresqlTestExtension {
|
||||||
|
inherit (finalAttrs) finalPackage;
|
||||||
|
withPackages = [ "timescaledb_toolkit" ];
|
||||||
|
postgresqlExtraSettings = ''
|
||||||
|
shared_preload_libraries='timescaledb,timescaledb_toolkit'
|
||||||
|
'';
|
||||||
|
sql = ''
|
||||||
|
CREATE EXTENSION timescaledb;
|
||||||
|
CREATE EXTENSION timescaledb_toolkit;
|
||||||
|
|
||||||
|
CREATE TABLE sth (
|
||||||
|
time TIMESTAMPTZ NOT NULL,
|
||||||
|
value DOUBLE PRECISION
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT create_hypertable('sth', 'time');
|
||||||
|
|
||||||
|
INSERT INTO sth (time, value) VALUES
|
||||||
|
('2003-04-12 04:05:06 America/New_York', 1.0),
|
||||||
|
('2003-04-12 04:05:07 America/New_York', 2.0),
|
||||||
|
('2003-04-12 04:05:08 America/New_York', 3.0),
|
||||||
|
('2003-04-12 04:05:09 America/New_York', 4.0),
|
||||||
|
('2003-04-12 04:05:10 America/New_York', 5.0)
|
||||||
|
;
|
||||||
|
|
||||||
|
WITH t AS (
|
||||||
|
SELECT
|
||||||
|
time_bucket('1 day'::interval, time) AS dt,
|
||||||
|
stats_agg(value) AS stats
|
||||||
|
FROM sth
|
||||||
|
GROUP BY time_bucket('1 day'::interval, time)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
average(stats)
|
||||||
|
FROM t;
|
||||||
|
'';
|
||||||
|
asserts = [
|
||||||
|
{
|
||||||
|
query = "SELECT count(*) FROM sth";
|
||||||
|
expected = "5";
|
||||||
|
description = "hypertable can be queried successfully.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
|
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
|
||||||
|
|||||||
Reference in New Issue
Block a user