@@ -292,6 +292,16 @@ instance Arbitrary ArbitrarySDU where
292
292
instance Arbitrary Mx. BearerState where
293
293
arbitrary = elements [Mx. Mature , Mx. Dead ]
294
294
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
+ ]
295
305
296
306
297
307
-- | A pair of two bytestrings which lengths are unevenly distributed
@@ -398,8 +408,10 @@ prop_mux_snd_recv (DummyRun messages) = ioProperty $ do
398
408
-- | Like prop_mux_snd_recv but using a bidirectional mux with client and server
399
409
-- on both endpoints.
400
410
prop_mux_snd_recv_bi :: DummyRun
411
+ -> DummyCapability
412
+ -> DummyCapability
401
413
-> 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
403
415
client_w <- atomically $ newTBQueue 10
404
416
client_r <- atomically $ newTBQueue 10
405
417
@@ -430,15 +442,15 @@ prop_mux_snd_recv_bi (DummyRun messages) = ioProperty $ do
430
442
miniProtocolNum = Mx. MiniProtocolNum 2 ,
431
443
miniProtocolDir = Mx. ResponderDirection ,
432
444
miniProtocolLimits = defaultMiniProtocolLimits,
433
- miniProtocolCapability = Nothing
445
+ miniProtocolCapability = clientCap
434
446
}
435
447
]
436
448
437
449
serverApps = [ MiniProtocolInfo {
438
450
miniProtocolNum = Mx. MiniProtocolNum 2 ,
439
451
miniProtocolDir = Mx. ResponderDirection ,
440
452
miniProtocolLimits = defaultMiniProtocolLimits,
441
- miniProtocolCapability = Nothing
453
+ miniProtocolCapability = serverCap
442
454
}
443
455
, MiniProtocolInfo {
444
456
miniProtocolNum = Mx. MiniProtocolNum 2 ,
@@ -724,12 +736,13 @@ type RunMuxApplications
724
736
-> IO Bool
725
737
726
738
727
- runMuxApplication :: [Mx. ByteChannel IO -> IO (Bool , Maybe BL. ByteString )]
739
+ runMuxApplication :: DummyCapability
740
+ -> [Mx. ByteChannel IO -> IO (Bool , Maybe BL. ByteString )]
728
741
-> Mx. Bearer IO
729
742
-> [Mx. ByteChannel IO -> IO (Bool , Maybe BL. ByteString )]
730
743
-> Mx. Bearer IO
731
744
-> IO Bool
732
- runMuxApplication initApps initBearer respApps respBearer = do
745
+ runMuxApplication ( DummyCapability rspCap) initApps initBearer respApps respBearer = do
733
746
let clientTracer = contramap (Mx. WithBearer " client" ) activeTracer
734
747
serverTracer = contramap (Mx. WithBearer " server" ) activeTracer
735
748
protNum = [1 .. ]
@@ -741,7 +754,7 @@ runMuxApplication initApps initBearer respApps respBearer = do
741
754
miniProtocolNum = Mx. MiniProtocolNum pn,
742
755
miniProtocolDir = Mx. ResponderDirectionOnly ,
743
756
miniProtocolLimits = defaultMiniProtocolLimits,
744
- miniProtocolCapability = Nothing
757
+ miniProtocolCapability = rspCap
745
758
}
746
759
)
747
760
respApps'
@@ -790,8 +803,9 @@ runMuxApplication initApps initBearer respApps respBearer = do
790
803
(Left _) -> return False
791
804
(Right b) -> return b
792
805
793
- runWithQueues :: RunMuxApplications
794
- runWithQueues initApps respApps = do
806
+ runWithQueues :: DummyCapability
807
+ -> RunMuxApplications
808
+ runWithQueues cap initApps respApps = do
795
809
client_w <- atomically $ newTBQueue 10
796
810
client_r <- atomically $ newTBQueue 10
797
811
let server_w = client_r
@@ -810,10 +824,11 @@ runWithQueues initApps respApps = do
810
824
serverTracer
811
825
QueueChannel { writeQueue = server_w, readQueue = server_r }
812
826
Nothing
813
- runMuxApplication initApps clientBearer respApps serverBearer
827
+ runMuxApplication cap initApps clientBearer respApps serverBearer
814
828
815
- runWithPipe :: RunMuxApplications
816
- runWithPipe initApps respApps =
829
+ runWithPipe :: DummyCapability
830
+ -> RunMuxApplications
831
+ runWithPipe cap initApps respApps =
817
832
#if defined(mingw32_HOST_OS)
818
833
withIOManager $ \ ioManager -> do
819
834
let pipeName = " \\\\ .\\ pipe\\ mux-test-pipe"
@@ -849,7 +864,7 @@ runWithPipe initApps respApps =
849
864
serverBearer <- getBearer makePipeChannelBearer (- 1 ) serverTracer serverChannel Nothing
850
865
851
866
Win32.Async. connectNamedPipe hSrv
852
- runMuxApplication initApps clientBearer respApps serverBearer
867
+ runMuxApplication cap initApps clientBearer respApps serverBearer
853
868
#else
854
869
bracket
855
870
((,) <$> createPipe <*> createPipe)
@@ -864,15 +879,18 @@ runWithPipe initApps respApps =
864
879
865
880
clientBearer <- getBearer makePipeChannelBearer (- 1 ) clientTracer clientChannel Nothing
866
881
serverBearer <- getBearer makePipeChannelBearer (- 1 ) serverTracer serverChannel Nothing
867
- runMuxApplication initApps clientBearer respApps serverBearer
882
+ runMuxApplication cap initApps clientBearer respApps serverBearer
868
883
869
884
#endif
870
885
where
871
886
clientTracer = contramap (Mx. WithBearer " client" ) activeTracer
872
887
serverTracer = contramap (Mx. WithBearer " server" ) activeTracer
873
888
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
876
894
bracket
877
895
(do
878
896
sd <- Socket. socket Socket. AF_INET Socket. Stream Socket. defaultProtocol
@@ -897,7 +915,7 @@ runWithSocket clientBuf_m serverBuf_m initApps respApps = withIOManager (\iocp -
897
915
clientB <- mkBearer clientBuf_m cd clientTracer
898
916
serverB <- mkBearer serverBuf_m sd serverTracer
899
917
900
- runMuxApplication initApps clientB respApps serverB
918
+ runMuxApplication cap initApps clientB respApps serverB
901
919
)
902
920
)
903
921
where
@@ -916,18 +934,18 @@ test_mux_1_mini run msgTrace = do
916
934
run [clientApp] [serverApp]
917
935
918
936
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)
921
939
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)
924
942
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 )
927
945
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))
931
949
932
950
-- | Verify that it is possible to run two miniprotocols over the same bearer.
933
951
-- Makes sure that messages are delivered to the correct miniprotocol in order.
@@ -945,27 +963,31 @@ test_mux_2_minis run msgTrace0 msgTrace1 = do
945
963
run [clientApp0, clientApp1] [serverApp0, serverApp1]
946
964
947
965
948
- prop_mux_2_minis_Queue :: DummyTrace
966
+ prop_mux_2_minis_Queue :: DummyCapability
967
+ -> DummyTrace
949
968
-> DummyTrace
950
969
-> 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
957
971
958
- prop_mux_2_minis_Socket :: DummyTrace
972
+ prop_mux_2_minis_Pipe :: DummyCapability
959
973
-> 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
964
974
-> DummyTrace
965
975
-> 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 $
967
989
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))
969
991
970
992
-- | Attempt to verify that capacity is diveded fairly between two active
971
993
-- miniprotocols. Two initiators send a request over two different
0 commit comments