diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c7233c4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: Continuous Integration + +on: [push, pull_request] + +jobs: + continuous-integration: + strategy: + matrix: + ghc-version: + - "9.0.2" + - "9.2.8" + - "9.4.5" + - "9.6.4" + - "9.8.2" + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install cabal/ghc + uses: haskell-actions/setup@v2 + id: setup-haskell + with: + ghc-version: ${{ matrix.ghc-version }} + cabal-version: '3.10.3.0' + + - name: Generate freeze file + run: | + cabal update + cabal configure --disable-optimization + cabal freeze + # 'cabal freeze' will use the nearest index state which might not be exactly equal + # to the index state specified in 'cabal.project' + sed '/^index-state: /d' cabal.project.freeze > dependencies-versions + + - name: Cache cabal work + uses: actions/cache@v4 + with: + path: | + dist-newstyle + ${{ steps.setup-haskell.outputs.cabal-store }} + # We are using the hash of 'cabal.project.local' so that different levels + # of optimizations are cached separately + key: ${{ runner.os }}-${{ hashFiles('dependencies-versions', 'cabal.project', 'cabal.project.local') }}-cabal-install + + - name: Build dependencies only + run: | + cabal build --enable-tests --only-dependencies + + - name: Build this package + run: | + cabal build --enable-tests + + - name: Run tests + run: | + cabal test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6f75fb7..db30022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,23 @@ -dist/ -.cabal-sandbox +dist +dist-* +cabal-dev +*.o +*.hi +*.hie +*.chi +*.chs.h +*.dyn_o +*.dyn_hi +.hpc +.hsenv +.cabal-sandbox/ cabal.sandbox.config -.stack* +*.prof +*.aux +*.hp +*.eventlog +.stack-work/ +cabal.project.local +cabal.project.local~ +.HTF/ +.ghc.environment.* \ No newline at end of file diff --git a/ChangeLog b/ChangeLog index 13ec498..8170195 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +unreleased 0.3.0 + +* Breaking change: update dependency bounds to require network-3.0. +* Use various functions from the `exceptions` package instead of the deprecated ones from `distributed-process`. + 2017-08-22 Facundo Domínguez 0.2.4 * Update dependency bounds to build with ghc-8.2.1. diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..f689149 --- /dev/null +++ b/cabal.project @@ -0,0 +1,12 @@ +packages: *.cabal + +test-show-details: streaming +tests: True + +-- We require a version of distributed-process which is +-- support a wider range of dependency versions, notably for +-- `hashable` +source-repository-package + type: git + location: https://github.com/haskell-distributed/distributed-process + tag: fe963293cd82afcbba61fc877ba2a6137cbaf469 \ No newline at end of file diff --git a/distributed-process-simplelocalnet.cabal b/distributed-process-simplelocalnet.cabal index 3bbc1b8..db9736a 100644 --- a/distributed-process-simplelocalnet.cabal +++ b/distributed-process-simplelocalnet.cabal @@ -1,5 +1,5 @@ Name: distributed-process-simplelocalnet -Version: 0.2.4 +Version: 0.3.0 Cabal-Version: >=1.8 Build-Type: Simple License: BSD3 @@ -23,13 +23,10 @@ Source-Repository head Type: git Location: https://github.com/haskell-distributed/distributed-process-simplelocalnet -Flag build-example - Default: False - Description: Build a simple example application - Library Build-Depends: base >= 4.4 && < 5, bytestring >= 0.9 && < 0.12, + exceptions >= 0.5 && <0.11, network >= 3.0 && < 3.2, network-multicast >= 0.1.1 && < 0.4, data-accessor >= 0.2 && < 0.3, @@ -46,10 +43,13 @@ Library ghc-options: -Wall HS-Source-Dirs: src -Executable TestSimpleLocalnet - Main-Is: TestSimpleLocalnet.hs - Build-Depends: base >= 4.4 && < 5, - distributed-process >= 0.5.0 && < 0.8, - distributed-process-simplelocalnet - ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind - HS-Source-Dirs: tests +Test-Suite SimpleLocalNet-TestSuite + Type: exitcode-stdio-1.0 + Hs-Source-Dirs: tests + Main-Is: Main.hs + ghc-options: -threaded -with-rtsopts=-N + Build-Depends: base + , distributed-process + , distributed-process-simplelocalnet + , tasty + , tasty-hunit diff --git a/src/Control/Distributed/Process/Backend/SimpleLocalnet.hs b/src/Control/Distributed/Process/Backend/SimpleLocalnet.hs index 06e9b57..6c69a38 100644 --- a/src/Control/Distributed/Process/Backend/SimpleLocalnet.hs +++ b/src/Control/Distributed/Process/Backend/SimpleLocalnet.hs @@ -105,6 +105,7 @@ import Data.Typeable (Typeable) import Control.Applicative ((<$>)) import Control.Exception (throw) import Control.Monad (forever, replicateM, replicateM_) +import Control.Monad.Catch (bracket, try, finally) import Control.Monad.IO.Class (liftIO) import Control.Concurrent (forkIO, threadDelay, ThreadId) import Control.Concurrent.MVar (MVar, newMVar, readMVar, modifyMVar_) @@ -129,13 +130,10 @@ import Control.Distributed.Process , unmonitor , NodeMonitorNotification(..) , ProcessRegistrationException - , finally , newChan , receiveChan , nsend , SendPort - , bracket - , try , send ) import qualified Control.Distributed.Process.Node as Node diff --git a/tests/Main.hs b/tests/Main.hs new file mode 100644 index 0000000..dd13e66 --- /dev/null +++ b/tests/Main.hs @@ -0,0 +1,44 @@ + + +import Control.Concurrent (forkIO, threadDelay) +import qualified Control.Concurrent.MVar as MVar +import Control.Distributed.Process (NodeId, Process, liftIO) +import Control.Distributed.Process.Node (initRemoteTable) +import Control.Distributed.Process.Backend.SimpleLocalnet +import Control.Monad (forM_) +import qualified Data.List as List +import Test.Tasty (TestTree, defaultMain, testGroup) +import Test.Tasty.HUnit (assertEqual, testCase) + +main :: IO () +main = defaultMain + $ testGroup "Test suite" + [ testDiscoverNodes + ] + +testDiscoverNodes :: TestTree +testDiscoverNodes = testCase "discover nodes" $ do + + -- Initialize slave nodes + forM_ ["10000", "10001", "10002", "10003"] $ \port -> do + backend <- initializeBackend "127.0.0.1" port initRemoteTable + _ <- forkIO $ startSlave backend + threadDelay 100000 + + -- initialize master node + discoveredNodesSlot <- MVar.newEmptyMVar + backend <- initializeBackend "127.0.0.1" "10004" initRemoteTable + startMaster backend $ \nds -> do + terminateAllSlaves backend + liftIO $ MVar.putMVar discoveredNodesSlot nds + + discoveredNodes <- (List.sort . List.nub) <$> MVar.readMVar discoveredNodesSlot + assertEqual "Discovered nodes" + [ "nid://127.0.0.1:10000:0" + , "nid://127.0.0.1:10001:0" + , "nid://127.0.0.1:10002:0" + , "nid://127.0.0.1:10003:0" + ] + (map show discoveredNodes) + + diff --git a/tests/TestSimpleLocalnet.hs b/tests/TestSimpleLocalnet.hs deleted file mode 100644 index fc9d820..0000000 --- a/tests/TestSimpleLocalnet.hs +++ /dev/null @@ -1,24 +0,0 @@ -import System.Environment (getArgs, getProgName) -import Control.Distributed.Process (NodeId, Process, liftIO) -import Control.Distributed.Process.Node (initRemoteTable) -import Control.Distributed.Process.Backend.SimpleLocalnet - -master :: Backend -> [NodeId] -> Process () -master backend slaves = do - liftIO . putStrLn $ "Slaves: " ++ show slaves - terminateAllSlaves backend - -main :: IO () -main = do - prog <- getProgName - args <- getArgs - - case args of - ["master", host, port] -> do - backend <- initializeBackend host port initRemoteTable - startMaster backend (master backend) - ["slave", host, port] -> do - backend <- initializeBackend host port initRemoteTable - startSlave backend - _ -> - putStrLn $ "usage: " ++ prog ++ " (master | slave) host port" diff --git a/tests/runTestSimpleLocalnet.sh b/tests/runTestSimpleLocalnet.sh deleted file mode 100755 index 7437430..0000000 --- a/tests/runTestSimpleLocalnet.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -TestSimpleLocalnet=dist/build/TestSimpleLocalnet/TestSimpleLocalnet -$TestSimpleLocalnet slave 127.0.0.1 8080 & -sleep 1 -$TestSimpleLocalnet slave 127.0.0.1 8081 & -sleep 1 -$TestSimpleLocalnet slave 127.0.0.1 8082 & -sleep 1 -$TestSimpleLocalnet slave 127.0.0.1 8083 & -sleep 1 -$TestSimpleLocalnet master 127.0.0.1 8084