mirror of
https://github.com/tensorflow/haskell.git
synced 2024-06-02 19:13:34 +02:00
Review changes
This commit is contained in:
parent
8dbbe12fce
commit
daf5bd4f35
|
@ -89,18 +89,19 @@ withEventWriter ::
|
|||
-- ^ logdir. Directory where event file will be written.
|
||||
-> (EventWriter -> m a)
|
||||
-> m a
|
||||
withEventWriter filePrefix =
|
||||
bracket (liftIO (newEventWriter filePrefix)) (liftIO . closeEventWriter)
|
||||
withEventWriter logdir =
|
||||
bracket (liftIO (newEventWriter logdir)) (liftIO . closeEventWriter)
|
||||
|
||||
newEventWriter :: FilePath -> IO EventWriter
|
||||
newEventWriter logdir = do
|
||||
createDirectoryIfMissing True logdir
|
||||
-- Create unique filename from prefix.
|
||||
t <- doubleWallTime
|
||||
hostname <- getHostName
|
||||
let filename = printf (logdir </> "events.out.tfevents.%010d.%s")
|
||||
(truncate t :: Integer) hostname
|
||||
-- Asynchronously consume events from a queue.
|
||||
-- We use a bounded queue to ensure the producer doesn't get too far ahead
|
||||
-- of the consumer. The buffer size was picked arbitrarily.
|
||||
q <- newTBMQueueIO 1024
|
||||
-- Use an MVar to signal that the worker thread has completed.
|
||||
done <- newEmptyMVar
|
||||
|
|
|
@ -50,9 +50,10 @@ testEventWriter = testCase "EventWriter" $
|
|||
withEventWriter dir $ \eventWriter ->
|
||||
mapM_ (logEvent eventWriter) expected
|
||||
files <- listDirectory dir
|
||||
assertBool "One file exists after" (length files == 1)
|
||||
assertEqual "One file exists after" 1 (length files)
|
||||
records <- runResourceT $ Conduit.runConduit $
|
||||
sourceTFRecords (dir </> head files) =$= Conduit.consume
|
||||
assertBool "File is not empty" (not (null records))
|
||||
let (header:body) = decodeMessageOrDie . BL.toStrict <$> records
|
||||
assertEqual "Header has expected version"
|
||||
(T.pack "brain.Event:2") (header ^. fileVersion)
|
||||
|
|
Loading…
Reference in New Issue
Block a user