:clown-face: fixed a test
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE InstanceSigs #-}
|
||||||
module SPC
|
module SPC
|
||||||
( -- * SPC startup
|
( -- * SPC startup
|
||||||
SPC,
|
SPC,
|
||||||
@ -93,7 +94,7 @@ type WorkerName = String
|
|||||||
|
|
||||||
-- | Messages sent to workers. These are sent both by SPC and by
|
-- | Messages sent to workers. These are sent both by SPC and by
|
||||||
-- processes spawned by the workes.
|
-- processes spawned by the workes.
|
||||||
data WorkerMsg
|
data WorkerMsg
|
||||||
= -- | New job time
|
= -- | New job time
|
||||||
MsgStartJob SPC (IO ()) JobId
|
MsgStartJob SPC (IO ()) JobId
|
||||||
|
|
||||||
@ -129,7 +130,6 @@ data SPCState = SPCState
|
|||||||
spcJobsDone :: [(JobId, JobDoneReason)],
|
spcJobsDone :: [(JobId, JobDoneReason)],
|
||||||
spcJobCounter :: JobId,
|
spcJobCounter :: JobId,
|
||||||
spcWorkers :: [(WorkerName, Worker)]
|
spcWorkers :: [(WorkerName, Worker)]
|
||||||
-- TODO: you will need to add more fields.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | The monad in which the main SPC thread runs. This is a state
|
-- | The monad in which the main SPC thread runs. This is a state
|
||||||
@ -137,6 +137,7 @@ data SPCState = SPCState
|
|||||||
newtype SPCM a = SPCM (SPCState -> IO (a, SPCState))
|
newtype SPCM a = SPCM (SPCState -> IO (a, SPCState))
|
||||||
|
|
||||||
instance Functor SPCM where
|
instance Functor SPCM where
|
||||||
|
fmap :: (a -> b) -> SPCM a -> SPCM b
|
||||||
fmap = liftM
|
fmap = liftM
|
||||||
|
|
||||||
instance Applicative SPCM where
|
instance Applicative SPCM where
|
||||||
@ -213,7 +214,7 @@ handleMsg c = do
|
|||||||
Just _ -> True
|
Just _ -> True
|
||||||
_ -> False
|
_ -> False
|
||||||
MsgAddWorker name worker -> do
|
MsgAddWorker name worker -> do
|
||||||
state <- get
|
state <- get
|
||||||
put $
|
put $
|
||||||
state
|
state
|
||||||
{ spcWorkers =
|
{ spcWorkers =
|
||||||
@ -230,12 +231,14 @@ handleMsg c = do
|
|||||||
spcJobsDone =
|
spcJobsDone =
|
||||||
(jobid, Done) : spcJobsDone state
|
(jobid, Done) : spcJobsDone state
|
||||||
}
|
}
|
||||||
|
Nothing -> pure ()
|
||||||
|
_ -> pure ()
|
||||||
|
|
||||||
deleteJob :: JobId -> [(JobId, (Job, Worker))] -> [(JobId, (Job, Worker))]
|
deleteJob :: JobId -> [(JobId, (Job, Worker))] -> [(JobId, (Job, Worker))]
|
||||||
deleteJob jobid list =
|
deleteJob jobid list =
|
||||||
case list of
|
case list of
|
||||||
[] -> []
|
[] -> []
|
||||||
(jid, (job, w)):l -> if (jid == jobid) then l else (jid,(job,w)):(deleteJob jobid l)
|
(jid, (job, w)):l -> if (jid == jobid) then l else (jid,(job,w)):(deleteJob jobid l)
|
||||||
|
|
||||||
startSPC :: IO SPC
|
startSPC :: IO SPC
|
||||||
startSPC = do
|
startSPC = do
|
||||||
@ -300,7 +303,7 @@ workerLoop name c = do
|
|||||||
MsgStartJob (SPC sc) action jobid -> do
|
MsgStartJob (SPC sc) action jobid -> do
|
||||||
action
|
action
|
||||||
sendTo sc $ MsgJobDone jobid
|
sendTo sc $ MsgJobDone jobid
|
||||||
|
|
||||||
-- | Shut down a running worker. No effect if the worker is already
|
-- | Shut down a running worker. No effect if the worker is already
|
||||||
-- terminated.
|
-- terminated.
|
||||||
workerStop :: Worker -> IO ()
|
workerStop :: Worker -> IO ()
|
||||||
|
@ -33,6 +33,6 @@ tests =
|
|||||||
testCase "worker-add-2-fail" $ do
|
testCase "worker-add-2-fail" $ do
|
||||||
spc <- startSPC
|
spc <- startSPC
|
||||||
_ <- workerAdd spc "BD-1"
|
_ <- workerAdd spc "BD-1"
|
||||||
w <- workerAdd spc "R5-D4"
|
w <- workerAdd spc "BD-1"
|
||||||
isRight w @?= False
|
isRight w @?= False
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user