-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{-# OPTIONS -XOverloadedStrings #-} | ||
|
||
module BasicRejectSpec (main, spec) where | ||
|
||
import Test.Hspec | ||
import Network.AMQP | ||
|
||
import Data.ByteString.Lazy.Char8 as L8 | ||
import Control.Concurrent (threadDelay) | ||
import Control.Exception (bracket) | ||
|
||
main :: IO () | ||
main = hspec spec | ||
|
||
withTestConnection :: (Channel -> IO c) -> IO c | ||
withTestConnection job = do | ||
bracket (openConnection "127.0.0.1" "/" "guest" "guest") closeConnection $ \conn -> do | ||
ch <- openChannel conn | ||
job ch | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "rejectMsg" $ do | ||
context "requeue = True" $ do | ||
it "requeues a message" $ withTestConnection $ \ch -> do | ||
let q = "haskell-amqp.basic.reject.with-requeue-true" | ||
|
||
(_, n1, _) <- declareQueue ch $ newQueue {queueName = q, queueDurable = False} | ||
n1 `shouldBe` 0 | ||
|
||
-- publishes using default exchange | ||
publishMsg ch "" q $ newMsg {msgBody = (L8.pack "hello")} | ||
threadDelay (1000 * 100) | ||
|
||
(_, n2, _) <- declareQueue ch (newQueue {queueName = q, queueDurable = False}) | ||
n2 `shouldBe` 1 | ||
|
||
Just (_msg, env) <- getMsg ch Ack q | ||
rejectMsg (envChannel env) (envDeliveryTag env) True | ||
threadDelay (1000 * 100) | ||
|
||
n3 <- deleteQueue ch q | ||
n3 `shouldBe` 1 | ||
|
||
context "requeue = False" $ do | ||
it "rejects a message" $ withTestConnection $ \ch -> do | ||
let q = "haskell-amqp.basic.reject.with-requeue-false" | ||
|
||
(_, n1, _) <- declareQueue ch $ newQueue {queueName = q, queueDurable = False} | ||
n1 `shouldBe` 0 | ||
|
||
-- publishes using default exchange | ||
publishMsg ch "" q $ newMsg {msgBody = (L8.pack "hello")} | ||
threadDelay (1000 * 100) | ||
|
||
(_, n2, _) <- declareQueue ch (newQueue {queueName = q, queueDurable = False}) | ||
n2 `shouldBe` 1 | ||
|
||
Just (_msg, env) <- getMsg ch Ack q | ||
rejectMsg (envChannel env) (envDeliveryTag env) False | ||
threadDelay (1000 * 100) | ||
|
||
n3 <- deleteQueue ch q | ||
n3 `shouldBe` 0 | ||
|
||
describe "rejectEnv" $ do | ||
context "requeue = True" $ do | ||
it "requeues a message" $ withTestConnection $ \ch -> do | ||
let q = "haskell-amqp.basic.reject.with-requeue-true" | ||
|
||
(_, n1, _) <- declareQueue ch $ newQueue {queueName = q, queueDurable = False} | ||
n1 `shouldBe` 0 | ||
|
||
-- publishes using default exchange | ||
publishMsg ch "" q $ newMsg {msgBody = (L8.pack "hello")} | ||
threadDelay (1000 * 100) | ||
|
||
(_, n2, _) <- declareQueue ch (newQueue {queueName = q, queueDurable = False}) | ||
n2 `shouldBe` 1 | ||
|
||
Just (_msg, env) <- getMsg ch Ack q | ||
rejectEnv env True | ||
threadDelay (1000 * 100) | ||
|
||
n3 <- deleteQueue ch q | ||
n3 `shouldBe` 1 | ||
|
||
context "requeue = False" $ do | ||
it "rejects a message" $ withTestConnection $ \ch -> do | ||
let q = "haskell-amqp.basic.reject.with-requeue-false" | ||
|
||
(_, n1, _) <- declareQueue ch $ newQueue {queueName = q, queueDurable = False} | ||
n1 `shouldBe` 0 | ||
|
||
-- publishes using default exchange | ||
publishMsg ch "" q $ newMsg {msgBody = (L8.pack "hello")} | ||
threadDelay (1000 * 100) | ||
|
||
(_, n2, _) <- declareQueue ch (newQueue {queueName = q, queueDurable = False}) | ||
n2 `shouldBe` 1 | ||
|
||
Just (_msg, env) <- getMsg ch Ack q | ||
rejectEnv env False | ||
threadDelay (1000 * 100) | ||
|
||
n3 <- deleteQueue ch q | ||
n3 `shouldBe` 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters