Conduit v0.12.10 Conduit.Test View Source

Helpers for testing receiving and publishing messages from a message queue.

The helpers in this module are intended to be used in conjunction with the Conduit.TestAdapter. When you publish a Conduit.Message with the Conduit.TestAdapter setup, it will send a message to the same process that publish on your broker, was called in.

If another process is responsible for publishing a Conduit.Message, you must:

  1. Pass [shared: true] when using Conduit.Test
  2. Pass [async: false] when using ExUnit.Case

This is necessary, because the helpers and the adapter must share configuration to know what the test process is. If async is true, multiple tests could override test process and the publish notification would go to the wrong process.

Examples

# Unit Testing
use ExUnit.Case, async: true
use Conduit.Test, shared: false

# Integration Testing
use ExUnit.Case, async: false
use Conduit.Test, shared: true

Link to this section Summary

Link to this section Functions

Link to this macro assert_message_publish(name) View Source (macro)

Asserts that a Conduit.Message will be published.

Accepts the name of the route. timeout after 100 ms.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{})
assert_message_publish(:message)
assert_message_publish(_)
Link to this macro assert_message_publish(name, timeout) View Source (macro)

Asserts that a Conduit.Message will be published.

Accepts the name of the route and a pattern for the message or a timeout for how long to wait for the message. If a message pattern is passed, timeout defaults to 100 ms.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{})
assert_message_publish(:message, 200)
assert_message_publish(:message, ^message)
Link to this macro assert_message_publish(name, message_pattern, timeout) View Source (macro)

Asserts that a Conduit.Message will be published.

Accepts the name of the route, a pattern for the message, and a pattern for the options or a timeout for how long to wait for the message. If a options pattern is passed, timeout defaults to 100 ms.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{}, to: "here")
assert_message_publish(:message, %{body: body}, 200)
assert_message_publish(:message, %{body: body}, [to: "here"])
assert_message_publish(:message, ^message, 300)
Link to this macro assert_message_publish(name, message_pattern, opts_pattern, timeout) View Source (macro)

Asserts that a Conduit.Message will be published.

Accepts the name of the route, a pattern for the message, a pattern for the options, and a timeout for how long to wait for the message.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{}, to: "here")
assert_message_publish(:message, %{body: body}, [to: "here"], 200)
assert_message_publish(:message, message, [to: "here"], 300)
assert_message_publish(:message, ^message, ^opts, 300)
Link to this macro assert_message_published(name) View Source (macro)

Asserts that a message was published.

Same as Conduit.Test.assert_message_publish/2, but with timeout set to 0.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{})
assert_message_published(:message)
Link to this macro assert_message_published(name, message_pattern) View Source (macro)

Asserts that a message was published.

Same as Conduit.Test.assert_message_publish/3, but with timeout set to 0.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{})
assert_message_published(:message, %Conduit.Message{body: body})
assert_message_published(:message, message)
assert_message_published(:message, ^message)
Link to this macro assert_message_published(name, message_pattern, opts_pattern) View Source (macro)

Asserts that a message was published with specific options.

Same as Conduit.Test.assert_message_publish/4, but with timeout set to 0.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{}, to: "queue")
assert_message_published(:message, %Conduit.Message{body: body}, [to: "queue"])
assert_message_published(:message, message, [to: destination])
assert_message_published(:message, ^message, ^opts)
Link to this macro refute_message_publish(name) View Source (macro)

Refutes that a Conduit.Message will be published.

Accepts the name of the route. Timeout defaults to 100 ms.

Examples

refute_message_publish(:message)
Link to this macro refute_message_publish(name, timeout) View Source (macro)

Refutes that a Conduit.Message will be published.

Accepts the name of the route and a pattern for the message or a timeout for how long to wait for the message. If a message pattern is passed, timeout defaults to 100 ms.

Examples

refute_message_publish(:message, 200)
refute_message_publish(:message, %{body: body})
refute_message_publish(:message, ^message)
Link to this macro refute_message_publish(name, message_pattern, timeout) View Source (macro)

Refutes that a Conduit.Message will be published.

Accepts the name of the route, a pattern for the message, and a pattern for options or a timeout for how long to wait for the message. If a options pattern is passed, timeout defaults to 100 ms.

Examples

refute_message_publish(:message, %Conduit.Message{}, 200)
refute_message_publish(:message, %{body: body}, [to: "elsewhere"])
refute_message_publish(:message, ^message, ^options)
Link to this macro refute_message_publish(name, message_pattern, opts_pattern, timeout) View Source (macro)

Refutes that a Conduit.Message will be published.

Accepts the name of the route, a pattern for the message, a pattern for options, and a timeout for how long to wait for the message.

Examples

refute_message_publish(:message, %Conduit.Message{}, [to: "elsewhere"], 200)
refute_message_publish(:message, %{body: body}, [to: "elsewhere"], 10)
refute_message_publish(:message, ^message, ^options, 50)
Link to this macro refute_message_published(name) View Source (macro)

Refutes that a Conduit.Message was published.

Same as Conduit.Test.refute_message_publish/2, but with timeout set to 0.

Examples

refute_message_published(:message)
refute_message_published(_)
Link to this macro refute_message_published(name, message_pattern) View Source (macro)

Refutes that a Conduit.Message was published.

Same as Conduit.Test.refute_message_publish/3, but with timeout set to 0.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{body: "bar"})
refute_message_published(:message, %Conduit.Message{body: "foo"})
Link to this macro refute_message_published(name, message_pattern, opts_pattern) View Source (macro)

Refutes that a Conduit.Message was published with specific options.

Same as Conduit.Test.refute_message_publish/4, but with timeout set to 0.

Examples

MyApp.Broker.publish(:message, %Conduit.Message{body: "bar"}, to: "queue")
refute_message_published(:message, %Conduit.Message{body: "bar"}, to: "elsewhere")