Testing approach for a GenStage producer_consumer?

I have a GenStage producer_consumer that I’d like to test in isolation and I’m not sure where to start. I tried building a Flow to pipe in a known input and see what output I get, but it hangs for some reason:

test "returns results" do
    {:ok, message_builder} = MessageBuilder.start_link

    {:ok, phase_1} =
      [%{body: "test"}]
      |> Flow.from_enumerable
      |> Flow.into_stages([message_builder])

    result =
      |> Flow.from_stage
      |> Enum.to_list

    assert length(result) == 1

I’m also considering testing the handle_events function directly, but that seems like I shouldn’t be testing a private api. What is the best way to approach this?

1 Like

What if you use GenStage.stream([phase_1]) in the last part? Instead of from_stage+to_list. This is a weird usage of those APIs but it feels like it should work, can you reproduce it with a simple producer_consumer and open up a bug report? Thank you.

Thanks for your quick reply! I just submitted an issue with a sample project here: https://github.com/elixir-lang/gen_stage/issues/118.