diff options
author | Christopher Baines <mail@cbaines.net> | 2021-02-03 09:14:43 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-02-03 09:57:35 +0000 |
commit | e740cc614096e768813280c718f9e96343ba41b3 (patch) | |
tree | 25ade70a5d408be80f62f19c6511172aab7dcce5 /gnu/tests/databases.scm | |
parent | 1b9186828867e77af1f2ee6741063424f8256398 (diff) | |
parent | 63cf277bfacf282d2b19f00553745b2a9370eca0 (diff) |
Merge branch 'master' into core-updates
Diffstat (limited to 'gnu/tests/databases.scm')
-rw-r--r-- | gnu/tests/databases.scm | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index 31d5ae4c6a..e831d69f5a 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm @@ -214,11 +214,31 @@ ;;; The PostgreSQL service. ;;; +(define %postgresql-log-directory + "/var/log/postgresql") + +(define %role-log-file + "/var/log/postgresql_roles.log") + (define %postgresql-os (simple-operating-system (service postgresql-service-type (postgresql-configuration - (postgresql postgresql-10))))) + (postgresql postgresql-10) + (config-file + (postgresql-config-file + (extra-config + '(("session_preload_libraries" "auto_explain") + ("random_page_cost" 2) + ("auto_explain.log_min_duration" "100 ms") + ("work_mem" "500 MB") + ("debug_print_plan" #t))))))) + (service postgresql-role-service-type + (postgresql-role-configuration + (roles + (list (postgresql-role + (name "root") + (create-database? #t)))))))) (define (run-postgresql-test) "Run tests in %POSTGRESQL-OS." @@ -254,6 +274,56 @@ (start-service 'postgres)) marionette)) + (test-assert "log-file" + (marionette-eval + '(begin + (use-modules (ice-9 ftw) + (ice-9 match)) + (current-output-port + (open-file "/dev/console" "w0")) + (let ((server-log-file + (string-append #$%postgresql-log-directory + "/pg_ctl.log"))) + (and (file-exists? server-log-file) + (display + (call-with-input-file server-log-file + get-string-all))) + #t)) + 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 + (use-modules (gnu services herd) + (ice-9 popen)) + (current-output-port + (open-file "/dev/console" "w0")) + (let* ((port (open-pipe* + OPEN_READ + #$(file-append postgresql "/bin/psql") + "-tAh" "/var/run/postgresql" + "-c" "SELECT 1 FROM pg_database WHERE + datname='root'")) + (output (get-string-all port))) + (close-pipe port) + (string-contains output "1"))) + marionette)) + (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) |