-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
defmodule Logflare.Queues.MemoryBufferTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
alias Logflare.Buffers.MemoryBuffer | ||
|
||
alias Logflare.Buffers.Buffer | ||
|
||
@subject Logflare.Buffers.MemoryBuffer | ||
|
||
@job %{some: "job"} | ||
|
||
setup do | ||
pid = start_supervised!(MemoryBuffer) | ||
pid = start_supervised!(@subject) | ||
{:ok, pid: pid} | ||
end | ||
|
||
test "can enqueue jobs", %{pid: pid} do | ||
assert :ok = MemoryBuffer.add(pid, @job) | ||
assert :ok = MemoryBuffer.add_many(pid, [@job]) | ||
assert MemoryBuffer.length(pid) == 2 | ||
assert :ok = Buffer.add(@subject, pid, @job) | ||
assert :ok = Buffer.add_many(@subject, pid, [@job]) | ||
assert Buffer.length(@subject, pid) == 2 | ||
end | ||
|
||
test "can pop n jobs from queue", %{pid: pid} do | ||
job1 = %{some: "job1"} | ||
job2 = %{some: "job2"} | ||
job3 = %{some: "job3"} | ||
job4 = %{some: "job4"} | ||
assert :ok = MemoryBuffer.add_many(pid, [job1, job2]) | ||
assert :ok = MemoryBuffer.add_many(pid, [job3, job4]) | ||
assert :ok = Buffer.add_many(@subject, pid, [job1, job2]) | ||
assert :ok = Buffer.add_many(@subject, pid, [job3, job4]) | ||
|
||
# should use fifo | ||
assert {:ok, [%{some: "job1"}, %{some: "job2"}]} = MemoryBuffer.pop_many(pid, 2) | ||
assert {:ok, [%{some: "job3"}, %{some: "job4"}]} = MemoryBuffer.pop_many(pid, 5) | ||
assert {:ok, []} = MemoryBuffer.pop_many(pid, 5) | ||
assert {:ok, [%{some: "job1"}, %{some: "job2"}]} = Buffer.pop_many(@subject, pid, 2) | ||
assert {:ok, [%{some: "job3"}, %{some: "job4"}]} = Buffer.pop_many(@subject, pid, 5) | ||
assert {:ok, []} = Buffer.pop_many(@subject, pid, 5) | ||
end | ||
|
||
test "can clear jobs from queue", %{pid: pid} do | ||
assert :ok = MemoryBuffer.add(pid, @job) | ||
MemoryBuffer.clear(pid) | ||
assert MemoryBuffer.length(pid) == 0 | ||
assert :ok = Buffer.add(@subject, pid, @job) | ||
Buffer.clear(@subject, pid) | ||
assert Buffer.length(@subject, pid) == 0 | ||
end | ||
end |