Skip to content

Commit 1ff41e8

Browse files
authored
Merge pull request #10285 from haskell/wip/hackage-tests-fix
ci: Fix --index-state for hackage roundtrip tests
2 parents 4f01b76 + 31507b1 commit 1ff41e8

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

Cabal-tests/Cabal-tests.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ test-suite hackage-tests
149149
, deepseq
150150
, directory
151151
, filepath
152+
, time
152153

153154
build-depends:
154155
base-compat >=0.11.0 && <0.14

Cabal-tests/tests/HackageTests.hs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import System.FilePath ((</>))
3333
import Data.Orphans ()
3434

3535
import qualified Codec.Archive.Tar as Tar
36+
import qualified Codec.Archive.Tar.Entry as Tar
3637
import qualified Data.ByteString as B
3738
import qualified Data.ByteString.Char8 as B8
3839
import qualified Data.ByteString.Lazy as BSL
@@ -56,11 +57,14 @@ import Data.TreeDiff.Instances.Cabal ()
5657
import Data.TreeDiff.Pretty (ansiWlEditExprCompact)
5758
#endif
5859

60+
import Data.Time.Clock.System
61+
import Data.Time.Format
62+
5963
-------------------------------------------------------------------------------
6064
-- parseIndex: Index traversal
6165
-------------------------------------------------------------------------------
6266

63-
parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool)
67+
parseIndex :: (Monoid a, NFData a) => (Tar.EpochTime -> FilePath -> Bool)
6468
-> (FilePath -> B.ByteString -> IO a) -> IO a
6569
parseIndex predicate action = do
6670
configPath <- getCabalConfigPath
@@ -99,7 +103,7 @@ parseIndex predicate action = do
99103

100104
parseIndex'
101105
:: (Monoid a, NFData a)
102-
=> (FilePath -> Bool)
106+
=> (Tar.EpochTime -> FilePath -> Bool)
103107
-> (FilePath -> B.ByteString -> IO a) -> FilePath -> IO a
104108
parseIndex' predicate action path = do
105109
putStrLn $ "Reading index from: " ++ path
@@ -110,7 +114,7 @@ parseIndex' predicate action path = do
110114

111115
where
112116
cons entry entries
113-
| predicate (Tar.entryPath entry) = entry : entries
117+
| predicate (Tar.entryTime entry) (Tar.entryPath entry) = entry : entries
114118
| otherwise = entries
115119

116120
f entry = case Tar.entryContent entry of
@@ -320,6 +324,13 @@ main = join (O.execParser opts)
320324
, O.progDesc "tests using Hackage's index"
321325
]
322326

327+
indexP =
328+
fmap cvt <$> O.optional (O.strOption (O.long "index-state" <> O.metavar "YYYY-MM-DD"))
329+
where
330+
cvt =
331+
systemSeconds . utcToSystemTime .
332+
parseTimeOrError False defaultTimeLocale "%Y-%m-%d"
333+
323334
optsP = subparser
324335
[ command "read-fields" readFieldsP
325336
"Parse outer format (to '[Field]', TODO: apply Quirks)"
@@ -330,20 +341,20 @@ main = join (O.execParser opts)
330341

331342
defaultA = do
332343
putStrLn "Default action: parsec k"
333-
parsecA (mkPredicate ["k"]) False
344+
parsecA ["k"] False Nothing
334345

335-
readFieldsP = readFieldsA <$> prefixP
336-
readFieldsA pfx = parseIndex pfx readFieldTest
346+
readFieldsP = readFieldsA <$> prefixP <*> indexP
347+
readFieldsA pfx idx = parseIndex (mkPredicate pfx idx) readFieldTest
337348

338-
parsecP = parsecA <$> prefixP <*> keepGoingP
349+
parsecP = parsecA <$> prefixP <*> keepGoingP <*> indexP
339350
keepGoingP =
340351
O.flag' True (O.long "keep-going") <|>
341352
O.flag' False (O.long "no-keep-going") <|>
342353
pure False
343354

344-
parsecA pfx keepGoing = do
355+
parsecA pfx keepGoing idx = do
345356
begin <- Clock.getTime Clock.Monotonic
346-
ParsecResult n w f <- parseIndex pfx (parseParsecTest keepGoing)
357+
ParsecResult n w f <- parseIndex (mkPredicate pfx idx) (parseParsecTest keepGoing)
347358
end <- Clock.getTime Clock.Monotonic
348359
let diff = Clock.toNanoSecs $ Clock.diffTimeSpec end begin
349360

@@ -353,14 +364,14 @@ main = join (O.execParser opts)
353364
putStrLn $ showFFloat (Just 6) (fromInteger diff / 1e9 :: Double) " seconds elapsed"
354365
putStrLn $ showFFloat (Just 6) (fromInteger diff / 1e6 / fromIntegral n :: Double) " milliseconds per file"
355366

356-
roundtripP = roundtripA <$> prefixP <*> testFieldsP
357-
roundtripA pfx testFieldsTransform = do
358-
Sum n <- parseIndex pfx (roundtripTest testFieldsTransform)
367+
roundtripP = roundtripA <$> prefixP <*> testFieldsP <*> indexP
368+
roundtripA pfx testFieldsTransform idx = do
369+
Sum n <- parseIndex (mkPredicate pfx idx) (roundtripTest testFieldsTransform)
359370
putStrLn $ show n ++ " files processed"
360371

361-
checkP = checkA <$> prefixP
362-
checkA pfx = do
363-
CheckResult n w x a b c d e <- parseIndex pfx parseCheckTest
372+
checkP = checkA <$> prefixP <*> indexP
373+
checkA pfx idx = do
374+
CheckResult n w x a b c d e <- parseIndex (mkPredicate pfx idx) parseCheckTest
364375
putStrLn $ show n ++ " files processed"
365376
putStrLn $ show w ++ " files have lexer/parser warnings"
366377
putStrLn $ show x ++ " files have check warnings"
@@ -370,7 +381,7 @@ main = join (O.execParser opts)
370381
putStrLn $ show d ++ " build dist suspicious warning"
371382
putStrLn $ show e ++ " build dist inexcusable"
372383

373-
prefixP = fmap mkPredicate $ many $ O.strArgument $ mconcat
384+
prefixP = many $ O.strArgument $ mconcat
374385
[ O.metavar "PREFIX"
375386
, O.help "Check only files starting with a prefix"
376387
]
@@ -380,8 +391,14 @@ main = join (O.execParser opts)
380391
, O.help "Test also 'showFields . fromParsecFields . readFields' transform"
381392
]
382393

