summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2015-07-17 09:12:03 -0400
committerRobert Haas <rhaas@postgresql.org>2015-07-17 09:12:03 -0400
commita04bb65f70dafdf462e0478ad19e6de56df89bfc (patch)
treef2095d72b0851f23d12ab03dc9f243c50dcd889a /src/test
parent43d89a23d59c487bc9258fad7a6187864cb8c0c0 (diff)
Add new function pg_notification_queue_usage.
This tells you what fraction of NOTIFY's queue is currently filled. Brendan Jurd, reviewed by Merlin Moncure and Gurjeet Singh. A few further tweaks by me.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/isolation/expected/async-notify.out17
-rw-r--r--src/test/isolation/specs/async-notify.spec14
-rw-r--r--src/test/regress/expected/async.out8
-rw-r--r--src/test/regress/sql/async.sql4
4 files changed, 43 insertions, 0 deletions
diff --git a/src/test/isolation/expected/async-notify.out b/src/test/isolation/expected/async-notify.out
new file mode 100644
index 00000000000..92d281a7d1f
--- /dev/null
+++ b/src/test/isolation/expected/async-notify.out
@@ -0,0 +1,17 @@
+Parsed test spec with 2 sessions
+
+starting permutation: listen begin check notify check
+step listen: LISTEN a;
+step begin: BEGIN;
+step check: SELECT pg_notification_queue_usage() > 0 AS nonzero;
+nonzero
+
+f
+step notify: SELECT count(pg_notify('a', s::text)) FROM generate_series(1, 1000) s;
+count
+
+1000
+step check: SELECT pg_notification_queue_usage() > 0 AS nonzero;
+nonzero
+
+t
diff --git a/src/test/isolation/specs/async-notify.spec b/src/test/isolation/specs/async-notify.spec
new file mode 100644
index 00000000000..7f451b18a15
--- /dev/null
+++ b/src/test/isolation/specs/async-notify.spec
@@ -0,0 +1,14 @@
+# Verify that pg_notification_queue_usage correctly reports a non-zero result,
+# after submitting notifications while another connection is listening for
+# those notifications and waiting inside an active transaction.
+
+session "listener"
+step "listen" { LISTEN a; }
+step "begin" { BEGIN; }
+teardown { ROLLBACK; }
+
+session "notifier"
+step "check" { SELECT pg_notification_queue_usage() > 0 AS nonzero; }
+step "notify" { SELECT count(pg_notify('a', s::text)) FROM generate_series(1, 1000) s; }
+
+permutation "listen" "begin" "check" "notify" "check"
diff --git a/src/test/regress/expected/async.out b/src/test/regress/expected/async.out
index ae0d5df3b78..19cbe38e636 100644
--- a/src/test/regress/expected/async.out
+++ b/src/test/regress/expected/async.out
@@ -32,3 +32,11 @@ NOTIFY notify_async2;
LISTEN notify_async2;
UNLISTEN notify_async2;
UNLISTEN *;
+-- Should return zero while there are no pending notifications.
+-- src/test/isolation/specs/async-notify.spec tests for actual usage.
+SELECT pg_notification_queue_usage();
+ pg_notification_queue_usage
+-----------------------------
+ 0
+(1 row)
+
diff --git a/src/test/regress/sql/async.sql b/src/test/regress/sql/async.sql
index af3a904e0f5..40f6e015387 100644
--- a/src/test/regress/sql/async.sql
+++ b/src/test/regress/sql/async.sql
@@ -17,3 +17,7 @@ NOTIFY notify_async2;
LISTEN notify_async2;
UNLISTEN notify_async2;
UNLISTEN *;
+
+-- Should return zero while there are no pending notifications.
+-- src/test/isolation/specs/async-notify.spec tests for actual usage.
+SELECT pg_notification_queue_usage();