From 82a860ad4b7c9bdbac59c9d2f92f72499bc2fd12 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Mon, 4 Mar 2024 10:20:00 -0800 Subject: [PATCH] Added test from before that I forgor --- test/pinchflat/tasks/source_tasks_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/pinchflat/tasks/source_tasks_test.exs b/test/pinchflat/tasks/source_tasks_test.exs index 7f5e988..21ec0ce 100644 --- a/test/pinchflat/tasks/source_tasks_test.exs +++ b/test/pinchflat/tasks/source_tasks_test.exs @@ -220,6 +220,25 @@ defmodule Pinchflat.Tasks.SourceTasksTest do SourceTasks.index_and_enqueue_download_for_media_items(source) refute_enqueued(worker: VideoDownloadWorker) end + + test "does not enqueue multiple download jobs for the same media items", %{source: source} do + watcher_poll_interval = Application.get_env(:pinchflat, :file_watcher_poll_interval) + + stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot, addl_opts -> + filepath = Keyword.get(addl_opts, :output_filepath) + File.write(filepath, source_attributes_return_fixture()) + + # Need to add a delay to ensure the file watcher has time to read the file + :timer.sleep(watcher_poll_interval * 2) + # This also returns the final result to the yt-dlp call (like the real usage actually would do) + # so it'll attempt to create the media items and enqueue the download jobs based on this as well + {:ok, source_attributes_return_fixture()} + end) + + SourceTasks.index_and_enqueue_download_for_media_items(source) + assert Repo.aggregate(MediaItem, :count, :id) == 3 + assert [_, _, _] = all_enqueued(worker: VideoDownloadWorker) + end end describe "enqueue_pending_media_tasks/1" do