1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Test actual sending of data

This commit is contained in:
Timothy Clem 2017-10-04 11:40:39 -07:00
parent f0edcd48f2
commit c7f4ae005b
3 changed files with 19 additions and 1 deletions

View File

@ -182,6 +182,7 @@ test-suite test
, HUnit
, leancheck
, mtl
, network
, containers
, recursion-schemes >= 4.1
, semantic-diff

View File

@ -17,8 +17,9 @@ module Semantic.Stat
, defaultStatsClient
, StatsClient(..)
-- Internal
-- Internal, exposed for testing
, renderDatagram
, sendStats
) where

View File

@ -5,6 +5,14 @@ import Test.Hspec hiding (shouldBe, shouldNotBe, shouldThrow, errorCall)
import Test.Hspec.Expectations.Pretty
import System.Environment
import Control.Exception
import Network.Socket hiding (recv)
import Network.Socket.ByteString
withSocketPair :: ((Socket, Socket) -> IO c) -> IO c
withSocketPair = bracket create release
where create = socketPair AF_UNIX Datagram defaultProtocol
release (client, server) = close client >> close server
withEnvironment :: String -> String -> (() -> IO ()) -> IO ()
withEnvironment key value = bracket (setEnv key value) (const (unsetEnv key))
@ -59,3 +67,11 @@ spec = do
it "renders tags without value" $ do
let inc = increment key [("key", "value"), ("a", "")]
renderDatagram "" inc `shouldBe` "app.metric:1|c|#key:value,a"
describe "sendStats" $
it "delivers datagram" $ do
client@StatsClient{..} <- defaultStatsClient
withSocketPair $ \(clientSoc, serverSoc) -> do
sendStats client { udpSocket = clientSoc } (increment "app.metric" [])
info <- recv serverSoc 1024
info `shouldBe` "semantic.app.metric:1|c"