@@ -292,6 +292,16 @@ instance Arbitrary ArbitrarySDU where
292292instance Arbitrary Mx. BearerState where
293293 arbitrary = elements [Mx. Mature , Mx. Dead ]
294294
295+ newtype DummyCapability = DummyCapability {
296+ unDummyCapability :: Maybe Int
297+ } deriving (Eq , Show )
298+
299+ instance Arbitrary DummyCapability where
300+ arbitrary =
301+ frequency [ (1 , return $ DummyCapability Nothing )
302+ , (8 , (DummyCapability . Just ) <$> choose (0 , 7 ))
303+ , (1 , (DummyCapability . Just ) <$> arbitrary)
304+ ]
295305
296306
297307-- | A pair of two bytestrings which lengths are unevenly distributed
@@ -398,8 +408,10 @@ prop_mux_snd_recv (DummyRun messages) = ioProperty $ do
398408-- | Like prop_mux_snd_recv but using a bidirectional mux with client and server
399409-- on both endpoints.
400410prop_mux_snd_recv_bi :: DummyRun
411+ -> DummyCapability
412+ -> DummyCapability
401413 -> Property
402- prop_mux_snd_recv_bi (DummyRun messages) = ioProperty $ do
414+ prop_mux_snd_recv_bi (DummyRun messages) ( DummyCapability clientCap) ( DummyCapability serverCap) = ioProperty $ do
403415 client_w <- atomically $ newTBQueue 10
404416 client_r <- atomically $ newTBQueue 10
405417
@@ -430,15 +442,15 @@ prop_mux_snd_recv_bi (DummyRun messages) = ioProperty $ do
430442 miniProtocolNum = Mx. MiniProtocolNum 2 ,
431443 miniProtocolDir = Mx. ResponderDirection ,
432444 miniProtocolLimits = defaultMiniProtocolLimits,
433- miniProtocolCapability = Nothing
445+ miniProtocolCapability = clientCap
434446 }
435447 ]
436448
437449 serverApps = [ MiniProtocolInfo {
438450 miniProtocolNum = Mx. MiniProtocolNum 2 ,
439451 miniProtocolDir = Mx. ResponderDirection ,
440452 miniProtocolLimits = defaultMiniProtocolLimits,
441- miniProtocolCapability = Nothing
453+ miniProtocolCapability = serverCap
442454 }
443455 , MiniProtocolInfo {
444456 miniProtocolNum = Mx. MiniProtocolNum 2 ,
@@ -724,12 +736,13 @@ type RunMuxApplications
724736 -> IO Bool
725737
726738
727- runMuxApplication :: [Mx. ByteChannel IO -> IO (Bool , Maybe BL. ByteString )]
739+ runMuxApplication :: DummyCapability
740+ -> [Mx. ByteChannel IO -> IO (Bool , Maybe BL. ByteString )]
728741 -> Mx. Bearer IO
729742 -> [Mx. ByteChannel IO -> IO (Bool , Maybe BL. ByteString )]
730743 -> Mx. Bearer IO
731744 -> IO Bool
732- runMuxApplication initApps initBearer respApps respBearer = do
745+ runMuxApplication ( DummyCapability rspCap) initApps initBearer respApps respBearer = do
733746 let clientTracer = contramap (Mx. WithBearer " client" ) activeTracer
734747 serverTracer = contramap (Mx. WithBearer " server" ) activeTracer
735748 protNum = [1 .. ]
@@ -741,7 +754,7 @@ runMuxApplication initApps initBearer respApps respBearer = do
741754 miniProtocolNum = Mx. MiniProtocolNum pn,
742755 miniProtocolDir = Mx. ResponderDirectionOnly ,
743756 miniProtocolLimits = defaultMiniProtocolLimits,
744- miniProtocolCapability = Nothing
757+ miniProtocolCapability = rspCap
745758 }
746759 )
747760 respApps'
@@ -790,8 +803,9 @@ runMuxApplication initApps initBearer respApps respBearer = do
790803 (Left _) -> return False
791804 (Right b) -> return b
792805
793- runWithQueues :: RunMuxApplications
794- runWithQueues initApps respApps = do
806+ runWithQueues :: DummyCapability
807+ -> RunMuxApplications
808+ runWithQueues cap initApps respApps = do
795809 client_w <- atomically $ newTBQueue 10
796810 client_r <- atomically $ newTBQueue 10
797811 let server_w = client_r
@@ -810,10 +824,11 @@ runWithQueues initApps respApps = do
810824 serverTracer
811825 QueueChannel { writeQueue = server_w, readQueue = server_r }
812826 Nothing
813- runMuxApplication initApps clientBearer respApps serverBearer
827+ runMuxApplication cap initApps clientBearer respApps serverBearer
814828
815- runWithPipe :: RunMuxApplications
816- runWithPipe initApps respApps =
829+ runWithPipe :: DummyCapability
830+ -> RunMuxApplications
831+ runWithPipe cap initApps respApps =
817832#if defined(mingw32_HOST_OS)
818833 withIOManager $ \ ioManager -> do
819834 let pipeName = " \\\\ .\\ pipe\\ mux-test-pipe"
@@ -849,7 +864,7 @@ runWithPipe initApps respApps =
849864 serverBearer <- getBearer makePipeChannelBearer (- 1 ) serverTracer serverChannel Nothing
850865
851866 Win32.Async. connectNamedPipe hSrv
852- runMuxApplication initApps clientBearer respApps serverBearer
867+ runMuxApplication cap initApps clientBearer respApps serverBearer
853868#else
854869 bracket
855870 ((,) <$> createPipe <*> createPipe)
@@ -864,15 +879,18 @@ runWithPipe initApps respApps =
864879
865880 clientBearer <- getBearer makePipeChannelBearer (- 1 ) clientTracer clientChannel Nothing
866881 serverBearer <- getBearer makePipeChannelBearer (- 1 ) serverTracer serverChannel Nothing
867- runMuxApplication initApps clientBearer respApps serverBearer
882+ runMuxApplication cap initApps clientBearer respApps serverBearer
868883
869884#endif
870885 where
871886 clientTracer = contramap (Mx. WithBearer " client" ) activeTracer
872887 serverTracer = contramap (Mx. WithBearer " server" ) activeTracer
873888
874- runWithSocket :: Maybe (Mx. ReadBuffer IO ) -> Maybe (Mx. ReadBuffer IO ) -> RunMuxApplications
875- runWithSocket clientBuf_m serverBuf_m initApps respApps = withIOManager (\ iocp -> do
889+ runWithSocket :: DummyCapability
890+ -> Maybe (Mx. ReadBuffer IO )
891+ -> Maybe (Mx. ReadBuffer IO )
892+ -> RunMuxApplications
893+ runWithSocket cap clientBuf_m serverBuf_m initApps respApps = withIOManager (\ iocp -> do
876894 bracket
877895 (do
878896 sd <- Socket. socket Socket. AF_INET Socket. Stream Socket. defaultProtocol
@@ -897,7 +915,7 @@ runWithSocket clientBuf_m serverBuf_m initApps respApps = withIOManager (\iocp -
897915 clientB <- mkBearer clientBuf_m cd clientTracer
898916 serverB <- mkBearer serverBuf_m sd serverTracer
899917
900- runMuxApplication initApps clientB respApps serverB
918+ runMuxApplication cap initApps clientB respApps serverB
901919 )
902920 )
903921 where
@@ -916,18 +934,18 @@ test_mux_1_mini run msgTrace = do
916934 run [clientApp] [serverApp]
917935
918936
919- prop_mux_1_mini_Queue :: DummyTrace -> Property
920- prop_mux_1_mini_Queue = ioProperty . test_mux_1_mini runWithQueues
937+ prop_mux_1_mini_Queue :: DummyCapability -> DummyTrace -> Property
938+ prop_mux_1_mini_Queue cap = ioProperty . test_mux_1_mini ( runWithQueues cap)
921939
922- prop_mux_1_mini_Pipe :: DummyTrace -> Property
923- prop_mux_1_mini_Pipe = ioProperty . test_mux_1_mini runWithPipe
940+ prop_mux_1_mini_Pipe :: DummyCapability -> DummyTrace -> Property
941+ prop_mux_1_mini_Pipe cap = ioProperty . test_mux_1_mini ( runWithPipe cap)
924942
925- prop_mux_1_mini_Socket :: DummyTrace -> Property
926- prop_mux_1_mini_Socket = ioProperty . test_mux_1_mini (runWithSocket Nothing Nothing )
943+ prop_mux_1_mini_Socket :: DummyCapability -> DummyTrace -> Property
944+ prop_mux_1_mini_Socket cap = ioProperty . test_mux_1_mini (runWithSocket cap Nothing Nothing )
927945
928- prop_mux_1_mini_Socket_buf :: DummyTrace -> Property
929- prop_mux_1_mini_Socket_buf dt = ioProperty $ withReadBufferIO (\ buf_a -> withReadBufferIO (\ buf_b ->
930- test_mux_1_mini (runWithSocket buf_a buf_b) dt))
946+ prop_mux_1_mini_Socket_buf :: DummyCapability -> DummyTrace -> Property
947+ prop_mux_1_mini_Socket_buf cap dt = ioProperty $ withReadBufferIO (\ buf_a -> withReadBufferIO (\ buf_b ->
948+ test_mux_1_mini (runWithSocket cap buf_a buf_b) dt))
931949
932950-- | Verify that it is possible to run two miniprotocols over the same bearer.
933951-- Makes sure that messages are delivered to the correct miniprotocol in order.
@@ -945,27 +963,31 @@ test_mux_2_minis run msgTrace0 msgTrace1 = do
945963 run [clientApp0, clientApp1] [serverApp0, serverApp1]
946964
947965
948- prop_mux_2_minis_Queue :: DummyTrace
966+ prop_mux_2_minis_Queue :: DummyCapability
967+ -> DummyTrace
949968 -> DummyTrace
950969 -> Property
951- prop_mux_2_minis_Queue a b = ioProperty $ test_mux_2_minis runWithQueues a b
952-
953- prop_mux_2_minis_Pipe :: DummyTrace
954- -> DummyTrace
955- -> Property
956- prop_mux_2_minis_Pipe a b = ioProperty $ test_mux_2_minis runWithPipe a b
970+ prop_mux_2_minis_Queue cap a b = ioProperty $ test_mux_2_minis (runWithQueues cap) a b
957971
958- prop_mux_2_minis_Socket :: DummyTrace
972+ prop_mux_2_minis_Pipe :: DummyCapability
959973 -> DummyTrace
960- -> Property
961- prop_mux_2_minis_Socket a b = ioProperty $ test_mux_2_minis (runWithSocket Nothing Nothing ) a b
962-
963- prop_mux_2_minis_Socket_buf :: DummyTrace
964974 -> DummyTrace
965975 -> Property
966- prop_mux_2_minis_Socket_buf a b = ioProperty $
976+ prop_mux_2_minis_Pipe cap a b = ioProperty $ test_mux_2_minis (runWithPipe cap) a b
977+
978+ prop_mux_2_minis_Socket :: DummyCapability
979+ -> DummyTrace
980+ -> DummyTrace
981+ -> Property
982+ prop_mux_2_minis_Socket cap a b = ioProperty $ test_mux_2_minis (runWithSocket cap Nothing Nothing ) a b
983+
984+ prop_mux_2_minis_Socket_buf :: DummyCapability
985+ -> DummyTrace
986+ -> DummyTrace
987+ -> Property
988+ prop_mux_2_minis_Socket_buf cap a b = ioProperty $
967989 withReadBufferIO (\ buf_a -> withReadBufferIO (\ buf_b ->
968- test_mux_2_minis (runWithSocket buf_a buf_b) a b))
990+ test_mux_2_minis (runWithSocket cap buf_a buf_b) a b))
969991
970992-- | Attempt to verify that capacity is diveded fairly between two active
971993-- miniprotocols. Two initiators send a request over two different
0 commit comments