, simHistory :: [SimCommand]
, simVectorClock :: VectorClock
, simRootDirectory :: FilePath
+ , simFailed :: Bool
}
deriving (Show, Read)
, simHistory = []
, simVectorClock = VectorClock 0
, simRootDirectory = rootdir
+ , simFailed = False
}
-- State that can vary between different repos in the simulation.
| CommandAdd RawFilePath ByteSize [RepoName]
| CommandAddMulti Int String ByteSize ByteSize [RepoName]
| CommandStep Int
+ | CommandStepStable Int
| CommandAction SimAction
| CommandSeed Int
| CommandPresent RepoName RawFilePath
Right $ Right st
| otherwise -> missing
(Just _, Nothing) -> missing
- (Nothing, _) -> Left $ "Expected " ++ fromRawFilePath file
- ++ " to be present in " ++ fromRepoName repo
- ++ ", but the simulation does not include that file."
+ (Nothing, _) -> Right $ Left $ do
+ showLongNote $ UnquotedString $
+ "Expected " ++ fromRawFilePath file
+ ++ " to be present in " ++ fromRepoName repo
+ ++ ", but the simulation does not include that file."
+ return $ st { simFailed = True }
where
- missing = Left $ "Expected " ++ fromRawFilePath file
- ++ " to be present in "
- ++ fromRepoName repo ++ ", but it is not."
+ missing = Right $ Left $ do
+ showLongNote $ UnquotedString $
+ "Expected " ++ fromRawFilePath file
+ ++ " to be present in "
+ ++ fromRepoName repo ++ ", but it is not."
+ return $ st { simFailed = True }
applySimCommand (CommandNotPresent repo file) st _ = checkKnownRepo repo st $ \u ->
case (M.lookup file (simFiles st), M.lookup u (simRepoState st)) of
(Just k, Just rst)
Right $ Right st
| otherwise -> present
(Just _, Nothing) -> present
- (Nothing, _) -> Left $ "Expected " ++ fromRawFilePath file
- ++ " to not be present in " ++ fromRepoName repo
- ++ ", but the simulation does not include that file."
+ (Nothing, _) -> Right $ Left $ do
+ showLongNote $ UnquotedString $
+ "Expected " ++ fromRawFilePath file
+ ++ " to not be present in " ++ fromRepoName repo
+ ++ ", but the simulation does not include that file."
+ return $ st { simFailed = True }
where
- present = Left $ "Expected " ++ fromRawFilePath file
- ++ " not to be present in "
- ++ fromRepoName repo ++ ", but it is present."
+ present = Right $ Left $ do
+ showLongNote $ UnquotedString $
+ "Expected " ++ fromRawFilePath file
+ ++ " not to be present in "
+ ++ fromRepoName repo ++ ", but it is present."
+ return $ st { simFailed = True }
applySimCommand c@(CommandVisit repo cmdparams) st _ =
checkKnownRepo repo st $ \u -> Right $ Left $ do
st' <- liftIO $ updateSimRepos st
n' -> applySimCommand' (CommandAddMulti n' suffix minsz maxsz repos) st'' repobyname
Right (Left _) -> error "applySimCommand' CommandAddMulti"
applySimCommand' (CommandStep n) st _ =
- Right $ Left $ handleStep n n st
+ Right $ Left $ handleStep False n n st
+applySimCommand' (CommandStepStable n) st _ =
+ Right $ Left $ handleStep True n n st
applySimCommand' (CommandAction act) st _ =
case getSimActionComponents act st of
Left err -> Left err
applySimCommand' (CommandPresent _ _) _ _ = error "applySimCommand' CommandPresent"
applySimCommand' (CommandNotPresent _ _) _ _ = error "applySimCommand' CommandNotPresent"
-handleStep :: Int -> Int -> SimState SimRepo -> Annex (SimState SimRepo)
-handleStep startn n st
+handleStep :: Bool -> Int -> Int -> SimState SimRepo -> Annex (SimState SimRepo)
+handleStep muststabilize startn n st
| n > 0 = do
let (st', actions) = getactions unsyncactions st
(st'', restactions) <- runoneaction actions st'
return st''''
else runrest restactions' st'''' (pred n)
else runrest restactions st'' (pred n)
- | otherwise = return st
+ | otherwise = checkstabalized st
where
runrest actions st' n'
| n' > 0 = do
(st'', restactions) <- runoneaction actions st'
if null restactions
- then handleStep startn n' st'
+ then handleStep muststabilize startn n' st'
else runrest restactions st'' (pred n')
+ | otherwise = checkstabalized st'
+
+ checkstabalized st'
+ | muststabilize = do
+ showLongNote $ UnquotedString $
+ "Simulation failed to stabilize after "
+ ++ show startn ++ " steps."
+ return $ st' { simFailed = True }
| otherwise = return st'
unsyncactions =
(["addmulti", show n, suffix, showsize minsz, showsize maxsz] ++ map fromRepoName repos) : go rest
go (CommandStep n : rest) =
["step", show n] : go rest
+ go (CommandStepStable n : rest) =
+ ["stepstable", show n] : go rest
go (CommandAction act : rest) = formatAction act : go rest
go (CommandSeed n : rest) =
["seed", show n] : go rest
case readMaybe n of
Just n' -> Right $ CommandStep n'
Nothing -> Left $ "Unable to parse step value \"" ++ n ++ "\""
+parseSimCommand ("stepstable":n:[]) =
+ case readMaybe n of
+ Just n' -> Right $ CommandStepStable n'
+ Nothing -> Left $ "Unable to parse step value \"" ++ n ++ "\""
parseSimCommand l@("action":_) = case parseSimAction l of
Right act -> Right $ CommandAction act
Left err -> Left err