You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2019/09/11 15:50:12 UTC

[couchdb-smoosh] branch scheduled-smoosh updated (1cf2048 -> 1e27fb2)

This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a change to branch scheduled-smoosh
in repository https://gitbox.apache.org/repos/asf/couchdb-smoosh.git.


    from 1cf2048  Support scheduling compactions during time windows
     new c6c0742  Fix check_window responses
     new 1e27fb2  Add unit tests for scheduling window logic

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/smoosh_channel.erl                 | 10 ++---
 src/smoosh_utils.erl                   |  9 ++--
 test/exunit/scheduling_window_test.exs | 81 ++++++++++++++++++++++++++++++++++
 test/exunit/test_helper.exs            |  2 +
 4 files changed, 93 insertions(+), 9 deletions(-)
 create mode 100644 test/exunit/scheduling_window_test.exs
 create mode 100644 test/exunit/test_helper.exs


[couchdb-smoosh] 02/02: Add unit tests for scheduling window logic

Posted by ko...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a commit to branch scheduled-smoosh
in repository https://gitbox.apache.org/repos/asf/couchdb-smoosh.git

commit 1e27fb2a0fd6845ad1ba4432cea1d5fcf9bb84f0
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Wed Sep 11 11:49:37 2019 -0400

    Add unit tests for scheduling window logic
---
 test/exunit/scheduling_window_test.exs | 81 ++++++++++++++++++++++++++++++++++
 test/exunit/test_helper.exs            |  2 +
 2 files changed, 83 insertions(+)

