You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2025/06/24 20:50:29 UTC
(couchdb) branch introduce-commit_header-2 created (now 25b9eddc9)
This is an automated email from the ASF dual-hosted git repository.
iilyak pushed a change to branch introduce-commit_header-2
in repository https://gitbox.apache.org/repos/asf/couchdb.git
at 25b9eddc9 Add tests for write_header/3 with [sync]
This branch includes the following new commits:
new 25b9eddc9 Add tests for write_header/3 with [sync]
The 1 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.
(couchdb) 01/01: Add tests for write_header/3 with [sync]
Posted by ii...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
iilyak pushed a commit to branch introduce-commit_header-2
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 25b9eddc988fae7282205b5ec998bfd4c53cb932
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Tue Jun 24 13:49:50 2025 -0700
Add tests for write_header/3 with [sync]
---
src/couch/test/eunit/couch_file_tests.erl | 76 +++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/src/couch/test/eunit/couch_file_tests.erl b/src/couch/test/eunit/couch_file_tests.erl
index 5b7481636..1f8c75afa 100644
--- a/src/couch/test/eunit/couch_file_tests.erl
+++ b/src/couch/test/eunit/couch_file_tests.erl
@@ -946,3 +946,79 @@ legacy_stats() ->
reset_legacy_checksum_stats() ->
Counter = couch_stats:sample([couchdb, legacy_checksums]),
couch_stats:decrement_counter([couchdb, legacy_checksums], Counter).
+
+write_header_sync_test_() ->
+ {
+ "Test sync options for write_header",
+ {
+ setup,
+ fun test_util:start_couch/0,
+ fun test_util:stop_couch/1,
+ {
+ foreach,
+ fun unlinked_setup/0,
+ % unlinked(fun setup/0),
+ % fun(Fd) ->
+ % meck:unload(file),
+ % case is_process_alive(Fd) of
+ % true -> ok = couch_file:close(Fd);
+ % false -> ok
+ % end
+ % end,
+ fun teardown/1,
+ [
+ ?TDEF_FE(t_should_handle_sync_option),
+ ?TDEF_FE(t_should_not_sync_by_default),
+ ?TDEF_FE(should_handle_error_of_the_fist_sync),
+ ?TDEF_FE(should_handle_error_of_the_second_sync),
+ ?TDEF_FE(should_handle_error_of_the_file_write)
+ ]
+ }
+ }
+ }.
+
+unlinked_setup() ->
+ Self = self(),
+ ReqId = make_ref(),
+ meck:new(file, [passthrough, unstick]),
+ spawn(fun() ->
+ {ok, Fd} = couch_file:open(?tempfile(), [create, overwrite]),
+ Self ! {ReqId, Fd}
+ end),
+ receive
+ {ReqId, Result} -> Result
+ end.
+
+t_should_handle_sync_option(Fd) ->
+ ok = couch_file:write_header(Fd, {<<"some_data">>, 32}, [sync]),
+ ?assertMatch({ok, {<<"some_data">>, 32}}, couch_file:read_header(Fd)),
+ ?assertEqual(2, meck:num_calls(file, datasync, ['_'])),
+ ok.
+
+t_should_not_sync_by_default(Fd) ->
+ ok = couch_file:write_header(Fd, {<<"some_data">>, 32}),
+ ?assertMatch({ok, {<<"some_data">>, 32}}, couch_file:read_header(Fd)),
+ ?assertEqual(0, meck:num_calls(file, datasync, ['_'])),
+ ok.
+
+should_handle_error_of_the_fist_sync(Fd) ->
+ meck:expect(file, datasync, ['_'],
+ meck:val({error, terminated})
+ ),
+ ?assertEqual({error, terminated}, couch_file:write_header(Fd, {<<"some_data">>, 32}, [sync])),
+ ok.
+
+should_handle_error_of_the_second_sync(Fd) ->
+ meck:expect(file, datasync, ['_'], meck:seq([
+ meck:val(ok),
+ meck:val({error, terminated})
+ ])),
+ ?assertEqual({error, terminated}, couch_file:write_header(Fd, {<<"some_data">>, 32}, [sync])),
+ ok.
+
+should_handle_error_of_the_file_write(Fd) ->
+ meck:expect(file, write, ['_', '_'],
+ meck:val({error, terminated})
+ ),
+ ?assertEqual({error, terminated}, couch_file:write_header(Fd, {<<"some_data">>, 32}, [sync])),
+ ok.