Skip to content

Commit

Permalink
connection-manager: simulation test
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed Oct 27, 2021
1 parent fec0edd commit 726ae5e
Show file tree
Hide file tree
Showing 4 changed files with 2,337 additions and 3 deletions.
Expand Up @@ -112,7 +112,8 @@ test-suite test
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: test
other-modules: Test.Ouroboros.Network.Driver
other-modules: Test.Ouroboros.Network.ConnectionManager
Test.Ouroboros.Network.Driver
Test.Ouroboros.Network.Orphans
Test.Ouroboros.Network.Server2
Test.Ouroboros.Network.Socket
Expand All @@ -129,6 +130,7 @@ test-suite test
, network
, serialise
, time
, quiet

, QuickCheck
, tasty
Expand All @@ -141,6 +143,7 @@ test-suite test
, io-classes
, network-mux
, ouroboros-network-framework
, ouroboros-network-testing
, typed-protocols
, typed-protocols-cborg
, typed-protocols-examples
Expand Down
16 changes: 16 additions & 0 deletions ouroboros-network-framework/src/Ouroboros/Network/Snocket.hs
Expand Up @@ -24,6 +24,7 @@ module Ouroboros.Network.Snocket
, LocalSocket (..)
, LocalAddress (..)
, localAddressFromPath
, TestAddress (..)

, FileDescriptor
, socketFileDescriptor
Expand All @@ -37,6 +38,7 @@ import Control.Tracer (Tracer)
import Data.Bifunctor (Bifunctor (..))
import Data.Bifoldable (Bifoldable (..))
import Data.Hashable
import Data.Typeable (Typeable)
import Data.Word
import GHC.Generics (Generic)
import Quiet (Quiet (..))
Expand Down Expand Up @@ -189,8 +191,16 @@ newtype LocalAddress = LocalAddress { getFilePath :: FilePath }
instance Hashable LocalAddress where
hashWithSalt s (LocalAddress path) = hashWithSalt s path

newtype TestAddress addr = TestAddress { getTestAddress :: addr }
deriving (Eq, Ord, Generic, Typeable)
deriving Show via Quiet (TestAddress addr)

-- | We support either sockets or named pipes.
--
-- There are three families of addresses: 'SocketFamily' usef for Berkeley
-- sockets, 'LocalFamily' used for 'LocalAddress'es (either Unix sockets or
-- Windows named pipe addresses), and 'TestFamily' for testing purposes.
--
-- 'LocalFamily' requires 'LocalAddress', this is needed to provide path of the
-- opened Win32 'HANDLE'.
--
Expand All @@ -201,6 +211,12 @@ data AddressFamily addr where

LocalFamily :: !LocalAddress -> AddressFamily LocalAddress

-- | Using a newtype wrapper 'TestAddress' makes pattern matches on
-- @AddressFamily@ complete, e.g. it makes 'AddressFamily' injective:
-- @AddressFamily addr == AddressFamily addr'@ then @addr == addr'@. .
--
TestFamily :: AddressFamily (TestAddress addr)

deriving instance Eq addr => Eq (AddressFamily addr)
deriving instance Show addr => Show (AddressFamily addr)

Expand Down
6 changes: 4 additions & 2 deletions ouroboros-network-framework/test/Main.hs
Expand Up @@ -2,8 +2,9 @@ module Main (main) where

import Test.Tasty

import qualified Test.Ouroboros.Network.Server2 as Server2
import qualified Test.Ouroboros.Network.ConnectionManager as ConnectionManager
import qualified Test.Ouroboros.Network.Driver as Driver
import qualified Test.Ouroboros.Network.Server2 as Server2
import qualified Test.Ouroboros.Network.Socket as Socket
import qualified Test.Ouroboros.Network.Subscription as Subscription
import qualified Test.Ouroboros.Network.RateLimiting as RateLimiting
Expand All @@ -14,7 +15,8 @@ main = defaultMain tests
tests :: TestTree
tests =
testGroup "ouroboros-network-framework"
[ Driver.tests
[ ConnectionManager.tests
, Driver.tests
, Server2.tests
, Socket.tests
, Subscription.tests
Expand Down

0 comments on commit 726ae5e

Please sign in to comment.