diff options
author | Marius Bakke <marius@gnu.org> | 2022-01-29 15:55:29 +0100 |
---|---|---|
committer | Marius Bakke <marius@gnu.org> | 2022-01-29 16:09:03 +0100 |
commit | b6b0cfa2f87ef8d151bf8672c7d711afad71a3e7 (patch) | |
tree | 4d20c9adb7f943d969e71f8591eb7c61ca1a96f7 /gnu | |
parent | 59847afda785cbfa19a61e4fd062f8c4ea01c912 (diff) | |
download | guix-b6b0cfa2f87ef8d151bf8672c7d711afad71a3e7.tar.gz guix-b6b0cfa2f87ef8d151bf8672c7d711afad71a3e7.zip |
tests: Add system test for TimescaleDB.
* gnu/tests/databases.scm (%timescaledb-os, run-timescaledb-test,
%test-timescaledb): New variables.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/tests/databases.scm | 139 |
1 files changed, 138 insertions, 1 deletions
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index 2374aaba04..296d91d118 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> -;;; Copyright © 2020 Marius Bakke <marius@gnu.org> +;;; Copyright © 2020, 2022 Marius Bakke <marius@gnu.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -29,10 +29,16 @@ #:use-module (gnu packages databases) #:use-module (guix gexp) #:use-module (guix store) + #:use-module (srfi srfi-1) #:export (%test-memcached %test-postgresql + %test-timescaledb %test-mysql)) +;;; +;;; The Memcached service. +;;; + (define %memcached-os (simple-operating-system (service dhcp-client-service-type) @@ -245,6 +251,137 @@ (description "Start the PostgreSQL service.") (value (run-postgresql-test)))) +;; Test TimescaleDB, a PostgreSQL extension. +(define %timescaledb-os + (let* ((postgresql-services (operating-system-services %postgresql-os)) + (postgresql-service-configuration + (service-value (find (lambda (svc) + (eq? (service-kind svc) postgresql-service-type)) + postgresql-services))) + (postgresql-role-service-configuration + (service-value (find (lambda (svc) + (eq? (service-kind svc) + postgresql-role-service-type)) + postgresql-services)))) + (simple-operating-system + (service postgresql-service-type + (postgresql-configuration + (inherit postgresql-service-configuration) + (extension-packages (list timescaledb)) + (config-file + (postgresql-config-file + (inherit (postgresql-configuration-file + postgresql-service-configuration)) + (extra-config + (append '(("shared_preload_libraries" "timescaledb")) + (postgresql-config-file-extra-config + (postgresql-configuration-file + postgresql-service-configuration)))))))) + (service postgresql-role-service-type + (postgresql-role-configuration + (inherit postgresql-role-service-configuration)))))) + +(define (run-timescaledb-test) + "Run tests in %TIMESCALEDB-OS." + (define os + (marionette-operating-system + %timescaledb-os + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define vm + (virtual-machine + (operating-system os) + (memory-size 512))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-64) + (gnu build marionette)) + + (define marionette + (make-marionette (list #$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "timescaledb") + + (test-assert "PostgreSQL running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'postgres)) + marionette)) + + (test-assert "database ready" + (begin + (marionette-eval + '(begin + (let loop ((i 10)) + (unless (or (zero? i) + (and (file-exists? #$%role-log-file) + (string-contains + (call-with-input-file #$%role-log-file + get-string-all) + ";\nCREATE DATABASE"))) + (sleep 1) + (loop (- i 1))))) + marionette))) + + (test-assert "database creation" + (marionette-eval + '(begin + (current-output-port + (open-file "/dev/console" "w0")) + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "CREATE DATABASE test")) + marionette)) + + (test-assert "load extension" + (marionette-eval + '(begin + (current-output-port (open-file "/dev/console" "w0")) + ;; Capture stderr for the next test. + (current-error-port (open-file "timescaledb.stderr" "w0")) + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "CREATE EXTENSION timescaledb" + "test")) + marionette)) + + (test-assert "telemetry is disabled" + (marionette-eval + '(begin + (string-contains (call-with-input-file "timescaledb.stderr" + (lambda (port) + (get-string-all port))) + "Please enable telemetry")) + marionette)) + + (test-assert "create hypertable" + (marionette-eval + '(begin + (current-output-port (open-file "/dev/console" "w0")) + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "CREATE TABLE ht ( +time TIMESTAMP NOT NULL, +data double PRECISION NULL +)" + "test") + (invoke #$(file-append postgresql "/bin/psql") + "-tA" "-c" "SELECT create_hypertable('ht','time')" + "test")) + marionette)) + + (test-end)))) + + (gexp->derivation "timescaledb-test" test)) + +(define %test-timescaledb + (system-test + (name "timescaledb") + (description "Test the TimescaleDB PostgreSQL extension.") + (value (run-timescaledb-test)))) + ;;; ;;; The MySQL service. |