On mocking a Flume enqueue in test env. we do not serialize the args. This is inconsistent with how the worker module receives the args on a dequeue from the queue.
Example
Operation
Flume.enqueue(:test, WorkerModule, :do_it, [%{a: 1, b: 2}])
Test env with mocks
with_flume_mock do
Flume.enqueue(:test, WorkerModule, :do_it, [%{a: 1, b: 2}])
assert_receive %{
queue: :test,
worker: WorkerModule,
function_name: :do_it,
args: [%{a: 1, b: 2}]
}
end
However, in an environment without mocks the job is serialized(Jason.encode!/1) before we enqueue it.
This may differ from a possible expectation of a worker to receive serialized arguments.
The worker module executes the following equivalent of the operation
Flume.enqueue(:test, WorkerModule, :do_it, [%{"a" => 1, "b" => 2}])
So, the assertion should actually be against a serialized-deserialized version of the arguments.
with_flume_mock do
Flume.enqueue(:test, WorkerModule, :do_it, [%{a: 1, b: 2}])
assert_receive %{
queue: :test,
worker: WorkerModule,
function_name: :do_it,
args: [%{"a" => 1, "b" => 2}]
}
end
Solution
Update the Mocked API to serialize and deserialize the arguments.
args = Jason.encode!(args) |> Jason.decode!()
On mocking a Flume enqueue in test env. we do not serialize the args. This is inconsistent with how the worker module receives the args on a dequeue from the queue.
Example
Operation
Test env with mocks
However, in an environment without mocks the job is serialized(
Jason.encode!/1) before we enqueue it.This may differ from a possible expectation of a worker to receive serialized arguments.
The worker module executes the following equivalent of the operation
So, the assertion should actually be against a serialized-deserialized version of the arguments.
Solution
Update the Mocked API to serialize and deserialize the arguments.