Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Bulk improvements (#27)
Browse files Browse the repository at this point in the history
Bulk improvements, including:
* Expanded gitignore
* Replace deprecated error-handling functions by the recommended ones from the `exceptions` package
* Updated changelog
* Test suite and GIthub Actions-based continuous integration
  • Loading branch information
LaurentRDC authored Mar 25, 2024
1 parent cabcecb commit 06ce2e9
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 53 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 22 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.*
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> 0.2.4

* Update dependency bounds to build with ghc-8.2.1.
Expand Down
12 changes: 12 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -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
24 changes: 12 additions & 12 deletions distributed-process-simplelocalnet.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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
4 changes: 1 addition & 3 deletions src/Control/Distributed/Process/Backend/SimpleLocalnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import Data.Typeable (Typeable)
import Control.Applicative ((<$>))

Check warning on line 105 in src/Control/Distributed/Process/Backend/SimpleLocalnet.hs

View workflow job for this annotation

GitHub Actions / continuous-integration (9.0.2)

The import of ‘Control.Applicative’ is redundant

Check warning on line 105 in src/Control/Distributed/Process/Backend/SimpleLocalnet.hs

View workflow job for this annotation

GitHub Actions / continuous-integration (9.2.8)

The import of ‘Control.Applicative’ is redundant

Check warning on line 105 in src/Control/Distributed/Process/Backend/SimpleLocalnet.hs

View workflow job for this annotation

GitHub Actions / continuous-integration (9.4.5)

The import of ‘Control.Applicative’ is redundant

Check warning on line 105 in src/Control/Distributed/Process/Backend/SimpleLocalnet.hs

View workflow job for this annotation

GitHub Actions / continuous-integration (9.6.4)

The import of ‘Control.Applicative’ is redundant

Check warning on line 105 in src/Control/Distributed/Process/Backend/SimpleLocalnet.hs

View workflow job for this annotation

GitHub Actions / continuous-integration (9.8.2)

The import of ‘Control.Applicative’ is redundant
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_)
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/Main.hs
Original file line number Diff line number Diff line change
@@ -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)


24 changes: 0 additions & 24 deletions tests/TestSimpleLocalnet.hs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/runTestSimpleLocalnet.sh

This file was deleted.

0 comments on commit 06ce2e9

Please sign in to comment.