diff --git a/test/exunit/scheduling_window_test.exs b/test/exunit/scheduling_window_test.exs
new file mode 100644
index 0000000..7fa6c23
--- /dev/null
+++ b/test/exunit/scheduling_window_test.exs
@@ -0,0 +1,81 @@
+defmodule SmooshSchedulingWindowTest do
+  use Couch.Test.ExUnit.Case
+
+  alias Couch.Test.Setup
+
+  setup_all(context) do
+    test_ctx = :test_util.start_couch([])
+
+    on_exit(fn ->
+      :config.delete('smoosh.test_channel', 'from')
+      :config.delete('smoosh.test_channel', 'to')
+      :test_util.stop_couch(test_ctx)
+    end)
+
+    context
+  end
+
+  test "in_allowed_window returns true by default", _context do
+    assert :smoosh_utils.in_allowed_window('nonexistent_channel') == true
+  end
+
+  test "in_allowed_window ignores bad input", _context do
+    :config.set('smoosh.test_channel', 'from', 'midnight', false)
+    :config.set('smoosh.test_channel', 'to', 'infinity', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == true
+  end
+
+  test "in_allowed_window returns false when now < from < to", _context do
+    now = DateTime.utc_now()
+    from = DateTime.add(now, 18_000)
+    to = DateTime.add(now, 36_000)
+    :config.set('smoosh.test_channel', 'from', '#{from.hour}:#{from.minute}', false)
+    :config.set('smoosh.test_channel', 'to', '#{to.hour}:#{to.minute}', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == false
+  end
+
+  test "in_allowed_window returns true when from < now < to", _context do
+    now = DateTime.utc_now()
+    from = DateTime.add(now, -18_000)
+    to = DateTime.add(now, 18_000)
+    :config.set('smoosh.test_channel', 'from', '#{from.hour}:#{from.minute}', false)
+    :config.set('smoosh.test_channel', 'to', '#{to.hour}:#{to.minute}', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == true
+  end
+
+  test "in_allowed_window returns false when from < to < now", _context do
+    now = DateTime.utc_now()
+    from = DateTime.add(now, -36_000)
+    to = DateTime.add(now, -18_000)
+    :config.set('smoosh.test_channel', 'from', '#{from.hour}:#{from.minute}', false)
+    :config.set('smoosh.test_channel', 'to', '#{to.hour}:#{to.minute}', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == false
+  end
+
+  test "in_allowed_window returns true when to < from < now", _context do
+    now = DateTime.utc_now()
+    from = DateTime.add(now, -18_000)
+    to = DateTime.add(now, -36_000)
+    :config.set('smoosh.test_channel', 'from', '#{from.hour}:#{from.minute}', false)
+    :config.set('smoosh.test_channel', 'to', '#{to.hour}:#{to.minute}', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == true
+  end
+
+  test "in_allowed_window returns false when to < now < from", _context do
+    now = DateTime.utc_now()
+    from = DateTime.add(now, 18_000)
+    to = DateTime.add(now, -18_000)
+    :config.set('smoosh.test_channel', 'from', '#{from.hour}:#{from.minute}', false)
+    :config.set('smoosh.test_channel', 'to', '#{to.hour}:#{to.minute}', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == false
+  end
+
+  test "in_allowed_window returns true when now < to < from", _context do
+    now = DateTime.utc_now()
+    from = DateTime.add(now, 36_000)
+    to = DateTime.add(now, 18_000)
+    :config.set('smoosh.test_channel', 'from', '#{from.hour}:#{from.minute}', false)
+    :config.set('smoosh.test_channel', 'to', '#{to.hour}:#{to.minute}', false)
+    assert :smoosh_utils.in_allowed_window('test_channel') == true
+  end
+end
diff --git a/test/exunit/test_helper.exs b/test/exunit/test_helper.exs
new file mode 100644
index 0000000..3140500
--- /dev/null
+++ b/test/exunit/test_helper.exs
@@ -0,0 +1,2 @@
+ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter])
+ExUnit.start()


[couchdb-smoosh] 01/02: Fix check_window responses

Posted by ko...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a commit to branch scheduled-smoosh
in repository https://gitbox.apache.org/repos/asf/couchdb-smoosh.git

commit c6c074237f43856c6dac7d482e2e1c128d785549
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Fri Sep 6 14:24:03 2019 -0400

    Fix check_window responses
---
 src/smoosh_channel.erl | 10 +++++-----
 src/smoosh_utils.erl   |  9 +++++----
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/smoosh_channel.erl b/src/smoosh_channel.erl
index a6269fc..d8a8d14 100644
--- a/src/smoosh_channel.erl
+++ b/src/smoosh_channel.erl
@@ -156,18 +156,18 @@ handle_info(check_window, State0) ->
     {ok, State} = code_change(nil, State0, nil),
     #state{paused = Paused, name = Name} = State,
     StrictWindow = smoosh_utils:get(Name, "strict_window", "false"),
-    FinalState = case {Paused, smoosh_utils:check_window(Name)} of
-        {true, pause} ->
+    FinalState = case {not Paused, smoosh_utils:in_allowed_window(Name)} of
+        {false, false} ->
             % already in desired state
             State;
-        {false, resume} ->
+        {true, true} ->
             % already in desired state
             State;
-        {true, resume} ->
+        {false, true} ->
             % resume is always safe even if we did not previously suspend
             {reply, ok, NewState} = handle_call(resume, nil, State),
             NewState;
-        {false, pause} ->
+        {true, false} ->
             if StrictWindow =:= "true" ->
                 {reply, ok, NewState} = handle_call(suspend, nil, State),
                 NewState;
diff --git a/src/smoosh_utils.erl b/src/smoosh_utils.erl
index 32c90db..b433de0 100644
--- a/src/smoosh_utils.erl
+++ b/src/smoosh_utils.erl
@@ -15,7 +15,7 @@
 
 -export([get/2, get/3, group_pid/1, split/1, stringify/1, ignore_db/1]).
 -export([
-    check_window/1
+    in_allowed_window/1
 ]).
 
 group_pid({Shard, GroupId}) ->
@@ -60,12 +60,12 @@ ignore_db(DbName) when is_list(DbName) ->
 ignore_db(Db) ->
     ignore_db(couch_db:name(Db)).
 
-check_window(Channel) ->
+in_allowed_window(Channel) ->
     From = parse_time(get(Channel, "from"), {00, 00}),
     To = parse_time(get(Channel, "to"), {24, 00}),
-    check_window(From, To).
+    in_allowed_window(From, To).
 
-check_window(From, To) ->
+in_allowed_window(From, To) ->
     {HH, MM, _} = erlang:time(),
     case From < To of
     true ->
@@ -74,6 +74,7 @@ check_window(From, To) ->
         ({HH, MM} >= From) orelse ({HH, MM} < To)
     end.
 
+
 parse_time(undefined, Default) ->
     Default;
 parse_time(String, Default) ->