Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 2f4ef85

Browse files
committed
[CBR-430] setupTestLogging and setupTestTrace
Signed-off-by: Alexander Diemand <[email protected]>
1 parent bf79184 commit 2f4ef85

File tree

15 files changed

+39
-42
lines changed

15 files changed

+39
-42
lines changed

explorer/test/Test/Pos/Explorer/Socket/MethodsSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ import Pos.Explorer.Socket.Methods (addrSubParam, addressSetByTxs,
3737
unsubscribeTxs)
3838
import Pos.Explorer.TestUtil (secretKeyToAddress)
3939
import Pos.Explorer.Web.ClientTypes (CAddress (..), toCAddress)
40-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
41-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
40+
import Pos.Util.Wlog (setupTestLogging)
4241

4342
import Test.Pos.Explorer.MockFactory (mkTxOut)
4443

@@ -50,7 +49,7 @@ import Test.Pos.Explorer.MockFactory (mkTxOut)
5049
-- stack test cardano-sl-explorer --fast --test-arguments "-m Test.Pos.Explorer.Socket"
5150

5251
spec :: Spec
53-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
52+
spec = beforeAll_ setupTestLogging $
5453
describe "Methods" $ do
5554
describe "fromCAddressOrThrow" $
5655
it "throws an exception if a given CAddress is invalid" $

generator/test/Test/Pos/Binary/CommunicationSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import Pos.DB.Class (Serialized (..))
1717
import Pos.Network.Block.Types (MsgBlock (..),
1818
MsgSerializedBlock (..))
1919
import Pos.Util.CompileInfo (withCompileInfo)
20-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
21-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
20+
import Pos.Util.Wlog (setupTestLogging)
2221

