summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2014-10-21 18:05:37 -0600
committerkballou <kballou@devnulllabs.io>2014-10-21 18:11:55 -0600
commit0d28c28a85582d2b7104f2caefe0c56f5062c578 (patch)
tree7be0b475722123cd9ad270636a87f4ca2089e55e
parent5a9a4ded49b32322a702e9ae3a02d3e4238b41a0 (diff)
downloadpoolparty-0d28c28a85582d2b7104f2caefe0c56f5062c578.tar.gz
poolparty-0d28c28a85582d2b7104f2caefe0c56f5062c578.tar.xz
Add some basic tests for pool scheduler
-rw-r--r--test/poolparty_test.exs60
1 files changed, 58 insertions, 2 deletions
diff --git a/test/poolparty_test.exs b/test/poolparty_test.exs
index 761c433..6e66bda 100644
--- a/test/poolparty_test.exs
+++ b/test/poolparty_test.exs
@@ -1,3 +1,59 @@
-defmodule PoolpartyTest do
- use ExUnit.Case
+defmodule PoolPartyTest do
+ use ExUnit.Case, aysnc: false
+
+ setup do
+ {:ok, pool} = PoolParty.start(nil, nil)
+ on_exit(pool, fn -> Application.stop(pool) end)
+ {:ok, pool: pool}
+ end
+
+ test "pool can perform work", %{pool: _} do
+ :timer.sleep(100)
+ [:ok, :ok, :ok, :ok, :ok, :ok, :ok, :ok] =
+ (1..8) |>
+ Enum.map(fn(x) -> PoolParty.Scheduler.process(&(&1*&1), x, self()) end)
+ :timer.sleep(100)
+ state = :sys.get_state(PoolParty.Scheduler)
+ assert_receive {:result, 1}
+ assert_receive {:result, 4}
+ assert_receive {:result, 9}
+ assert_receive {:result, 16}
+ assert_receive {:result, 25}
+ assert_receive {:result, 36}
+ assert_receive {:result, 49}
+ assert_receive {:result, 64}
+ assert(state.max_pool_size == Application.get_env(:poolparty, :pool_size))
+ assert(length(state.queue) == 0)
+ end
+
+ test "pool queues work when full", %{pool: _} do
+ :timer.sleep(100)
+ (1..16) |>
+ Enum.map(fn(x) ->
+ PoolParty.Scheduler.process(
+ fn(x) ->
+ :timer.sleep(100)
+ x
+ end,
+ x, self()) end)
+ state = :sys.get_state(PoolParty.Scheduler)
+ assert(length(state.queue) == 8)
+ assert(HashDict.size(state.processing) == 8)
+ end
+
+ test "pool can handle worker leaving", %{pool: _} do
+ :timer.sleep(100)
+ PoolParty.Scheduler.process(fn(_)-> exit(:kill) end, [], self())
+ assert(HashDict.size(:sys.get_state(PoolParty.Scheduler).processing) == 1)
+ :timer.sleep(100)
+ state = :sys.get_state(PoolParty.Scheduler)
+ assert_receive {:result, :failed}
+ assert(length(state.workers) == 8)
+ assert(HashDict.size(state.processing) == 0)
+ end
+
+ test "pool handles leaving process without fail", %{pool: _} do
+ :timer.sleep(100)
+ PoolParty.Scheduler.leave(self())
+ end
end