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

[couchdb] 08/41: Speedup eunit: couchdb_file_compression_tests

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

davisp pushed a commit to branch speedup-test-suite
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 380489eff972167e2cb2ae90b7c18e0a6e000446
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 19 13:02:47 2019 -0600

    Speedup eunit: couchdb_file_compression_tests
    
    This just populates a single test db and then copies the raw file to a
    new database name for each individual test.
---
 .../test/eunit/couchdb_file_compression_tests.erl  | 124 ++++++++++-----------
 1 file changed, 57 insertions(+), 67 deletions(-)

diff --git a/src/couch/test/eunit/couchdb_file_compression_tests.erl b/src/couch/test/eunit/couchdb_file_compression_tests.erl
index 8f0fe5b..7725033 100644
--- a/src/couch/test/eunit/couchdb_file_compression_tests.erl
+++ b/src/couch/test/eunit/couchdb_file_compression_tests.erl
@@ -16,10 +16,11 @@
 -include_lib("couch/include/couch_db.hrl").
 
 -define(DDOC_ID, <<"_design/test">>).
--define(DOCS_COUNT, 5000).
--define(TIMEOUT, 60000).
+-define(DOCS_COUNT, 1000).
+-define(TIMEOUT, 60).
 
-setup() ->
+setup_all() ->
+    Ctx = test_util:start_couch(),
     config:set("couchdb", "file_compression", "none", false),
     DbName = ?tempdb(),
     {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
@@ -35,13 +36,13 @@ setup() ->
         }
     ]}),
     {ok, _} = couch_db:update_doc(Db, DDoc, []),
-    refresh_index(DbName),
     ok = couch_db:close(Db),
-    DbName.
+    {Ctx, DbName}.
 
-teardown(DbName) ->
+
+teardown_all({Ctx, DbName}) ->
     ok = couch_server:delete(DbName, [?ADMIN_CTX]),
-    ok.
+    test_util:stop_couch(Ctx).
 
 
 couch_file_compression_test_() ->
@@ -49,75 +50,51 @@ couch_file_compression_test_() ->
         "CouchDB file compression tests",
         {
             setup,
-            fun test_util:start_couch/0, fun test_util:stop_couch/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_use_none/1,
-                    fun should_use_deflate_1/1,
-                    fun should_use_deflate_9/1,
-                    fun should_use_snappy/1,
-                    fun should_compare_compression_methods/1
-                ]
-            }
+            fun setup_all/0,
+            fun teardown_all/1,
+            {with, [
+                fun should_use_none/1,
+                fun should_use_deflate_1/1,
+                fun should_use_deflate_9/1,
+                fun should_use_snappy/1,
+                fun should_compare_compression_methods/1
+            ]}
         }
     }.
 
 
-should_use_none(DbName) ->
-    config:set("couchdb", "file_compression", "none", false),
-    {
-        "Use no compression",
-        [
-            {"compact database",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_db(DbName))}},
-            {"compact view",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_view(DbName))}}
-        ]
-    }.
+should_use_none({_, DbName}) -> run_test(DbName, "none").
+should_use_deflate_1({_, DbName}) -> run_test(DbName, "deflate_1").
+should_use_deflate_9({_, DbName}) -> run_test(DbName, "deflate_9").
+should_use_snappy({_, DbName}) -> run_test(DbName, "snappy").
 
-should_use_deflate_1(DbName) ->
-    config:set("couchdb", "file_compression", "deflate_1", false),
-    {
-        "Use deflate compression at level 1",
-        [
-            {"compact database",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_db(DbName))}},
-            {"compact view",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_view(DbName))}}
-        ]
-    }.
 
-should_use_deflate_9(DbName) ->
-    config:set("couchdb", "file_compression", "deflate_9", false),
-    {
-        "Use deflate compression at level 9",
-        [
-            {"compact database",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_db(DbName))}},
-            {"compact view",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_view(DbName))}}
-        ]
-    }.
+should_compare_compression_methods({_, DbName}) ->
+    TestDb = setup_db(DbName),
+    Name = "none > snappy > deflate_1 > deflate_9",
+    try
+        {Name, {timeout, ?TIMEOUT, ?_test(compare_methods(TestDb))}}
+    after
+        couch_server:delete(TestDb, [?ADMIN_CTX])
+    end.
 
-should_use_snappy(DbName) ->
-    config:set("couchdb", "file_compression", "snappy", false),
-    {
-        "Use snappy compression",
-        [
-            {"compact database",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_db(DbName))}},
-            {"compact view",
-             {timeout, 5 + ?TIMEOUT div 1000, ?_test(compact_view(DbName))}}
-        ]
-    }.
 
-should_compare_compression_methods(DbName) ->
-    {"none > snappy > deflate_1 > deflate_9",
-     {timeout, ?TIMEOUT div 1000, ?_test(compare_compression_methods(DbName))}}.
+run_test(DbName, Comp) ->
+    config:set("couchdb", "file_compression", Comp, false),
+    Timeout = 5 + ?TIMEOUT,
+    TestDb = setup_db(DbName),
+    Tests = [
+        {"compact database", {timeout, Timeout, ?_test(compact_db(DbName))}},
+        {"compact view", {timeout, Timeout, ?_test(compact_view(DbName))}}
+    ],
+    try
+        {"Use compression: " ++ Comp, Tests}
+    after
+        ok = couch_server:delete(TestDb, [?ADMIN_CTX])
+    end.
+
 
-compare_compression_methods(DbName) ->
+compare_methods(DbName) ->
     config:set("couchdb", "file_compression", "none", false),
     ExternalSizePreCompact = db_external_size(DbName),
     compact_db(DbName),
@@ -178,6 +155,19 @@ populate_db(Db, NumDocs) ->
     {ok, _} = couch_db:update_docs(Db, Docs, []),
     populate_db(Db, NumDocs - 500).
 
+
+setup_db(SrcDbName) ->
+    TgtDbName = ?tempdb(),
+    TgtDbFileName = binary_to_list(TgtDbName) ++ ".couch",
+    couch_util:with_db(SrcDbName, fun(Db) ->
+        OldPath = couch_db:get_filepath(Db),
+        NewPath = filename:join(filename:dirname(OldPath), TgtDbFileName),
+        {ok, _} = file:copy(OldPath, NewPath)
+    end),
+    refresh_index(TgtDbName),
+    TgtDbName.
+
+
 refresh_index(DbName) ->
     {ok, Db} = couch_db:open_int(DbName, []),
     {ok, DDoc} = couch_db:open_doc(Db, ?DDOC_ID, [ejson_body]),