Commit ffceed6d authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

make queue fairness test more deterministic

parent 862391be
Pipeline #3923 failed with stage
in 27 minutes and 28 seconds
...@@ -138,35 +138,28 @@ testExceptions = do ...@@ -138,35 +138,28 @@ testExceptions = do
testFairness :: IO () testFairness :: IO ()
testFairness = do testFairness = do
k <- genSecret k <- genSecret
let settings = defaultJobSettings 2 k let settings = defaultJobSettings 1 k
st :: JobsState JobT [String] () <- newJobsState settings defaultPrios st :: JobsState JobT [String] () <- newJobsState settings defaultPrios
runningJs <- newTVarIO (Counts 0 0) pickedSchedule <- newMVar (JobSchedule mempty)
let j jobt _jHandle _inp _l = do let j jobt _jHandle _inp _l = addJobToSchedule jobt pickedSchedule
atomically $ modifyTVar runningJs (inc jobt)
threadDelay jobDuration
atomically $ modifyTVar runningJs (dec jobt)
jobs = [ (A, j A) jobs = [ (A, j A)
, (A, j A) , (A, j A)
, (B, j B) , (B, j B)
, (A, j A) , (A, j A)
, (A, j A) , (A, j A)
] ]
_jids <- forM jobs $ \(t, f) -> do time <- getCurrentTime
pushJob t () f settings st -- in this scenario we simulate two types of jobs all with
threadDelay initialDelay -- all the same level of priority: our queue implementation
r1 <- readTVarIO runningJs -- will behave as a classic FIFO, keeping into account the
r1 `shouldBe` (Counts 2 0) -- time of arrival.
threadDelay jobDuration atomically $ forM_ (zip [0,2 ..] jobs) $ \(timeDelta, (t, f)) -> void $
r2 <- readTVarIO runningJs pushJobWithTime (addUTCTime (fromInteger timeDelta) time) t () f settings st
r2 `shouldBe` (Counts 1 1) -- MOST IMPORTANT CHECK: the B got picked after the
-- two As, because it was inserted right after them
-- and has equal priority.
threadDelay jobDuration
r3 <- readTVarIO runningJs
r3 `shouldBe` (Counts 1 0)
threadDelay jobDuration threadDelay jobDuration
r4 <- readTVarIO runningJs finalSchedule <- readMVar pickedSchedule
r4 `shouldBe` (Counts 0 0) finalSchedule `shouldBe` JobSchedule (fromList [A, A, B, A, A])
newtype MyDummyMonad a = newtype MyDummyMonad a =
MyDummyMonad { _MyDummyMonad :: GargM Env GargError a } MyDummyMonad { _MyDummyMonad :: GargM Env GargError a }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment