On Wed, Apr 9, 2014 at 9:06 PM, Klaus Aehlig <[email protected]> wrote:

> The internal representation of the lock waiting structure contains
> some arbitrariness---pending requests are arbitrarily keyed by one
> of the lock owners that blocks them. Therefore, LockWaiting is not
> an instance of Eq. To allow some meaningful form of comparison
> nevertheless (in particular for testing), provide some representation
> of LockWaiting where equality on the representation is observable
> equivalence.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  src/Ganeti/Locking/Waiting.hs | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/src/Ganeti/Locking/Waiting.hs b/src/Ganeti/Locking/Waiting.hs
> index 2f99fe8..d0f60a8 100644
> --- a/src/Ganeti/Locking/Waiting.hs
> +++ b/src/Ganeti/Locking/Waiting.hs
> @@ -33,8 +33,10 @@ module Ganeti.Locking.Waiting
>   , removePendingRequest
>   , releaseResources
>   , getPendingRequests
> + , extRepr
>   ) where
>
> +import Control.Arrow ((&&&))
>  import qualified Data.Map as M
>  import Data.Maybe (fromMaybe)
>  import qualified Data.Set as S
> @@ -99,6 +101,14 @@ getPendingRequests :: (Ord a, Ord b, Ord c)
>                     => LockWaiting a b c -> S.Set (c, b, [L.LockRequest a])
>  getPendingRequests = S.unions . M.elems . lwPending
>
> +-- | Get a representation, comparable by (==), that captures the
> extensional
> +-- behaviour. In other words, @uncurry (==) . (extRepr &&& extRepr)@ is a

+-- bisumlation.
>

I'm not familiar with the term bisumlation, but didn't you mean `***`
instead of `&&&`? Or perhaps `on (==) extRepr`?


> +extRepr :: (Ord a, Ord b, Ord c)
> +        => LockWaiting a b c
> +        -> (L.LockAllocation a b, S.Set (c, b, [L.LockRequest a]))
> +extRepr = getAllocation &&& getPendingRequests
> +
>  -- | Internal function to fulfill one request if possible, and keep track
> of
>  -- the owners to be notified. The type is chosen to be suitable as fold
>  -- operation.
> --
> 1.9.1.423.g4596e3a
>
>
LGTM

Reply via email to