summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorDaniel Schüssler <933504+DanielSchuessler@users.noreply.github.com>2018-08-31 22:38:03 +0200
committerDaniel Schüssler <933504+DanielSchuessler@users.noreply.github.com>2018-10-06 19:54:01 +0200
commite4bcc59790b4c1650a891c6a4c25e528689c44ac (patch)
tree8e6a3c7679d37d77ebf3997146ce76a1090d8203 /test
parentb9a181870ce82c309613fba17edd9fd0b78b43cc (diff)
downloadxmobar-e4bcc59790b4c1650a891c6a4c25e528689c44ac.tar.gz
xmobar-e4bcc59790b4c1650a891c6a4c25e528689c44ac.tar.bz2
Alsa plugin: Cancel reader thread (to terminate alsactl) when plugin main thread exits.
Diffstat (limited to 'test')
-rw-r--r--test/Plugins/Monitors/AlsaSpec.hs116
1 files changed, 58 insertions, 58 deletions
diff --git a/test/Plugins/Monitors/AlsaSpec.hs b/test/Plugins/Monitors/AlsaSpec.hs
index a813c1d..77845e0 100644
--- a/test/Plugins/Monitors/AlsaSpec.hs
+++ b/test/Plugins/Monitors/AlsaSpec.hs
@@ -57,83 +57,83 @@ runFakeAlsactlTest =
waiterTaskIsRunning <- newEmptyMVar :: IO (MVar ())
waiterTaskIsWaiting <- newEmptyMVar :: IO (MVar ())
- waitFunc <- getMonitorWaiter fifoPath (Just fakeAlsactlPath)
+ withMonitorWaiter fifoPath (Just fakeAlsactlPath) $ \waitFunc -> do
- let addToTimeline e = modifyMVar_ timeline (pure . (e :))
+ let addToTimeline e = modifyMVar_ timeline (pure . (e :))
- emitEvent = do
- addToTimeline EventEmitted
- hPutStrLn fifo "#17 (2,0,0,Master Playback Volume,0) VALUE"
- hFlush fifo
+ emitEvent = do
+ addToTimeline EventEmitted
+ hPutStrLn fifo "#17 (2,0,0,Master Playback Volume,0) VALUE"
+ hFlush fifo
- putNow mv val = do
- ok <- tryPutMVar mv val
- unless ok $ expectationFailure "Expected the MVar to be empty"
+ putNow mv val = do
+ ok <- tryPutMVar mv val
+ unless ok $ expectationFailure "Expected the MVar to be empty"
- simulateRunVolumeCompleted = putNow runVolumeCompleted False
+ simulateRunVolumeCompleted = putNow runVolumeCompleted False
- quitWaiter = putNow runVolumeCompleted True
+ quitWaiter = putNow runVolumeCompleted True
- waiterTaskMain = do
- addToTimeline RunVolume
- putNow waiterTaskIsRunning ()
- q <- takeMVar runVolumeCompleted
- unless q $ do
- addToTimeline Waiting
- putNow waiterTaskIsWaiting ()
- waitFunc
+ waiterTaskMain = do
+ addToTimeline RunVolume
+ putNow waiterTaskIsRunning ()
+ q <- takeMVar runVolumeCompleted
+ unless q $ do
+ addToTimeline Waiting
+ putNow waiterTaskIsWaiting ()
+ waitFunc
- waiterTaskMain
+ waiterTaskMain
- delay_ms = threadDelay . (* 1000)
+ delay_ms = threadDelay . (* 1000)
- withAsync waiterTaskMain $ \waiterTask -> do
+ withAsync waiterTaskMain $ \waiterTask -> do
- takeMVar waiterTaskIsRunning
- simulateRunVolumeCompleted
- takeMVar waiterTaskIsWaiting
- takeMVar waiterTaskIsRunning -- Waiter returns instantly once
- simulateRunVolumeCompleted
- takeMVar waiterTaskIsWaiting
-
- emitEvent
- takeMVar waiterTaskIsRunning
- simulateRunVolumeCompleted
- takeMVar waiterTaskIsWaiting
-
- let iters = 3
- burstSize = 5
-
- replicateM_ iters $ do
- emitEvent
takeMVar waiterTaskIsRunning
- -- Now more events start to accumulate during runVolume
- replicateM_ burstSize emitEvent
- delay_ms 250 -- Give the events time to go through the pipe
simulateRunVolumeCompleted
- -- runVolume completed and should run once more due to
- -- accumulated events
takeMVar waiterTaskIsWaiting
+ takeMVar waiterTaskIsRunning -- Waiter returns instantly once
+ simulateRunVolumeCompleted
+ takeMVar waiterTaskIsWaiting
+
+ emitEvent
takeMVar waiterTaskIsRunning
simulateRunVolumeCompleted
takeMVar waiterTaskIsWaiting
- emitEvent
- takeMVar waiterTaskIsRunning
- quitWaiter
+ let iters = 3
+ burstSize = 5
+
+ replicateM_ iters $ do
+ emitEvent
+ takeMVar waiterTaskIsRunning
+ -- Now more events start to accumulate during runVolume
+ replicateM_ burstSize emitEvent
+ delay_ms 250 -- Give the events time to go through the pipe
+ simulateRunVolumeCompleted
+ -- runVolume completed and should run once more due to
+ -- accumulated events
+ takeMVar waiterTaskIsWaiting
+ takeMVar waiterTaskIsRunning
+ simulateRunVolumeCompleted
+ takeMVar waiterTaskIsWaiting
+
+ emitEvent
+ takeMVar waiterTaskIsRunning
+ quitWaiter
- wait waiterTask
+ wait waiterTask
- timelineValue <- reverse <$> readMVar timeline
+ timelineValue <- reverse <$> readMVar timeline
- timelineValue `shouldBe`
- [RunVolume, Waiting, RunVolume, Waiting, EventEmitted, RunVolume, Waiting]
- ++ concat
- (replicate iters $
- [EventEmitted, RunVolume]
- ++ replicate burstSize EventEmitted
- ++ [Waiting, RunVolume, Waiting])
- ++ [EventEmitted, RunVolume]
+ timelineValue `shouldBe`
+ [RunVolume, Waiting, RunVolume, Waiting, EventEmitted, RunVolume, Waiting]
+ ++ concat
+ (replicate iters $
+ [EventEmitted, RunVolume]
+ ++ replicate burstSize EventEmitted
+ ++ [Waiting, RunVolume, Waiting])
+ ++ [EventEmitted, RunVolume]
data TimelineEntry = EventEmitted | Waiting | RunVolume
deriving(Eq)
@@ -154,4 +154,4 @@ withFifoWriteHandle fifoPath body = do
(proc "bash" ["-c", "cat >> \"$0\"", fifoPath]) {std_in = CreatePipe}
$ \(Just h) _ _ _ -> do
hSetBuffering h LineBuffering
- body h \ No newline at end of file
+ body h