before switch to ncq3

This commit is contained in:
voidlizard 2025-08-22 13:40:58 +03:00
parent 7a357dd8c4
commit 051fe680be
2 changed files with 31 additions and 20 deletions

View File

@ -36,6 +36,18 @@ ncqStorageStop NCQStorage{..} = do
atomically $ writeTVar ncqStopReq True atomically $ writeTVar ncqStopReq True
ncqRemoveGarbage :: forall m. MonadIO m
=> NCQStorage
-> m ()
ncqRemoveGarbage me = do
let wd = ncqGetWorkDir me
let garb x = List.isSuffixOf ".part" x
|| List.isSuffixOf ".cq$" x
|| List.isSuffixOf ".merge" x
dirFiles wd <&> filter garb >>= mapM_ rm
ncqTryLoadState :: forall m. MonadUnliftIO m ncqTryLoadState :: forall m. MonadUnliftIO m
=> NCQStorage => NCQStorage
-> m () -> m ()
@ -156,6 +168,8 @@ ncqStorageRun ncq@NCQStorage{..} = withSem ncqRunSem $ flip runContT pure do
ContT $ bracket none $ const $ liftIO do ContT $ bracket none $ const $ liftIO do
debug "storage done" debug "storage done"
ncqRemoveGarbage ncq
liftIO (ncqTryLoadState ncq) liftIO (ncqTryLoadState ncq)
closeQ <- liftIO newTQueueIO closeQ <- liftIO newTQueueIO

View File

@ -163,7 +163,7 @@ validateTestResult logFile = do
entry $ bindMatch "has-seed-block-result" $ nil_ \case entry $ bindMatch "has-seed-block-result" $ nil_ \case
[ HashLike _, LitIntVal _ ] -> none [ HashLike _, LitIntVal _ ] -> none
[ HashLike h] -> err $ red "missed seed block" <+> pretty h [ HashLike h] -> err $ red "missed seed block (2)" <+> pretty h
_ -> none _ -> none
-- has-block-result -- has-block-result
@ -374,33 +374,30 @@ ncq3EnduranceTest = do
for_ seeds $ \(h,_,_) -> do for_ seeds $ \(h,_,_) -> do
here <- hasBlock (AnyStorage sto) (coerce h) here <- hasBlock (AnyStorage sto) (coerce h)
unless (isJust here) do unless (isJust here) do
err $ "missed seed block" <+> pretty h err $ "missed seed block (1)" <+> pretty h
fix \recover -> handle (\(e :: IOException) -> err (viaShow e) >> pause @'Seconds 1 >> recover) do let handler e = err (viaShow e) >> debug "RECOVERING" >> pause @'Seconds 3
fix \recover -> handleAny (\e -> handler e >> recover) do
flip runContT pure do flip runContT pure do
p <- startProcess conf -- ContT $ withProcessWait conf p <- startProcess conf -- ContT $ withProcessWait conf
storms <- newTQueueIO storms <- newTQueueIO
let inp = getStdin p let inp = getStdin p
let outp = getStdout p
let logFile = testEnvDir </> "op.log" let logFile = testEnvDir </> "op.log"
pread <- ContT $ withAsync $ fix \loop -> do pread <- ContT $ withAsync $ flip runContT pure $ callCC \stop -> do
liftIO (try @_ @IOException (IO.hGetLine outp)) >>= \case let outp = getStdout p
Left e | isEOFError e -> none fix \loop -> do
Left e -> err (viaShow e) >> throwIO e s <- liftIO (try @_ @IOException (IO.hGetLine outp)) >>= \case
Right s -> do Left e -> err (red "pread:" <+> viaShow e) >> stop ()
Right s -> pure s
liftIO do liftIO do
appendFile logFile (s <> "\n") appendFile logFile (s <> "\n")
void $ try @_ @SomeException (parseTop s & either (err.viaShow) (void . run d)) void $ try @_ @SomeException (parseTop s & either (err.viaShow) (void . run d))
putStrLn s putStrLn s
loop loop
link pread
ContT $ withAsync $ forever do ContT $ withAsync $ forever do
join $ atomically (readTQueue storms) join $ atomically (readTQueue storms)
@ -506,8 +503,8 @@ ncq3EnduranceTest = do
debug $ red "KILL" <+> viaShow pid debug $ red "KILL" <+> viaShow pid
cancel pread cancel pread
hFlush inp hFlush inp
hClose outp liftIO $ appendFile logFile "; killed"
pause @'Seconds 0.1 pause @'Seconds 0.25
void $ runProcess (proc "kill" ["-9", show pid]) void $ runProcess (proc "kill" ["-9", show pid])
notice $ red "Killed" <+> viaShow pid notice $ red "Killed" <+> viaShow pid
atomically $ modifyTVar killed succ atomically $ modifyTVar killed succ