Make flag-decision tests fail fast and assert the outbound metric

This commit is contained in:
2026-09-30 08:57:40 +03:00
parent 526710ef71
commit aee34f4e14
2 changed files with 13 additions and 9 deletions
+8 -6
View File
@@ -3,9 +3,8 @@
module ConnectionSpec (spec) where
import AFRP (Request(..))
import Control.Monad.IO.Class (liftIO)
import Data.Aeson (object, (.=))
import Data.Foldable (forM_)
import qualified Data.HashMap.Strict as HM
import Data.Maybe (fromJust)
import Data.Text (Text)
import Data.Time (UTCTime (..), utc)
@@ -19,6 +18,7 @@ import HomeAssistant.Runtime.Connection (dispatchService, encodeService, isTrigg
import Katip (Namespace (Namespace), Severity (InfoS), runKatipContextT)
import System.IO.Temp (withTempDirectory)
import qualified System.Metrics as Metrics
import System.Timeout (timeout)
import Test.Hspec
spec :: Spec
@@ -63,10 +63,12 @@ spec = do
flags <- loadFlags dir ["test"]
setEnabled flags "test" False
withBus InfoS m flags $ \bus -> do
runKatipContextT (busLogEnv bus) () (Namespace ["connection"]) $
dispatchService limiter bus (req 1) (lightOn [EntityId "light.test"])
generateCallId (busGen bus) `shouldReturn` 1
timeout 1000000 (do
runKatipContextT (busLogEnv bus) () (Namespace ["connection"]) $
dispatchService limiter bus (req 1) (lightOn [EntityId "light.test"])
generateCallId (busGen bus)) `shouldReturn` Just 1
sample <- Metrics.sampleAll store
HM.lookup "hass.service.out" sample `shouldBe` Just (Metrics.Counter 0)
req :: Int -> Request
req n = Request (UTCTime (toEnum 0) (fromIntegral (0 :: Int))) utc