Works
This commit is contained in:
+10
-6
@@ -2,6 +2,7 @@
|
||||
|
||||
module BusSpec (spec) where
|
||||
|
||||
import AFRP (Request (..))
|
||||
import Control.Concurrent.STM
|
||||
( atomically
|
||||
, dupTChan
|
||||
@@ -9,14 +10,16 @@ import Control.Concurrent.STM
|
||||
, writeTChan
|
||||
)
|
||||
import Data.Aeson (Value (..))
|
||||
import Data.Time (UTCTime (..))
|
||||
import Data.UUID (nil)
|
||||
import HomeAssistant.Controller (HASSEff (..), Service (..), Target(..))
|
||||
import HomeAssistant.Runtime.Bus
|
||||
import Katip (Namespace (Namespace), runKatipContextT)
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "Bus" $ do
|
||||
it "broadcasts inbound messages to every dup'd channel in order" $ do
|
||||
bus <- newBus 0
|
||||
it "broadcasts inbound messages to every dup'd channel in order" $ withBus $ \bus -> do
|
||||
p1 <- atomically $ dupTChan (busInbound bus)
|
||||
p2 <- atomically $ dupTChan (busInbound bus)
|
||||
atomically $ writeTChan (busInbound bus) (Number 1)
|
||||
@@ -26,10 +29,11 @@ spec = describe "Bus" $ do
|
||||
r1 `shouldBe` (Number 1, Number 2)
|
||||
r2 `shouldBe` (Number 1, Number 2)
|
||||
|
||||
it "channelHassEval writes CallService to the outbound channel" $ do
|
||||
bus <- newBus 0
|
||||
let svc = Service "light" "turn_on" Nothing [EntityId "light.bedroom_masse"]
|
||||
channelHassEval bus (CallService svc)
|
||||
it "channelHassEval writes CallService to the outbound channel" $ withBus $ \bus -> do
|
||||
let req = Request (UTCTime (toEnum 0) 0) nil
|
||||
svc = Service "light" "turn_on" Nothing [EntityId "light.bedroom_masse"]
|
||||
runKatipContextT (busLogEnv bus) () (Namespace ["test"]) $
|
||||
channelHassEval bus (CallService req svc)
|
||||
atomically (readTChan (busOutbound bus)) `shouldReturn` svc
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -13,8 +13,7 @@ import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "runController" $ do
|
||||
it "feeds inbound events through the machine and forwards service calls" $ do
|
||||
bus <- newBus 0
|
||||
it "feeds inbound events through the machine and forwards service calls" $ withBus $ \bus -> do
|
||||
_ <- async (runController bus (Controller "test" lightController True))
|
||||
putStrLn "Before the delay"
|
||||
threadDelay 100000 -- let the controller dup its inbound channel
|
||||
|
||||
Reference in New Issue
Block a user