Skip to content

Commit 3e9c0c6

Browse files
committed
Add a test for session expiration
1 parent b8534be commit 3e9c0c6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

test/Spec.hs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
module Main where
33

4+
import Control.Concurrent (threadDelay)
45
import Control.Exception.Base (assert)
56
import Control.Monad
67
import Data.Default (def)
@@ -17,8 +18,8 @@ main :: IO ()
1718
main = do
1819
conn <- dbconnect
1920
conn' <- fromSimpleConnection conn
20-
store <- dbStore conn' def
21-
purger conn' def
21+
store <- dbStore conn' testSettings
22+
purger conn' testSettings
2223

2324
((lookupSess1, insertSess1), mknewsessid) <- store Nothing
2425
sessid <- mknewsessid
@@ -46,9 +47,18 @@ main = do
4647
assert (newsessid2 /= newsessid) it
4748
assert (newsessid2 /= invalidsessid) it
4849

49-
l3 <- lookupSess3 "foo"
50-
assert (l3 == Nothing) it
50+
l4 <- lookupSess3 "foo"
51+
assert (l4 == Nothing) it
5152

53+
((lookupSess4, insertSess4), mknewsessid) <- store $ Just sessid
54+
l5 <- lookupSess4 "foo"
55+
assert (l5 == (Just "bar")) it
56+
57+
threadDelay 6000000
58+
59+
((lookupSess5, insertSess5), mknewsessid) <- store $ Just sessid
60+
l6 <- lookupSess5 "foo"
61+
assert (l6 == Nothing) it
5262

5363
it :: IO ()
5464
it = return ()
@@ -62,3 +72,6 @@ dbconnect = do
6272
, connectPassword = "omed"
6373
, connectDatabase = "demodb" }
6474
connectPostgreSQL $ postgreSQLConnectionString connectInfo
75+
76+
testSettings :: StoreSettings
77+
testSettings = def { storeSettingsSessionTimeout=5 }

0 commit comments

Comments
 (0)