summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2020-09-16 09:47:18 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2020-09-16 09:47:18 +0300
commit599f8bb152ca0669d17baa5f313f00f0791209b6 (patch)
tree9bc4e08bdc2a0c78ba773775dc11a17c9e0350d1 /test
parentc74fad9e06cdb272a1378082908448f7f0b592ac (diff)
downloadpleroma-599f8bb152ca0669d17baa5f313f00f0791209b6.tar.gz
pleroma-599f8bb152ca0669d17baa5f313f00f0791209b6.zip
RepoStreamer.chunk_stream -> Repo.chunk_stream
Diffstat (limited to 'test')
-rw-r--r--test/repo_test.exs28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/repo_test.exs b/test/repo_test.exs
index 72c0b5071..155791be2 100644
--- a/test/repo_test.exs
+++ b/test/repo_test.exs
@@ -49,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