|
|
|
|
@ -16,7 +16,7 @@ import Control.Monad
@@ -16,7 +16,7 @@ import Control.Monad
|
|
|
|
|
import Control.Monad.Loops |
|
|
|
|
import Control.Concurrent.MVar |
|
|
|
|
import Control.Concurrent.BoundedChan |
|
|
|
|
import Control.Concurrent hiding (writeChan) |
|
|
|
|
import Control.Concurrent hiding (writeChan, readChan) |
|
|
|
|
import Control.Exception |
|
|
|
|
import System.ZMQ4 |
|
|
|
|
import Data.Time.Clock |
|
|
|
|
@ -31,7 +31,7 @@ makeEndpoint = do
@@ -31,7 +31,7 @@ makeEndpoint = do
|
|
|
|
|
uid <- toText <$> UV4.nextRandom |
|
|
|
|
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 |
|
|
|
|
ep <- makeEndpoint |
|
|
|
|
@ -40,4 +40,19 @@ testStartStop = testCase "QuoteSource client connects and disconnects" $ withCon
@@ -40,4 +40,19 @@ testStartStop = testCase "QuoteSource client connects and disconnects" $ withCon
|
|
|
|
|
bracket (startQuoteSourceServer chan ctx ep) stopQuoteSourceServer (\qs -> |
|
|
|
|
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))) |
|
|
|
|
|
|
|
|
|
|