Skip to content

Commit

Permalink
modify test + fix dialyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
jondthomas committed Dec 10, 2024
1 parent a21fcaf commit 7560c0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/kafee/consumer/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Kafee.Consumer.Adapter do
end
"""
@spec push_message(atom(), Kafee.Consumer.options(), Message.t()) :: :ok | {:error, any()}
@spec push_message(atom(), Kafee.Consumer.options(), Message.t()) :: :ok | {:error, Exception.t()}
def push_message(consumer, options, %Message{} = message) do
Message.set_logger_metadata(message)

Expand Down
11 changes: 6 additions & 5 deletions lib/kafee/consumer/broadway_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ defmodule Kafee.Consumer.BroadwayAdapter do
Enum.map(messages, &Broadway.Message.failed(&1, reason))
end

# Dialyzer can't recognize that :ok is a valid return type for this function
# due to the rescue clause in push_message/3
@dialyzer {:nowarn_function, do_consumer_work: 3}
defp do_consumer_work(
%Broadway.Message{
data: value,
Expand All @@ -262,11 +265,9 @@ defmodule Kafee.Consumer.BroadwayAdapter do
}
)

with :ok <- result do
message
else
error ->
Broadway.Message.failed(message, error)
case result do
:ok -> message
error -> Broadway.Message.failed(message, error)
end
catch
kind, reason ->
Expand Down
3 changes: 2 additions & 1 deletion test/kafee/consumer/broadway_adapter_integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ defmodule Kafee.Consumer.BroadwayAdapterIntegrationTest do
# assert they were done asynchronously
assert 100 == task_pids |> Enum.uniq() |> length

assert_receive {:error_reason, "%RuntimeError{message: \"Error handling a message for key-fail-1\"}"}
assert_receive message
IO.inspect(message)

Check warning on line 132 in test/kafee/consumer/broadway_adapter_integration_test.exs

View workflow job for this annotation

GitHub Actions / Credo

There should be no calls to IO.inspect/1.
assert_receive {:error_reason, "%RuntimeError{message: \"Error handling a message for key-fail-2\"}"}
end
end
Expand Down

0 comments on commit 7560c0a

Please sign in to comment.