summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@gmail.com>2023-04-10 16:20:37 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2023-04-10 22:01:19 -0400
commite32cfd63d8950e2d1e083374e8cd2a1445b606e5 (patch)
treedc8ba7a95bb0385240fe7a28947ec037653b587f
parent1432717b154e2986e86da18c78ca843e020a5bfd (diff)
downloadcouchdb-e32cfd63d8950e2d1e083374e8cd2a1445b606e5.tar.gz
Improve compression eunit test suite
Use the simpler `?TDEF_FE` macro and fix timeout usage bug. EUnit timeout is in seconds, while test_util:wait/2 takes milliseconds. This was revealed due a slow disk IO speed on the new s390x worker. To reduce flakiness and to ensure db / view size before compaction is greater than the size after compaction, even with `none` compression option, make db update batches smaller and use more frequent index commits. Issue: https://github.com/apache/couchdb/issues/4521
-rw-r--r--src/couch/test/eunit/couchdb_file_compression_tests.erl116
1 files changed, 55 insertions, 61 deletions
diff --git a/src/couch/test/eunit/couchdb_file_compression_tests.erl b/src/couch/test/eunit/couchdb_file_compression_tests.erl
index 75bf18a12..122900d4b 100644
--- a/src/couch/test/eunit/couchdb_file_compression_tests.erl
+++ b/src/couch/test/eunit/couchdb_file_compression_tests.erl
@@ -18,9 +18,38 @@
-define(DDOC_ID, <<"_design/test">>).
-define(DOCS_COUNT, 1000).
-define(TIMEOUT, 60).
+% Smaller doc batches will generate more garbage
+-define(BATCH_SIZE, 100).
setup_all() ->
Ctx = test_util:start_couch(),
+ config:set("query_server_config", "commit_freq", "0", false),
+ config:set("couchdb", "file_compression", "none", false),
+ Ctx.
+
+teardown_all(Ctx) ->
+ config:delete("couchdb", "file_compression", false),
+ config:delete("query_server_config", "commit_freq", false),
+ test_util:stop_couch(Ctx).
+
+couch_file_compression_test_() ->
+ {
+ "CouchDB file compression tests",
+ {
+ setup,
+ fun setup_all/0,
+ fun teardown_all/1,
+ {foreach, fun setup/0, fun teardown/1, [
+ ?TDEF_FE(should_use_none, ?TIMEOUT),
+ ?TDEF_FE(should_use_deflate_1, ?TIMEOUT),
+ ?TDEF_FE(should_use_deflate_9, ?TIMEOUT),
+ ?TDEF_FE(should_use_snappy, ?TIMEOUT),
+ ?TDEF_FE(should_compare_compression_methods, ?TIMEOUT)
+ ]}
+ }
+ }.
+
+setup() ->
config:set("couchdb", "file_compression", "none", false),
DbName = ?tempdb(),
{ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
@@ -40,58 +69,34 @@ setup_all() ->
),
{ok, _} = couch_db:update_doc(Db, DDoc, []),
ok = couch_db:close(Db),
- {Ctx, DbName}.
+ ok = refresh_index(DbName),
+ DbName.
-teardown_all({Ctx, DbName}) ->
- ok = couch_server:delete(DbName, [?ADMIN_CTX]),
- test_util:stop_couch(Ctx).
+teardown(DbName) ->
+ config:delete("couchdb", "file_compression", false),
+ couch_server:delete(DbName, [?ADMIN_CTX]).
-couch_file_compression_test_() ->
- {
- "CouchDB file compression tests",
- {
- setup,
- 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),
+ compact_db(DbName),
+ 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_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_deflate_1(DbName) ->
+ config:set("couchdb", "file_compression", "deflate_1", false),
+ compact_db(DbName),
+ compact_view(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.
+should_use_deflate_9(DbName) ->
+ config:set("couchdb", "file_compression", "deflate_9", false),
+ compact_db(DbName),
+ compact_view(DbName).
+
+should_use_snappy(DbName) ->
+ config:set("couchdb", "file_compression", "deflate_9", false),
+ compact_db(DbName),
+ compact_view(DbName).
-compare_methods(DbName) ->
+should_compare_compression_methods(DbName) ->
config:set("couchdb", "file_compression", "none", false),
ExternalSizePreCompact = db_external_size(DbName),
compact_db(DbName),
@@ -149,21 +154,10 @@ populate_db(Db, NumDocs) ->
]}
)
end,
- lists:seq(1, 500)
+ lists:seq(1, ?BATCH_SIZE)
),
{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.
+ populate_db(Db, NumDocs - ?BATCH_SIZE).
refresh_index(DbName) ->
{ok, Db} = couch_db:open_int(DbName, []),
@@ -226,7 +220,7 @@ wait_compaction(DbName, Kind, Line) ->
false -> ok
end
end,
- case test_util:wait(WaitFun, ?TIMEOUT) of
+ case test_util:wait(WaitFun, ?TIMEOUT * 1000) of
timeout ->
erlang:error(
{assertion_failed, [