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 -> Test
18testNotify TestEnv{..} =
20 withConn $ \conn2 -> do
21 execute_ conn "LISTEN foo"
22 execute_ conn "LISTEN bar"
24 results_mv <- newEmptyMVar
25 forkIO $ replicateM 2 (getNotification conn)
26 >>= putMVar results_mv
30 execute_ conn2 "NOTIFY foo"
31 execute_ conn2 "NOTIFY bar"
33 [n1, n2] <- sortBy (compare `on` notificationChannel)
34 <$> takeMVar results_mv
36 assertEqual "n1" "bar" (notificationChannel n1)
37 assertEqual "n2" "foo" (notificationChannel n2)
39 -- Other sanity checks
40 assertEqual "Server PIDs match" (notificationPid n1) (notificationPid n2)
41 assertBool "notificationData is empty" $
42 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