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.
This commit is contained in:
Felipe Lessa 2015-05-28 02:03:12 -03:00
parent 172c3c01c4
commit 83faccf3f9
2 changed files with 2 additions and 2 deletions

View File

@ -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

View File

@ -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 ()))