iilyak commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r731808295



##########
File path: src/smoosh/test/smoosh_tests.erl
##########
@@ -0,0 +1,123 @@
+-module(smoosh_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+-include("couch/src/couch_db_int.hrl").
+
+-define(KILOBYTE, << <<"x">> || _ <- lists:seq(1, 1024)>>).
+
+%% ==========
+%% Setup
+%% ----------
+
+setup(ChannelType) ->
+    DbName = ?tempdb(),
+    {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
+    couch_db:close(Db),
+    {ok, ChannelPid} = smoosh_server:get_channel(ChannelType),
+    smoosh_channel:flush(ChannelPid),
+    ok = config:set(config_section(ChannelType), "min_size", "200000", false),
+    ok = config:set("smoosh", "auto_save", "50", false),
+    DbName.
+
+teardown(ChannelType, DbName) ->
+    ok = couch_server:delete(DbName, [?ADMIN_CTX]),
+    ok = config:delete(config_section(DbName), "min_size", false),
+    {ok, ChannelPid} = smoosh_server:get_channel(ChannelType),
+    smoosh_channel:flush(ChannelPid),
+    ok.
+
+config_section(ChannelType) ->
+    "smoosh." ++ ChannelType.
+
+%% ==========
+%% Tests
+%% ----------
+
+smoosh_test_() ->
+    {
+        "Testing smoosh",
+        {
+            setup,
+            fun() -> test_util:start_couch([smoosh]) end,
+            fun test_util:stop/1,
+            [
+                channels_tests(),
+                persistence_tests()
+            ]
+        }
+    }.
+
+persistence_tests() ->
+    Tests = [
+        fun should_persist_queue/2
+    ],
+    {
+        "Should persist queue state",
+        [
+              make_test_case("ratio_dbs", Tests)
+        ]
+    }.
+
+
+channels_tests() ->
+    Tests = [
+        fun should_enqueue/2
+    ],
+    {
+        "Various channels tests",
+        [
+              make_test_case("ratio_dbs", Tests)
+        ]
+    }.
+
+make_test_case(Type, Funs) ->
+    {foreachx, fun setup/1, fun teardown/2, [{Type, Fun} || Fun <- Funs]}.
+
+should_enqueue("ratio_dbs" = ChannelType, DbName) ->
+    ok = grow_db_file(DbName, 300),
+    ?_test(begin
+        ok = wait_enqueue(),
+        ?assertEqual(1, length(channel_queue(ChannelType))),
+        ok
+    end).
+
+should_persist_queue(_, DbName) ->
+    ?_test(begin
+        ok = grow_db_file(DbName, 3000),
+        ok = wait_enqueue(),
+        Queued = channel_queue("ratio_dbs"),
+        ok = application:stop(smoosh),
+        ok = application:start(smoosh),
+        ?assertEqual(Queued, channel_queue("ratio_dbs")),
+        ok
+    end).
+
+grow_db_file(DbName, SizeInKb) ->

Review comment:
       nice one!!!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to