Browse Source

QuoteSource client: +1 test

master
Denis Tereshkin 9 years ago
parent
commit
14f1f5212c
  1. 19
      test/TestQuoteSourceClient.hs

19
test/TestQuoteSourceClient.hs

@ -16,7 +16,7 @@ import Control.Monad
import Control.Monad.Loops import Control.Monad.Loops
import Control.Concurrent.MVar import Control.Concurrent.MVar
import Control.Concurrent.BoundedChan import Control.Concurrent.BoundedChan
import Control.Concurrent hiding (writeChan) import Control.Concurrent hiding (writeChan, readChan)
import Control.Exception import Control.Exception
import System.ZMQ4 import System.ZMQ4
import Data.Time.Clock import Data.Time.Clock
@ -31,7 +31,7 @@ makeEndpoint = do
uid <- toText <$> UV4.nextRandom uid <- toText <$> UV4.nextRandom
return $ "inproc://server" `T.append` uid return $ "inproc://server" `T.append` uid
unitTests = testGroup "QuoteSource.Client" [testStartStop] unitTests = testGroup "QuoteSource.Client" [testStartStop, testTickStream]
testStartStop = testCase "QuoteSource client connects and disconnects" $ withContext (\ctx -> do testStartStop = testCase "QuoteSource client connects and disconnects" $ withContext (\ctx -> do
ep <- makeEndpoint ep <- makeEndpoint
@ -40,4 +40,19 @@ testStartStop = testCase "QuoteSource client connects and disconnects" $ withCon
bracket (startQuoteSourceServer chan ctx ep) stopQuoteSourceServer (\qs -> bracket (startQuoteSourceServer chan ctx ep) stopQuoteSourceServer (\qs ->
bracket (startQuoteSourceClient clientChan [] ctx ep) stopQuoteSourceClient (const yield))) bracket (startQuoteSourceClient clientChan [] ctx ep) stopQuoteSourceClient (const yield)))
testTickStream = testCase "QuoteSource clients receives ticks" $ withContext (\ctx -> do
ep <- makeEndpoint
chan <- newBoundedChan 1000
clientChan <- newBoundedChan 1000
bracket (startQuoteSourceServer chan ctx ep) stopQuoteSourceServer (\qs ->
bracket (startQuoteSourceClient clientChan ["FOOBAR"] ctx ep) stopQuoteSourceClient (\qc -> do
let tick = Tick {
security = "FOOBAR",
datatype = Price,
timestamp = UTCTime (fromGregorian 2016 9 27) 16000,
value = 1000,
volume = 1}
writeChan chan (Just tick)
recvdTick <- readChan clientChan
tick @=? recvdTick)))

Loading…
Cancel
Save