From 1b89f244f83b4c81e89da971c225bcb4f2886561 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 15 Sep 2025 07:42:03 +0300 Subject: [PATCH] Change test to avoid timing-related failures When inserting twice, the second insertion is a no-op, due to the fact that we use `on_conflict: :nothing` in the `Repo.insert/2` call. This means that for fields generated client side like timestamps we don't get the stored values, but the client side values (which haven't been persisted). In case of the test crossing the second boundary, the second asset would be different because of the timestamps, and the test would fail. This test is better. It tests that no matter how many times we insert the same thing we always have one stored. --- test/music_library/assets_test.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/music_library/assets_test.exs b/test/music_library/assets_test.exs index e83e219d..89424cd4 100644 --- a/test/music_library/assets_test.exs +++ b/test/music_library/assets_test.exs @@ -26,8 +26,10 @@ defmodule MusicLibrary.AssetsTest do properties: %{"language" => "english"} } - assert {:ok, asset} = Assets.store(params) - assert {:ok, asset} == Assets.store(params) + assert {:ok, _} = Assets.store(params) + assert {:ok, _} = Assets.store(params) + + assert 1 = Repo.aggregate(Assets.Asset, :count, :hash) end end