speed up --pattern
authorJoey Hess <joeyh@joeyh.name>
Wed, 7 Dec 2022 17:46:16 +0000 (13:46 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 7 Dec 2022 17:51:22 +0000 (13:51 -0400)
The splitting of the tests into parts for parallelism made --pattern
do extra work, because init tests have to be run for each part, but
many of the parts are empty.

For example, git-annex test --pattern '/move (ssh remote)/'
took 12 seconds to run before. This improves the runtime to 4 seconds.

Sponsored-by: Dartmouth College's Datalad project
Test/Framework.hs
doc/bugs/git_annex_test_never_exits__63__/comment_6_d12ddfb48706454eba1bd552a681e5ba._comment

index d74ae7f3e1345bfb488a989472d14e01dc0424ac..9023eb0c8339884dfdc81a0aef00c6e626ab6d98 100644 (file)
@@ -749,7 +749,12 @@ parallelTestRunner' numjobs opts mkts
        -- Make more parts than there are jobs, because some parts
        -- are larger, and this allows the smaller parts to be packed
        -- in more efficiently, speeding up the test suite overall.
-       numparts = numjobs * 2
+       --
+       -- When there is a pattern, splitting into parts will cause
+       -- extra work.
+       numparts = if haspattern
+               then 1
+               else numjobs * 2
 
        worker rs nvar a = do
                (n, m) <- atomically $ do
@@ -814,15 +819,16 @@ parallelTestRunner' numjobs opts mkts
                                        , exitFailure
                                        )
        
-       tastyopts = case lookupOption (tastyOptionSet opts) of
+       (haspattern, tastyopts) = case lookupOption (tastyOptionSet opts) of
                -- Work around limitation of tasty; when tests to run
                -- are limited to a pattern, it does not include their
                -- dependencies. So, add another pattern including the
                -- init tests, which are a dependency of most tests.
                TestPattern (Just p) -> 
-                       setOption (TestPattern (Just (TP.Or p (TP.ERE initTestsName))))
-                               (tastyOptionSet opts)
-               TestPattern Nothing -> tastyOptionSet opts
+                       (True, setOption (TestPattern (Just (TP.Or p (TP.ERE initTestsName))))
+                               (tastyOptionSet opts))
+               TestPattern Nothing ->
+                       (False, tastyOptionSet opts)
 
 topLevelTestGroup :: [TestTree] -> TestTree
 topLevelTestGroup = testGroup "Tests"
index fffca75e74b0cbfdccd1e8b9a710e708dc18236a..030f6816ee6d5c9aab5bb5d6bd7fb9d294727e8f 100644 (file)
@@ -14,4 +14,6 @@ This will limit the test suite to only running the that test:
 
 I have that repeating locally in a loop, in case it's just something that
 happens every 1000 test runs or something like that.
+
+(I've patched git-annex to speed up the above command 400%.)
 """]]