Broadway.test_batch
test_batch
, go back to Broadway module for more information.
Specs
Sends a list of data as a batch of messages to the Broadway pipeline.
This is a convenience used for testing. Each message is automatically
wrapped in a Broadway.Message
with Broadway.CallerAcknowledger
configured to send a message back to the caller once all batches
have been fully processed.
If there are more messages in the batch than the pipeline batch_size
or if the messages in the batch take more time to process than
batch_timeout
then the caller will receive multiple messages.
It returns a reference that can be used to identify the ack messages.
See "Testing" section in module documentation for more information.
Options
:batch_mode
- when set to:flush
, the batch the message is in is immediately delivered. When set to:bulk
, batch is delivered when its size or timeout is reached. Defaults to:bulk
.:metadata
- optionally a map of additional fields to add to the message. This can be used, for example, when testingBroadwayRabbitMQ.Producer
.:acknowledger
- optionally a function that generatesack
fields ofBroadway.Message.t()
that is sent. This function should have following spec(data :: term, {pid, reference()} -> {module, ack_ref :: term, data :: term})
. Seetest_message/3
for an example.
Examples
For example, in your tests, you may do:
ref = Broadway.test_batch(broadway, [1, 2, 3])
assert_receive {:ack, ^ref, successful, failed}, 1000
assert length(successful) == 3
assert length(failed) == 0
Note that messages sent using this function will ignore demand and :transform
option specified in :producer option in Broadway.start_link/2
.