Refactor modules into contexts (#78)
* [WIP] break out a few contexts, start refactoring fast index modules * [WIP] more contexts, this time around slow indexing and downloads * [WIP] got all tests passing * [WIP] Added moduledocs * Built a genserver to rename old jobs on boot * Added a module naming check; moved things around * Fixed specs
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
defmodule Pinchflat.SlowIndexing.FileFollowerServerTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
alias Pinchflat.SlowIndexing.FileFollowerServer
|
||||
|
||||
setup do
|
||||
{:ok, pid} = FileFollowerServer.start_link()
|
||||
tmpfile = FilesystemHelpers.generate_metadata_tmpfile(:txt)
|
||||
|
||||
{:ok, %{pid: pid, tmpfile: tmpfile}}
|
||||
end
|
||||
|
||||
describe "watch_file" do
|
||||
test "calls the handler for each existing line in the file", %{pid: pid, tmpfile: tmpfile} do
|
||||
File.write!(tmpfile, "line1\nline2")
|
||||
parent = self()
|
||||
|
||||
handler = fn line -> send(parent, line) end
|
||||
FileFollowerServer.watch_file(pid, tmpfile, handler)
|
||||
|
||||
assert_receive "line1\n"
|
||||
assert_receive "line2"
|
||||
end
|
||||
|
||||
test "calls the handler for each new line in the file", %{pid: pid, tmpfile: tmpfile} do
|
||||
parent = self()
|
||||
file = File.open!(tmpfile, [:append])
|
||||
handler = fn line -> send(parent, line) end
|
||||
|
||||
FileFollowerServer.watch_file(pid, tmpfile, handler)
|
||||
|
||||
IO.binwrite(file, "line1\n")
|
||||
assert_receive "line1\n"
|
||||
IO.binwrite(file, "line2")
|
||||
assert_receive "line2"
|
||||
end
|
||||
end
|
||||
|
||||
describe "stop" do
|
||||
test "stops the watcher", %{pid: pid, tmpfile: tmpfile} do
|
||||
handler = fn _line -> :noop end
|
||||
FileFollowerServer.watch_file(pid, tmpfile, handler)
|
||||
|
||||
refute is_nil(Process.info(pid))
|
||||
FileFollowerServer.stop(pid)
|
||||
# Gotta wait for the server to stop async
|
||||
:timer.sleep(50)
|
||||
assert is_nil(Process.info(pid))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user