defmodule Medicode.TranscriptionServerTest do @moduledoc """ Tests for Medicode.TranscriptionServer """ use Medicode.DataCase import Medicode.TranscriptionsFixtures alias Medicode.Transcriptions alias Medicode.TranscriptionServer setup do sample_file = __DIR__ |> Path.join("../../medasrdemo-Paul.mp3") |> Path.expand() transcription = transcription_fixture(%{filename: sample_file}) %{transcription: transcription} end test "transcribe and tag audio", %{transcription: transcription} do spec = {TranscriptionServer, %{transcription: transcription, name: "transcription:#{transcription.id}"}} {:ok, pid} = start_supervised(spec, restart: :transient) # NOTE: Monitoring the async process to ensure it completes # before asserting results. See https://elixirforum.com/t/whats-the-correct-way-to-handle-async-tasks-i-dont-care-about-in-an-exunit-test-error-postgrex-protocol-disconnected/36605/2 # for further explanation. ref = Process.monitor(pid) # NOTE: This timeout of 15 seconds is arbitrary and may need to be adjusted assert_receive({:DOWN, ^ref, :process, _object, _pid}, 15_000) transcription = Transcriptions.get_transcription!(transcription.id, true) assert 14 == Enum.count(transcription.chunks) end end