Testing Membrane Element

I'm trying to setup a simple test of a membrane element, but I'm stumped a bit on how to assert that the element is sending the correct output. For context, this is an element that accepts an audio stream, sends it to a speech 2 text api and then forwards along a text buffer.

The test fails, as there's no 'buffer' in the mailbox. Though I'm positive that's what my element emits when the stream is complete. I've tried longer timeouts (10s) but that doesn't alter the test.

I could use some advice.

    test "Converts sample audio to text" do
      current_dir = __DIR__
      file_path = Path.join([current_dir, "../../fixtures/test.wav"])
      absolute_path = Path.expand(file_path)
      sample_audio = File.read!(absolute_path)

      expected_text =
        "Adventure 1 a scandal in Bohemia from The Adventures of Sherlock Holmes by Sir Arthur Conan Doyle. This is a LibriVox recording."

      links = [
        child(:source, %Source{output: [sample_audio], stream_format: %RawAudio{sample_format: :s16le, sample_rate: 16_000, channels: 1}})
        |> child(:speech_2_text, Speech2Text)
        |> child(:sink, %Sink{})
      ]

      options = [
        spec: links
      ]

      pipeline = Pipeline.start_link_supervised!(options)

      assert_sink_buffer(pipeline, :sink, {:buffer, %Buffer{payload: ^expected_text}}, 5_000)

      Pipeline.terminate(pipeline)
    end
24 responses