summaryrefslogtreecommitdiffstats
path: root/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test.lua')
-rwxr-xr-xtest.lua48
1 files changed, 45 insertions, 3 deletions
diff --git a/test.lua b/test.lua
index 03658d8..80f774f 100755
--- a/test.lua
+++ b/test.lua
@@ -60,15 +60,17 @@ end
local utils = require 'lem.utils'
local postgres = require 'lem.postgres'
-local db = assert(postgres.connect([[
+local dbconnstr = [[
host=localhost
user=myuser
password=mypasswd
dbname=mydb
-]]))
+]]
+
+local db = assert(postgres.connect(dbconnstr))
assert(db:exec(
-'CREATE TABLE mytable (id serial PRIMARY KEY, name TEXT, foo integer)'))
+'CREATE TEMPORARY TABLE mytable (id serial PRIMARY KEY, name TEXT, foo integer)'))
assert(db:exec("COPY mytable (name, foo) FROM STDIN (delimiter ',')"))
assert(db:put('alpha,1\n'))
@@ -107,6 +109,46 @@ end
assert(db:exec('DROP TABLE mytable'))
+assert(db:exec('LISTEN mytest;'))
+
+assert(db:exec('NOTIFY mytest;'))
+assert(db:exec("NOTIFY mytest, 'foo';"))
+
+db:set_notifier(function(ev, payload, pid)
+ print('notification', ev, payload, pid)
+end)
+
+assert(db:exec('SELECT pg_notify($1, $2);', 'mytest', 'bar'))
+assert(db:exec('SELECT pg_notify($1, $2), pg_notify($1, $3);', 'mytest', 'foo', 'bar'))
+
+db:set_notifier(function(ev, payload, pid)
+ print('\nnotification', ev, payload, pid)
+end)
+
+utils.spawn(function()
+ local sleeper = utils.newsleeper()
+ for i=1,19 do
+ sleeper:sleep(0.20)
+ io.write('.')
+ end
+ print('')
+end)
+
+
+utils.spawn(function()
+ local sleeper = utils.newsleeper()
+ local db2 = assert(postgres.connect(dbconnstr))
+ for i=1,3 do
+ sleeper:sleep(1)
+ assert(db2:exec("NOTIFY mytest, 'foo from secondary connection';"))
+ end
+end)
+
+local sleeper = utils.newsleeper()
+print('\ngoing to sleep')
+sleeper:sleep(4)
+print('awake again\n')
+
print("Exiting " .. arg[0])
-- vim: syntax=lua ts=2 sw=2 noet: