forked from pma/amqp
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
10c50e9
commit 97f7e3f
Showing
2 changed files
with
98 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
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,46 @@ | ||
defmodule ConfirmTest do | ||
use ExUnit.Case | ||
|
||
alias AMQP.Connection | ||
alias AMQP.Channel | ||
alias AMQP.Confirm | ||
|
||
setup do | ||
{:ok, conn} = Connection.open | ||
{:ok, chan} = Channel.open(conn) | ||
:ok = Confirm.select(chan) | ||
on_exit fn -> | ||
:ok = Connection.close(conn) | ||
end | ||
{:ok, chan: chan} | ||
end | ||
|
||
describe "next_publish_seqno" do | ||
test "returns 1 whe no messages where sent", ctx do | ||
assert 1 == Confirm.next_publish_seqno(ctx[:chan]) | ||
end | ||
end | ||
|
||
describe "register_handler" do | ||
test "handler receive confirm with message seqno", ctx do | ||
seq_no = Confirm.next_publish_seqno(ctx[:chan]) | ||
:ok = AMQP.Basic.publish(ctx[:chan], "", "", "foo") | ||
:ok = Confirm.register_handler(ctx[:chan], self()) | ||
assert_receive {:basic_ack, seq_no, false} | ||
:ok = Confirm.unregister_handler(ctx[:chan]) | ||
end | ||
end | ||
|
||
describe "unregister_handler" do | ||
setup ctx do | ||
:ok = Confirm.register_handler(ctx[:chan], self()) | ||
{:ok, ctx} | ||
end | ||
|
||
test "handler no more receive confirm", ctx do | ||
:ok = Confirm.unregister_handler(ctx[:chan]) | ||
:ok = AMQP.Basic.publish(ctx[:chan], "", "", "foo") | ||
refute_receive {:basic_ack, 1, false} | ||
end | ||
end | ||
end |