@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
{- # LANGUAGE FlexibleInstances # -}
{- # LANGUAGE GeneralizedNewtypeDeriving # -}
{- # LANGUAGE MultiParamTypeClasses # -}
{- # LANGUAGE OverloadedStrings # -}
{- # LANGUAGE TypeSynonymInstances # -}
@ -16,6 +17,7 @@ import Test.Tasty.SmallCheck as SC
@@ -16,6 +17,7 @@ import Test.Tasty.SmallCheck as SC
import ATrade.Driver.Junction.QuoteThread ( addSubscription ,
startQuoteThread ,
stopQuoteThread )
import ATrade.Logging ( Message )
import ATrade.Quotes.HistoryProvider ( HistoryProvider ( .. ) )
import ATrade.Quotes.TickerInfoProvider ( TickerInfoProvider ( .. ) )
import ATrade.QuoteSource.Client ( QuoteData ( QDBar ) )
@ -26,23 +28,21 @@ import ATrade.RoboCom.Types (BarSeries (bsBars),
@@ -26,23 +28,21 @@ import ATrade.RoboCom.Types (BarSeries (bsBars),
BarSeriesId ( BarSeriesId ) ,
InstrumentParameters ( InstrumentParameters ) )
import ATrade.Types
import Colog.Core ( LogAction ( .. ) )
import Colog.Core.Class ( HasLog ( .. ) )
import Control.Concurrent ( forkIO , threadDelay )
import Control.Concurrent.BoundedChan ( newBoundedChan , readChan ,
writeChan )
import Control.Exception ( bracket )
import Control.Monad ( forever )
import Control.Monad.Reader
import Data.IORef ( newIORef , readIORef )
import Data.IORef ( IORef , newIORef , readIORef )
import qualified Data.Map.Strict as M
import qualified Data.Text as T
import Data.Time ( UTCTime ( UTCTime ) ,
fromGregorian )
import System.IO ( BufferMode ( LineBuffering ) ,
hSetBuffering , stderr )
import System.Log.Formatter
import System.Log.Handler ( setFormatter )
import System.Log.Handler.Simple
import System.Log.Logger
import System.ZMQ4 ( withContext )
import Test.Mock.HistoryProvider ( MockHistoryProvider ,
mkMockHistoryProvider ,
@ -70,13 +70,16 @@ instance TickerInfoProvider TestM where
@@ -70,13 +70,16 @@ instance TickerInfoProvider TestM where
tip <- asks tickerInfoProvider
liftIO $ mockGetInstrumentParameters tip tickers
instance HasLog TestEnv Message TestM where
getLogAction env = LogAction $ \ msg -> return ()
qsEndpoint = " inproc://qs "
mockHistoryProvider = mkMockHistoryProvider $ M . fromList [ ( BarSeriesId " FOO " ( BarTimeframe 3600 ) , bars ) ]
where
bars = []
mockTickerInfoProvider = mkMockTickerInfoProvider $ M . fromList [ ( " FOO " , InstrumentParameters 10 0.1 ) ]
mockTickerInfoProvider = mkMockTickerInfoProvider $ M . fromList [ ( " FOO " , InstrumentParameters " FOO " 10 0.1 ) ]
unitTests = testGroup " Driver.Junction.QuoteThread " [
testSubscription
@ -85,12 +88,14 @@ unitTests = testGroup "Driver.Junction.QuoteThread" [
@@ -85,12 +88,14 @@ unitTests = testGroup "Driver.Junction.QuoteThread" [
testSubscription :: TestTree
testSubscription = testCase " Subscription " $ withContext $ \ ctx -> do
barsRef <- newIORef M . empty
tiRef <- newIORef M . empty
serverChan <- newBoundedChan 2000
let clientSecurityParams = defaultClientSecurityParams
bracket
( startQuoteSourceServer serverChan ctx qsEndpoint defaultServerSecurityParams )
stopQuoteSourceServer $ \ _ ->
bracket
( startQuoteThread barsRef ctx qsEndpoint Nothing Nothing ( ` runReaderT ` ( TestEnv mockHistoryProvider mockTickerInfoProvider ) ) )
( startQuoteThread barsRef tiRef ctx qsEndpoint clientSecurityParams ( ` runReaderT ` ( TestEnv mockHistoryProvider mockTickerInfoProvider ) ) ( LogAction $ \ _ -> return ( )) )
stopQuoteThread $ \ qt -> do
chan <- newBoundedChan 2000