Debian Codegraph @

src/test/isolation/specs/async-notify.spec

raw
1 # Tests for LISTEN/NOTIFY
2
3 # Most of these tests use only the "notifier" session and hence exercise only
4 # self-notifies, which are convenient because they minimize timing concerns.
5 # Note we assume that each step is delivered to the backend as a single Query
6 # message so it will run as one transaction.
7
8 session notifier
9 step listenc { LISTEN c1; LISTEN c2; }
10 step notify1 { NOTIFY c1; }
11 step notify2 { NOTIFY c2, 'payload'; }
12 step notify3 { NOTIFY c3, 'payload3'; } # not listening to c3
13 step notifyf { SELECT pg_notify('c2', NULL); }
14 step notifyd1 { NOTIFY c2, 'payload'; NOTIFY c1; NOTIFY "c2", 'payload'; }
15 step notifyd2 { NOTIFY c1; NOTIFY c1; NOTIFY c1, 'p1'; NOTIFY c1, 'p2'; }
16 step notifys1 {
17 BEGIN;
18 NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
19 NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
20 SAVEPOINT s1;
21 NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
22 NOTIFY c1, 'payloads'; NOTIFY "c2", 'payloads';
23 NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
24 NOTIFY c1, 'payloads'; NOTIFY "c2", 'payloads';
25 RELEASE SAVEPOINT s1;
26 SAVEPOINT s2;
27 NOTIFY c1, 'rpayload'; NOTIFY "c2", 'rpayload';
28 NOTIFY c1, 'rpayloads'; NOTIFY "c2", 'rpayloads';
29 NOTIFY c1, 'rpayload'; NOTIFY "c2", 'rpayload';
30 NOTIFY c1, 'rpayloads'; NOTIFY "c2", 'rpayloads';
31 ROLLBACK TO SAVEPOINT s2;
32 COMMIT;
33 }
34 step usage { SELECT pg_notification_queue_usage() > 0 AS nonzero; }
35 step bignotify { SELECT count(pg_notify('c1', s::text)) FROM generate_series(1, 1000) s; }
36 teardown { UNLISTEN *; }
37
38 # The listener session is used for cross-backend notify checks.
39
40 session listener
41 step llisten { LISTEN c1; LISTEN c2; }
42 step lcheck { SELECT 1 AS x; }
43 step lbegin { BEGIN; }
44 step lbegins { BEGIN ISOLATION LEVEL SERIALIZABLE; }
45 step lcommit { COMMIT; }
46 teardown { UNLISTEN *; }
47
48 # In some tests we need a second listener, just to block the queue.
49
50 session listener2
51 step l2listen { LISTEN c1; }
52 step l2begin { BEGIN; }
53 step l2commit { COMMIT; }
54 step l2stop { UNLISTEN *; }
55
56
57 # Trivial cases.
58 permutation listenc notify1 notify2 notify3 notifyf
59
60 # Check simple and less-simple deduplication.
61 permutation listenc notifyd1 notifyd2 notifys1
62
63 # Cross-backend notification delivery. We use a "select 1" to force the
64 # listener session to check for notifies. In principle we could just wait
65 # for delivery, but that would require extra support in isolationtester
66 # and might have portability-of-timing issues.
67 permutation llisten notify1 notify2 notify3 notifyf lcheck
68
69 # Again, with local delivery too.
70 permutation listenc llisten notify1 notify2 notify3 notifyf lcheck
71
72 # Check for bug when initial listen is only action in a serializable xact,
73 # and notify queue is not empty
74 permutation l2listen l2begin notify1 lbegins llisten lcommit l2commit l2stop
75
76 # Verify that pg_notification_queue_usage correctly reports a non-zero result,
77 # after submitting notifications while another connection is listening for
78 # those notifications and waiting inside an active transaction. We have to
79 # fill a page of the notify SLRU to make this happen, which is a good deal
80 # of traffic. To not bloat the expected output, we intentionally don't
81 # commit the listener's transaction, so that it never reports these events.
82 # Hence, this should be the last test in this script.
83
84 permutation llisten lbegin usage bignotify usage