summaryrefslogtreecommitdiff
path: root/gnu/tests
diff options
context:
space:
mode:
authorMarius Bakke <marius@gnu.org>2022-01-29 15:55:29 +0100
committerMarius Bakke <marius@gnu.org>2022-01-29 16:09:03 +0100
commitb6b0cfa2f87ef8d151bf8672c7d711afad71a3e7 (patch)
tree4d20c9adb7f943d969e71f8591eb7c61ca1a96f7 /gnu/tests
parent59847afda785cbfa19a61e4fd062f8c4ea01c912 (diff)
tests: Add system test for TimescaleDB.
* gnu/tests/databases.scm (%timescaledb-os, run-timescaledb-test, %test-timescaledb): New variables.
Diffstat (limited to 'gnu/tests')
-rw-r--r--gnu/tests/databases.scm139
1 files changed, 138 insertions, 1 deletions
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm
index 2374aaba04a..296d91d1185 100644
--- a/gnu/tests/databases.scm
+++ b/gnu/tests/databases.scm
@@ -1,6 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> 2;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
3;;; Copyright © 2020 Marius Bakke <marius@gnu.org> 3;;; Copyright © 2020, 2022 Marius Bakke <marius@gnu.org>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
6;;; 6;;;
@@ -29,10 +29,16 @@
29 #:use-module (gnu packages databases) 29 #:use-module (gnu packages databases)
30 #:use-module (guix gexp) 30 #:use-module (guix gexp)
31 #:use-module (guix store) 31 #:use-module (guix store)
32 #:use-module (srfi srfi-1)
32 #:export (%test-memcached 33 #:export (%test-memcached
33 %test-postgresql 34 %test-postgresql
35 %test-timescaledb
34 %test-mysql)) 36 %test-mysql))
35 37
38;;;
39;;; The Memcached service.
40;;;
41
36(define %memcached-os 42(define %memcached-os
37 (simple-operating-system 43 (simple-operating-system
38 (service dhcp-client-service-type) 44 (service dhcp-client-service-type)
@@ -245,6 +251,137 @@
245 (description "Start the PostgreSQL service.") 251 (description "Start the PostgreSQL service.")
246 (value (run-postgresql-test)))) 252 (value (run-postgresql-test))))
247 253
254;; Test TimescaleDB, a PostgreSQL extension.
255(define %timescaledb-os
256 (let* ((postgresql-services (operating-system-services %postgresql-os))
257 (postgresql-service-configuration
258 (service-value (find (lambda (svc)
259 (eq? (service-kind svc) postgresql-service-type))
260 postgresql-services)))
261 (postgresql-role-service-configuration
262 (service-value (find (lambda (svc)
263 (eq? (service-kind svc)
264 postgresql-role-service-type))
265 postgresql-services))))
266 (simple-operating-system
267 (service postgresql-service-type
268 (postgresql-configuration
269 (inherit postgresql-service-configuration)
270 (extension-packages (list timescaledb))
271 (config-file
272 (postgresql-config-file
273 (inherit (postgresql-configuration-file
274 postgresql-service-configuration))
275 (extra-config
276 (append '(("shared_preload_libraries" "timescaledb"))
277 (postgresql-config-file-extra-config
278 (postgresql-configuration-file
279 postgresql-service-configuration))))))))
280 (service postgresql-role-service-type
281 (postgresql-role-configuration
282 (inherit postgresql-role-service-configuration))))))
283
284(define (run-timescaledb-test)
285 "Run tests in %TIMESCALEDB-OS."
286 (define os
287 (marionette-operating-system
288 %timescaledb-os
289 #:imported-modules '((gnu services herd)
290 (guix combinators))))
291
292 (define vm
293 (virtual-machine
294 (operating-system os)
295 (memory-size 512)))
296
297 (define test
298 (with-imported-modules '((gnu build marionette))
299 #~(begin
300 (use-modules (srfi srfi-64)
301 (gnu build marionette))
302
303 (define marionette
304 (make-marionette (list #$vm)))
305
306 (test-runner-current (system-test-runner #$output))
307 (test-begin "timescaledb")
308
309 (test-assert "PostgreSQL running"
310 (marionette-eval
311 '(begin
312 (use-modules (gnu services herd))
313 (start-service 'postgres))
314 marionette))
315
316 (test-assert "database ready"
317 (begin
318 (marionette-eval
319 '(begin
320 (let loop ((i 10))
321 (unless (or (zero? i)
322 (and (file-exists? #$%role-log-file)
323 (string-contains
324 (call-with-input-file #$%role-log-file
325 get-string-all)
326 ";\nCREATE DATABASE")))
327 (sleep 1)
328 (loop (- i 1)))))
329 marionette)))
330
331 (test-assert "database creation"
332 (marionette-eval
333 '(begin
334 (current-output-port
335 (open-file "/dev/console" "w0"))
336 (invoke #$(file-append postgresql "/bin/psql")
337 "-tA" "-c" "CREATE DATABASE test"))
338 marionette))
339
340 (test-assert "load extension"
341 (marionette-eval
342 '(begin
343 (current-output-port (open-file "/dev/console" "w0"))
344 ;; Capture stderr for the next test.
345 (current-error-port (open-file "timescaledb.stderr" "w0"))
346 (invoke #$(file-append postgresql "/bin/psql")
347 "-tA" "-c" "CREATE EXTENSION timescaledb"
348 "test"))
349 marionette))
350
351 (test-assert "telemetry is disabled"
352 (marionette-eval
353 '(begin
354 (string-contains (call-with-input-file "timescaledb.stderr"
355 (lambda (port)
356 (get-string-all port)))
357 "Please enable telemetry"))
358 marionette))
359
360 (test-assert "create hypertable"
361 (marionette-eval
362 '(begin
363 (current-output-port (open-file "/dev/console" "w0"))
364 (invoke #$(file-append postgresql "/bin/psql")
365 "-tA" "-c" "CREATE TABLE ht (
366time TIMESTAMP NOT NULL,
367data double PRECISION NULL
368)"
369 "test")
370 (invoke #$(file-append postgresql "/bin/psql")
371 "-tA" "-c" "SELECT create_hypertable('ht','time')"
372 "test"))
373 marionette))
374
375 (test-end))))
376
377 (gexp->derivation "timescaledb-test" test))
378
379(define %test-timescaledb
380 (system-test
381 (name "timescaledb")
382 (description "Test the TimescaleDB PostgreSQL extension.")
383 (value (run-timescaledb-test))))
384
248 385
249;;; 386;;;
250;;; The MySQL service. 387;;; The MySQL service.