1module Notify (testNotify) where
5import Control.Applicative
6import Control.Concurrent
10import Database.PostgreSQL.Simple.Notification
12import qualified Data.ByteString as B
14-- TODO: Test with payload, but only for PostgreSQL >= 9.0
15-- (when that feature was introduced).
17testNotify :: TestEnv -> Assertion
18testNotify TestEnv{..} =
19 withConn $ \conn2 -> do
20 execute_ conn "LISTEN foo"
21 execute_ conn "LISTEN bar"
23 results_mv <- newEmptyMVar
24 forkIO $ replicateM 2 (getNotification conn)
25 >>= putMVar results_mv
29 execute_ conn2 "NOTIFY foo"
30 execute_ conn2 "NOTIFY bar"
32 [n1, n2] <- sortBy (compare `on` notificationChannel)
33 <$> takeMVar results_mv
35 assertEqual "n1" "bar" (notificationChannel n1)
36 assertEqual "n2" "foo" (notificationChannel n2)
38 -- Other sanity checks
39 assertEqual "Server PIDs match" (notificationPid n1) (notificationPid n2)
40 assertBool "notificationData is empty" $
41 all (B.null . notificationData) [n1, n2]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list