2322
import Test.Pos.Block.Logic.Mode (blockPropertyTestable)
2423
import Test.Pos.Block.Logic.Util (EnableTxPayload (..),
@@ -72,7 +71,7 @@ deserializeSerilizedMsgSerializedBlockSpec = do
7271
descNoBlock = "deserialization of a serialized MsgNoSerializedBlock message should give back corresponding MsgNoBlock"
7372

7473
spec :: Spec
75-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
74+
spec = beforeAll_ setupTestLogging $
7675
withStaticConfigurations $ \_ _ -> withCompileInfo $
7776
describe "Pos.Binary.Communication" $ do
7877
describe "serializeMsgSerializedBlock" serializeMsgSerializedBlockSpec

generator/test/Test/Pos/Block/Logic/VarSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ import Pos.Generator.BlockEvent.DSL (BlockApplyResult (..),
4141
runBlockEventGenT)
4242
import qualified Pos.GState as GS
4343
import Pos.Launcher (HasConfigurations)
44-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
45-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
44+
import Pos.Util.Wlog (setupTestLogging)
4645

4746
import Test.Pos.Block.Logic.Event (BlockScenarioResult (..),
4847
DbNotEquivalentToSnapshot (..), runBlockScenario)
@@ -61,7 +60,7 @@ import Test.Pos.Util.QuickCheck.Property (splitIntoChunks,
6160
spec :: Spec
6261
-- Unfortunatelly, blocks generation is quite slow nowdays.
6362
-- See CSL-1382.
64-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $ withStaticConfigurations $ \txpConfig _ ->
63+
spec = beforeAll_ setupTestLogging $ withStaticConfigurations $ \txpConfig _ ->
6564
describe "Block.Logic.VAR" $ modifyMaxSuccess (min 4) $ do
6665
describe "verifyBlocksPrefix" $ verifyBlocksPrefixSpec txpConfig
6766
describe "verifyAndApplyBlocks" $ verifyAndApplyBlocksSpec txpConfig

lib/test/Test/Pos/Diffusion/BlockSpec.hs

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ import Pos.Infra.Network.Types (Bucket (..))
4545
import Pos.Infra.Reporting.Health.Types (HealthStatus (..))
4646
import Pos.Logic.Pure (pureLogic)
4747
import Pos.Logic.Types as Logic (Logic (..))
48-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
49-
import Pos.Util.Trace (wlogTrace, wsetupLogging)
50-
import Pos.Util.Wlog (Severity (Debug))
48+
import Pos.Util.Trace (setupTestTrace, wlogTrace)
5149

5250
import Test.Pos.Chain.Block.Arbitrary.Generate (generateMainBlock)
5351

@@ -122,7 +120,7 @@ clientLogic = pureLogic
122120

123121
withServer :: Transport -> Logic IO -> (NodeId -> IO t) -> IO t
124122
withServer transport logic k = do
125-
logTrace <- liftIO $ wsetupLogging "test" (defaultTestConfiguration Debug) ("server.outboundqueue")
123+
logTrace <- liftIO $ setupTestTrace
126124
-- Morally, the server shouldn't need an outbound queue, but we have to
127125
-- give one.
128126
oq <- liftIO $ OQ.new

lib/test/Test/Pos/Launcher/ConfigurationSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ import Pos.Core.Slotting (Timestamp (..))
1111
import Pos.Launcher.Configuration (ConfigurationOptions (..),
1212
defaultConfigurationOptions, withConfigurationsM)
1313
import Pos.Util.Config (ConfigurationException)
14-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
15-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
14+
import Pos.Util.Wlog (setupTestLogging)
1615

1716
spec :: Spec
1817
spec = describe "Pos.Launcher.Configuration" $ do
1918
describe "withConfigurationsM" $ do
2019
it "should parse `lib/configuration.yaml` file" $ do
21-
liftIO $ setupLogging "test" (defaultTestConfiguration Debug)
20+
liftIO $ setupTestLogging
2221
startTime <- Timestamp . round . (* 1000000) <$> liftIO getPOSIXTime
2322
let cfo = defaultConfigurationOptions
2423
{ cfoFilePath = "./configuration.yaml"

networking/test/Test/NodeSpec.hs

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ import Test.QuickCheck.Modifiers (NonEmptyList (..), getNonEmpty)
3535

3636
import Node
3737
import Node.Message.Binary (binaryPacking)
38-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
39-
import Pos.Util.Trace (wsetupLogging)
40-
import Pos.Util.Wlog (Severity (Debug))
38+
import Pos.Util.Trace (setupTestTrace)
4139
import Test.Util (HeavyParcel (..), Parcel (..), Payload (..),
4240
TestState, deliveryTest, expected, makeInMemoryTransport,
4341
makeTCPTransport, mkTestState, modifyTestState,
@@ -46,7 +44,7 @@ import Test.Util (HeavyParcel (..), Parcel (..), Payload (..),
4644
spec :: Spec
4745
spec = describe "Node" $ modifyMaxSuccess (const 50) $ do
4846

49-
logTrace <- runIO $ wsetupLogging "test" (defaultTestConfiguration Debug) "nodespec"
47+
logTrace <- runIO $ setupTestTrace
5048

5149
-- Take at most 25000 bytes for each Received message.
5250
-- We want to ensure that the MTU works, but not make the tests too

util/src/Pos/Util/Trace.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Pos.Util.Trace
1313
, Wlog.Severity (..)
1414
-- * trace setup
1515
, setupLogging
16-
, wsetupLogging
16+
, setupTestTrace
1717
, logTrace
1818
-- * log messages
1919
, logDebug
@@ -26,6 +26,7 @@ module Pos.Util.Trace
2626
import Data.Functor.Contravariant (Contravariant (..), Op (..))
2727
import qualified Data.Text.IO as TIO
2828
import qualified Pos.Util.Log as Log
29+
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
2930
import qualified Pos.Util.Wlog as Wlog
3031
import Universum hiding (trace)
3132

@@ -60,6 +61,10 @@ wsetupLogging cfoKey lc ln = do
6061
Wlog.setupLogging cfoKey lc
6162
return $ wlogTrace ln
6263

64+
setupTestTrace :: IO (Trace IO (Wlog.Severity, Text))
65+
setupTestTrace =
66+
wsetupLogging "test" (defaultTestConfiguration Wlog.Debug) "testing"
67+
6368
trace :: Trace m s -> s -> m ()
6469
trace = getOp . runTrace
6570

util/src/Pos/Util/Wlog.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Pos.Util.Wlog
1515
, runNamedPureLog
1616
-- * Setup
1717
, setupLogging
18+
, setupTestLogging
1819
-- * Logging functions
1920
, logDebug
2021
, logError
@@ -55,4 +56,4 @@ import Pos.Util.Wlog.Compatibility (CanLog (..), HasLoggerName (..),
5556
launchNamedPureLog, logDebug, logError, logInfo, logMCond,
5657
logMessage, logNotice, logWarning, productionB,
5758
removeAllHandlers, retrieveLogContent, runNamedPureLog,
58-
setupLogging, usingLoggerName)
59+
setupLogging, setupTestLogging, usingLoggerName)

util/src/Pos/Util/Wlog/Compatibility.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Pos.Util.Wlog.Compatibility
99
, dispatchEvents
1010
, LogEvent (..)
1111
, setupLogging
12+
, setupTestLogging
1213
-- * Logging functions
1314
, logDebug
1415
, logError
@@ -56,8 +57,8 @@ import qualified Pos.Util.Log as Log
5657
import qualified Pos.Util.Log.Internal as Internal
5758
import Pos.Util.Log.LoggerConfig (LogHandler (..),
5859
LogSecurityLevel (..), LoggerConfig (..),
59-
defaultInteractiveConfiguration, lcLoggerTree, lhName,
60-
ltHandlers)
60+
defaultInteractiveConfiguration, defaultTestConfiguration,
61+
lcLoggerTree, lhName, ltHandlers)
6162
import System.IO.Unsafe (unsafePerformIO)
6263

6364
import Universum
@@ -226,6 +227,10 @@ loggingHandler :: MVar LoggingHandler
226227
loggingHandler = unsafePerformIO $ do
227228
newMVar $ error "LoggingHandler MVar is not initialized."
228229

230+
-- | setup logging used in tests
231+
setupTestLogging :: IO ()
232+
setupTestLogging = setupLogging "test" (defaultTestConfiguration Debug)
233+
229234
-- | setup logging according to configuration @LoggerConfig@
230235
-- the backends (scribes) will be registered with katip
231236
setupLogging :: MonadIO m => Text -> LoggerConfig -> m ()

wallet-new/test/InternalAPISpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import Pos.Client.KeyStorage (getSecretKeysPlain)
2020
import Pos.Wallet.Web.Account (genSaveRootKey)
2121

2222
import Pos.Launcher (HasConfigurations)
23-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
24-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
23+
import Pos.Util.Wlog (setupTestLogging)
2524
import Test.Pos.Util.QuickCheck.Property (assertProperty)
2625

2726
import Test.Hspec (Spec, beforeAll_, describe)
@@ -37,7 +36,7 @@ import Servant
3736
{-# ANN module ("HLint: ignore Reduce duplication" :: Text) #-}
3837

3938
spec :: Spec
40-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
39+
spec = beforeAll_ setupTestLogging $
4140
withDefConfigurations $ \_ _ _ ->
4241
describe "development endpoint" $
4342
describe "secret-keys" $ modifyMaxSuccess (const 10) deleteAllSecretKeysSpec

wallet/test/Test/Pos/Wallet/Web/AddressSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import Pos.Client.Txp.Addresses (getFakeChangeAddress, getNewAddress)
2020
import Pos.Core.Common (Address)
2121
import Pos.Crypto (PassPhrase)
2222

23-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
24-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
23+
import Pos.Util.Wlog (setupTestLogging)
2524
import Pos.Wallet.Web.Account (GenSeed (..), genUniqueAddress)
2625
import Pos.Wallet.Web.ClientTypes (AccountId, CAccountInit (..), caId)
2726
import Pos.Wallet.Web.Error (WalletError (..))
@@ -37,7 +36,7 @@ import Test.Pos.Wallet.Web.Util (importSingleWallet,
3736
mostlyEmptyPassphrases)
3837

3938
spec :: Spec
40-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
39+
spec = beforeAll_ setupTestLogging $
4140
withDefConfigurations $ \_ _ _ ->
4241
describe "Fake address has maximal possible size" $
4342
modifyMaxSuccess (const 10) $ do

wallet/test/Test/Pos/Wallet/Web/Methods/BackupDefaultAddressesSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import Universum
99

1010
import Pos.Launcher (HasConfigurations)
1111

12-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
13-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
12+
import Pos.Util.Wlog (setupTestLogging)
1413
import Pos.Wallet.Web.ClientTypes (CWallet (..))
1514
import Pos.Wallet.Web.Methods.Restore (restoreWalletFromBackup)
1615
import Test.Hspec (Spec, beforeAll_, describe)
@@ -23,7 +22,7 @@ import Test.QuickCheck (Arbitrary (..))
2322
import Test.QuickCheck.Monadic (pick)
2423

2524
spec :: Spec
26-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
25+
spec = beforeAll_ setupTestLogging $
2726
withDefConfigurations $ \_ _ _ ->
2827
describe "restoreAddressFromWalletBackup" $ modifyMaxSuccess (const 10) $ do
2928
restoreWalletAddressFromBackupSpec

wallet/test/Test/Pos/Wallet/Web/Methods/LogicSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import Universum
1010
import Test.Hspec (Spec, beforeAll_, describe)
1111
import Test.Hspec.QuickCheck (prop)
1212

13-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
14-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
13+
import Pos.Util.Wlog (setupTestLogging)
1514
import Pos.Wallet.Web.Methods.Logic (getAccounts, getWallets)
1615

1716
import Test.Pos.Configuration (withDefConfigurations)
@@ -20,7 +19,7 @@ import Test.Pos.Wallet.Web.Mode (WalletProperty)
2019

2120
-- TODO remove HasCompileInfo when MonadWalletWebMode will be splitted.
2221
spec :: Spec
23-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
22+
spec = beforeAll_ setupTestLogging $
2423
withDefConfigurations $ \_ _ _ ->
2524
describe "Pos.Wallet.Web.Methods" $ do
2625
prop emptyWalletOnStarts emptyWallet

wallet/test/Test/Pos/Wallet/Web/Methods/PaymentSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ import qualified Pos.Wallet.Web.State.State as WS
4444
import Pos.Wallet.Web.State.Storage (AddressInfo (..), wamAddress)
4545
import Pos.Wallet.Web.Util (decodeCTypeOrFail, getAccountAddrsOrThrow)
4646

47-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
4847
import Pos.Util.Servant (encodeCType)
49-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
48+
import Pos.Util.Wlog (setupTestLogging)
5049

5150
import Test.Pos.Chain.Genesis.Dummy (dummyConfig, dummyGenesisData)
5251
import Test.Pos.Configuration (withDefConfigurations)
@@ -63,7 +62,7 @@ deriving instance Eq CTx
6362

6463
-- TODO remove HasCompileInfo when MonadWalletWebMode will be splitted.
6564
spec :: Spec
66-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
65+
spec = beforeAll_ setupTestLogging $
6766
withCompileInfo $
6867
withDefConfigurations $ \_ txpConfig _ ->
6968
describe "Wallet.Web.Methods.Payment" $ modifyMaxSuccess (const 10) $ do

wallet/test/Test/Pos/Wallet/Web/Tracking/SyncSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import Pos.Core.Chrono (nonEmptyOldestFirst, toNewestFirst)
2525
import Pos.Crypto (emptyPassphrase)
2626
import Pos.DB.Block (rollbackBlocks)
2727
import Pos.Launcher (HasConfigurations)
28-
import Pos.Util.Log.LoggerConfig (defaultTestConfiguration)
29-
import Pos.Util.Wlog (Severity (Debug), setupLogging)
28+
import Pos.Util.Wlog (setupTestLogging)
3029
import qualified Pos.Wallet.Web.State as WS
3130
import Pos.Wallet.Web.State.Storage (WalletStorage (..))
3231
import Pos.Wallet.Web.Tracking.Decrypt (WalletDecrCredentialsKey (..),
@@ -51,7 +50,7 @@ import Test.Pos.Wallet.Web.Mode (walletPropertySpec)
5150
import Test.Pos.Wallet.Web.Util (importSomeWallets, wpGenBlocks)
5251

5352
spec :: Spec
54-
spec = beforeAll_ (setupLogging "test" (defaultTestConfiguration Debug)) $
53+
spec = beforeAll_ setupTestLogging $
5554
withDefConfigurations $ \_ _ _ -> do
5655
describe "Pos.Wallet.Web.Tracking.BListener" $ modifyMaxSuccess (const 10) $ do
5756
describe "Two applications and rollbacks" twoApplyTwoRollbacksSpec

0 commit comments

Comments
 (0)