From 83faccf3f9ab367a0c138960633bd6ee64af62d1 Mon Sep 17 00:00:00 2001 From: Felipe Lessa Date: Thu, 28 May 2015 02:03:12 -0300 Subject: [PATCH] Use insertLookupWithKey when needing old value. updateLookupWithKey returns original value only if it was deleted. If it was updated, it returns the updated value. On both acid-state and MockStorage we want the old value, though. Now all acid-state tests are green once more. MockStorage tests were already green because MockStorage does not mantain a cached mapping of auth IDs to session IDs. --- .../src/Web/ServerSession/Backend/Acid/Internal.hs | 2 +- serversession/tests/Main.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/serversession-backend-acid-state/src/Web/ServerSession/Backend/Acid/Internal.hs b/serversession-backend-acid-state/src/Web/ServerSession/Backend/Acid/Internal.hs index 12ae658..81df8a1 100644 --- a/serversession-backend-acid-state/src/Web/ServerSession/Backend/Acid/Internal.hs +++ b/serversession-backend-acid-state/src/Web/ServerSession/Backend/Acid/Internal.hs @@ -139,7 +139,7 @@ replaceSession :: SS.Session -> Update ServerSessionAcidState () replaceSession session = do -- Check that the old session exists while replacing it. ServerSessionAcidState sits aits <- get - let (moldSession, sits') = M.updateLookupWithKey (\_ _ -> Just session) sid sits + let (moldSession, sits') = M.insertLookupWithKey (\_ v _ -> v) sid session sits sid = SS.sessionKey session case moldSession of Nothing -> E.throw $ SS.SessionDoesNotExist session diff --git a/serversession/tests/Main.hs b/serversession/tests/Main.hs index 095647b..789d925 100644 --- a/serversession/tests/Main.hs +++ b/serversession/tests/Main.hs @@ -307,7 +307,7 @@ instance Storage MockStorage where replaceSession sto session = join $ I.atomicModifyIORef' (mockSessions sto) $ \oldMap -> let (moldVal, newMap) = - M.updateLookupWithKey (\_ _ -> Just session) (sessionKey session) oldMap + M.insertLookupWithKey (\_ v _ -> v) (sessionKey session) session oldMap in maybe (oldMap, E.throwIO $ SessionDoesNotExist session) (const (newMap, return ()))