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:
parent
172c3c01c4
commit
83faccf3f9
@ -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
|
||||
|
||||
@ -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 ()))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user