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.
This commit is contained in:
Claudio Ortolina
2025-09-15 07:42:03 +03:00
parent 57deea2f4c
commit 1b89f244f8
+4 -2
View File
@@ -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