383-
mkPredicate [] = const True
384-
mkPredicate pfxs = \n -> any (`isPrefixOf` n) pfxs
394+
indexPredicate :: Maybe Tar.EpochTime -> (k -> Bool) -> (Tar.EpochTime -> k -> Bool)
395+
indexPredicate Nothing k = const k
396+
indexPredicate (Just indexDate) k =
397+
\e -> if (e <= indexDate) then k else const False
398+
399+
mkPredicate :: [String] -> Maybe Tar.EpochTime -> (Tar.EpochTime -> FilePath -> Bool)
400+
mkPredicate [] idx = indexPredicate idx (const True)
401+
mkPredicate pfxs idx = indexPredicate idx (\n -> any (`isPrefixOf` n) pfxs)
385402

386403
command name p desc = O.command name
387404
(O.info (p <**> O.helper) (O.progDesc desc))

validate.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,18 @@ CMD="$($CABALLISTBIN Cabal-tests:test:rpmvercmp) $TESTSUITEJOBS --hide-successes
417417
CMD="$($CABALLISTBIN Cabal-tests:test:no-thunks-test) $TESTSUITEJOBS --hide-successes"
418418
(cd Cabal-tests && timed $CMD) || exit 1
419419

420+
421+
# See #10284 for why this value is pinned.
422+
HACKAGE_TESTS_INDEX_STATE="--index-state=2024-08-25"
423+
420424
CMD=$($CABALLISTBIN Cabal-tests:test:hackage-tests)
421-
(cd Cabal-tests && timed $CMD read-fields) || exit 1
425+
(cd Cabal-tests && timed $CMD read-fields $HACKAGE_TESTS_INDEX_STATE) || exit 1
422426
if $HACKAGETESTSALL; then
423-
(cd Cabal-tests && timed $CMD parsec) || exit 1
424-
(cd Cabal-tests && timed $CMD roundtrip) || exit 1
427+
(cd Cabal-tests && timed $CMD parsec $HACKAGE_TESTS_INDEX_STATE) || exit 1
428+
(cd Cabal-tests && timed $CMD roundtrip $HACKAGE_TESTS_INDEX_STATE) || exit 1
425429
else
426-
(cd Cabal-tests && timed $CMD parsec d) || exit 1
427-
(cd Cabal-tests && timed $CMD roundtrip k) || exit 1
430+
(cd Cabal-tests && timed $CMD parsec d $HACKAGE_TESTS_INDEX_STATE) || exit 1
431+
(cd Cabal-tests && timed $CMD roundtrip k $HACKAGE_TESTS_INDEX_STATE) || exit 1
428432
fi
429433
}
430434

0 commit comments

Comments
 (0)