diff options
author | lain <lain@soykaf.club> | 2020-09-17 13:26:04 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-09-17 13:26:04 +0200 |
commit | 7a7385092885bd3c28497828d7b8da12e769ca83 (patch) | |
tree | beee4c47c210cf4019d44e4c0b9a659c62436fe2 /test/repo_test.exs | |
parent | c4061f06ba26656a6a0e61f68c5f097930a4b054 (diff) | |
parent | c5acbf8a1bd1a14ea82610cb3f69b8ebbb3ea28b (diff) | |
download | pleroma-7a7385092885bd3c28497828d7b8da12e769ca83.tar.gz pleroma-7a7385092885bd3c28497828d7b8da12e769ca83.zip |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into alexgleason/pleroma-chat-moderation
Diffstat (limited to 'test/repo_test.exs')
-rw-r--r-- | test/repo_test.exs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/test/repo_test.exs b/test/repo_test.exs index 92e827c95..155791be2 100644 --- a/test/repo_test.exs +++ b/test/repo_test.exs @@ -37,7 +37,9 @@ defmodule Pleroma.RepoTest do test "get one-to-many assoc from repo" do user = insert(:user) - notification = refresh_record(insert(:notification, user: user)) + + notification = + refresh_record(insert(:notification, user: user, activity: insert(:note_activity))) assert Repo.get_assoc(user, :notifications) == {:ok, [notification]} end @@ -47,4 +49,32 @@ defmodule Pleroma.RepoTest do assert Repo.get_assoc(token, :user) == {:error, :not_found} end end + + describe "chunk_stream/3" do + test "fetch records one-by-one" do + users = insert_list(50, :user) + + {fetch_users, 50} = + from(t in User) + |> Repo.chunk_stream(5) + |> Enum.reduce({[], 0}, fn %User{} = user, {acc, count} -> + {acc ++ [user], count + 1} + end) + + assert users == fetch_users + end + + test "fetch records in bulk" do + users = insert_list(50, :user) + + {fetch_users, 10} = + from(t in User) + |> Repo.chunk_stream(5, :batches) + |> Enum.reduce({[], 0}, fn users, {acc, count} -> + {acc ++ users, count + 1} + end) + + assert users == fetch_users + end + end end |