Skip to content

Commit

Permalink
Merge pull request #459 from symbiont-io/course
Browse files Browse the repository at this point in the history
course
  • Loading branch information
symbiont-stevan-andjelkovic authored Feb 3, 2022
2 parents 17fe814 + 3fc2cea commit 320e717
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions doc/advanced-testing-mini-course/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

0. Assume familiarity with Haskell and QuickCheck
1. State machine testing
- Pre-conditions
- Coverage
- Execution trace for counterexamples
- Regression tests from counterexamples
- Metrics
- References?
2. Consumer-driven contract tests using state machines
Expand All @@ -16,9 +19,9 @@

```haskell
data Network = Network
{ deploy :: Addr -> IO Socket -- bind and listen
, send :: [(Addr, Msg)] -> IO ()
, select :: [Socket] -> IO (Addr, Msg, Time) -- accept and recv
{ deploy :: Addr -> IO () -- bind and listen
, connect :: Addr -> IO ()
, select :: [(Addr, Msg)] -> IO (Addr, Msg, Time) -- send, accept and recv
}

eventLoop :: Network -> [(Addr, StateMachine)] -> IO ()
Expand All @@ -27,26 +30,30 @@ eventLoop nw nodes = do
connectAllNodesToEachOther nw nodes
-- ^ Or do this as part of creating `Network`.
let env = nodes `zip` initialStates
go env
go env []
where
go env = do
(receiver, msg, time) <- select socks
(outgoing, env') <- step env receiver msg time
send nw outgoing
go env'
go env outgoing = do
(receiver, msg, time) <- select outgoing
(outgoing', env') <- step env receiver msg time
go env' outgoing'

fakeSend :: Heap -> Addr -> Msg -> (Heap, ())
fakeSend heap addr msg = do
t <- genArrivalTime
(enqueue (addr, msg, t) heap, ())

fakeRecv :: Heap -> (Heap, (Addr, Msg, Time))
fakeRecv = dequeue -- XXX: partial function

newFakeNetwork :: IO Network
newFakeNetwork = do
heap <- newIORef emptyHeap
let send = do
let select outgoing = do
h <- readIORef heap
let (h', ()) = fakeSend h
writeIORef heap h'
let h' = fakeSendAll h outgoing
(h'', incoming) = fakeRecv h'
writeIORef heap h''
return incoming
...
return Network {..}
```

0 comments on commit 320e717

Please sign in to comment.