Skip to content

Commit

Permalink
concurrent-tests setting #492
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jul 3, 2015
1 parent e94aa71 commit fc963d1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Rename `stack docker exec` to `stack exec --plain`
* Add the `--skip-msys` flag [#377](https://github.com/commercialhaskell/stack/issues/377)
* `--keep-going`, turned on by default for tests and benchmarks [#478](https://github.com/commercialhaskell/stack/issues/478)
* `concurrent-tests: BOOL` [#492](https://github.com/commercialhaskell/stack/issues/492)

## 0.1.1.0

Expand Down
15 changes: 14 additions & 1 deletion src/Control/Concurrent/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data ExecuteState = ExecuteState
, esExceptions :: TVar [SomeException]
, esInAction :: TVar (Set ActionId)
, esCompleted :: TVar Int
, esFinalLock :: Maybe (TMVar ())
, esKeepGoing :: Bool
}

Expand All @@ -59,15 +60,19 @@ instance Show ExecuteException where

runActions :: Int -- ^ threads
-> Bool -- ^ keep going after one task has failed
-> Bool -- ^ run final actions concurrently?
-> [Action]
-> (TVar Int -> IO ()) -- ^ progress updated
-> IO [SomeException]
runActions threads keepGoing actions0 withProgress = do
runActions threads keepGoing concurrentFinal actions0 withProgress = do
es <- ExecuteState
<$> newTVarIO actions0
<*> newTVarIO []
<*> newTVarIO Set.empty
<*> newTVarIO 0
<*> (if concurrentFinal
then pure Nothing
else Just <$> atomically (newTMVar ()))
<*> pure keepGoing
_ <- async $ withProgress $ esCompleted es
if threads <= 1
Expand Down Expand Up @@ -100,6 +105,13 @@ runActions' ExecuteState {..} =
return $ return ()
else retry
(xs, action:ys) -> do
unlock <-
case (actionId action, esFinalLock) of
(ActionId _ ATFinal, Just lock) -> do
takeTMVar lock
return $ putTMVar lock ()
_ -> return $ return ()

let as' = xs ++ ys
inAction <- readTVar esInAction
let remaining = Set.union
Expand All @@ -112,6 +124,7 @@ runActions' ExecuteState {..} =
{ acRemaining = remaining
}
atomically $ do
unlock
modifyTVar esInAction (Set.delete $ actionId action)
modifyTVar esCompleted (+1)
case eres of
Expand Down
7 changes: 6 additions & 1 deletion src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,20 @@ executePlan' plan ee@ExecuteEnv {..} = do
(planTasks plan)
(planFinals plan)
threads <- asks $ configJobs . getConfig
concurrentTests <- asks $ configConcurrentTests . getConfig
let keepGoing =
case boptsKeepGoing eeBuildOpts of
Just kg -> kg
Nothing ->
case boptsFinalAction eeBuildOpts of
DoNothing -> False
_ -> True
concurrentFinal =
case boptsFinalAction eeBuildOpts of
DoTests _ -> concurrentTests
_ -> True
terminal <- asks getTerminal
errs <- liftIO $ runActions threads keepGoing actions $ \doneVar -> do
errs <- liftIO $ runActions threads keepGoing concurrentFinal actions $ \doneVar -> do
let total = length actions
loop prev
| prev == total =
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ configFromConfigMonoid configStackRoot mproject configMonoid@ConfigMonoid{..} =
case configMonoidJobs of
Nothing -> liftIO getNumCapabilities
Just i -> return i
let configConcurrentTests = fromMaybe True configMonoidConcurrentTests

return Config {..}

Expand Down
7 changes: 7 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ data Config =
-- ^ --extra-lib-dirs arguments
,configConfigMonoid :: !ConfigMonoid
-- ^ @ConfigMonoid@ used to generate this
,configConcurrentTests :: !Bool
-- ^ Run test suites concurrently
}

-- | Information on a single package index
Expand Down Expand Up @@ -432,6 +434,8 @@ data ConfigMonoid =
-- ^ See: 'configExtraIncludeDirs'
,configMonoidExtraLibDirs :: !(Set Text)
-- ^ See: 'configExtraLibDirs'
,configMonoidConcurrentTests :: !(Maybe Bool)
-- ^ See: 'configConcurrentTests'
}
deriving Show

Expand All @@ -452,6 +456,7 @@ instance Monoid ConfigMonoid where
, configMonoidJobs = Nothing
, configMonoidExtraIncludeDirs = Set.empty
, configMonoidExtraLibDirs = Set.empty
, configMonoidConcurrentTests = Nothing
}
mappend l r = ConfigMonoid
{ configMonoidDockerOpts = configMonoidDockerOpts l <> configMonoidDockerOpts r
Expand All @@ -470,6 +475,7 @@ instance Monoid ConfigMonoid where
, configMonoidJobs = configMonoidJobs l <|> configMonoidJobs r
, configMonoidExtraIncludeDirs = Set.union (configMonoidExtraIncludeDirs l) (configMonoidExtraIncludeDirs r)
, configMonoidExtraLibDirs = Set.union (configMonoidExtraLibDirs l) (configMonoidExtraLibDirs r)
, configMonoidConcurrentTests = configMonoidConcurrentTests l <|> configMonoidConcurrentTests r
}

instance FromJSON ConfigMonoid where
Expand All @@ -493,6 +499,7 @@ instance FromJSON ConfigMonoid where
configMonoidJobs <- obj .:? "jobs"
configMonoidExtraIncludeDirs <- obj .:? "extra-include-dirs" .!= Set.empty
configMonoidExtraLibDirs <- obj .:? "extra-lib-dirs" .!= Set.empty
configMonoidConcurrentTests <- obj .:? "concurrent-tests"
return ConfigMonoid {..}

-- | Newtype for non-orphan FromJSON instance.
Expand Down

0 comments on commit fc963d1

Please sign in to comment.