You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2026/04/21 04:09:23 UTC
(couchdb-jiffy) 12/49: Add yielding tests
This is an automated email from the ASF dual-hosted git repository.
nickva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-jiffy.git
commit e1fa8a41314ecc6a901d5f8573dd3832d464c0ad
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Tue Mar 31 01:03:51 2026 -0400
Add yielding tests
Yielding properly is one of the best "hidden" features of Jiffy, which makes it
run very well in a highly concurrent environment. It turns out we didn't have a
test which tried to explicilty consume more time slices so try to add one.
The rest is a rather boring set of bytes_per_red/bytes_per_iter option
combinations.
---
test/jiffy_19_yielding_tests.erl | 45 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/test/jiffy_19_yielding_tests.erl b/test/jiffy_19_yielding_tests.erl
new file mode 100644
index 0000000..d12ee88
--- /dev/null
+++ b/test/jiffy_19_yielding_tests.erl
@@ -0,0 +1,45 @@
+% This file is part of Jiffy released under the MIT license.
+% See the LICENSE file for more information.
+
+-module(jiffy_19_yielding_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+-include("jiffy_util.hrl").
+
+decode_bytes_per_red_test() ->
+ ?assertEqual([1,2,3], dec(<<"[1,2,3]">>, [{bytes_per_red, 50}])).
+
+encode_bytes_per_red_test() ->
+ ?assertEqual(<<"[1,2,3]">>, enc([1,2,3], [{bytes_per_red, 50}])).
+
+decode_bytes_per_iter_test() ->
+ ?assertEqual([1,2,3], dec(<<"[1,2,3]">>, [{bytes_per_iter, 20000}])).
+
+encode_bytes_per_iter_test() ->
+ ?assertEqual(<<"[1,2,3]">>, enc([1,2,3], [{bytes_per_iter, 20000}])).
+
+decode_both_bytes_opts_test() ->
+ Opts = [{bytes_per_red, 100}, {bytes_per_iter, 200000}],
+ ?assertEqual(1, dec(<<"1">>, Opts)).
+
+encode_both_bytes_opts_test() ->
+ Opts = [{bytes_per_red, 100}, {bytes_per_iter, 200000}],
+ ?assertEqual(<<"1">>, enc(1, Opts)).
+
+% Give it something large to chew on so it hopefully does some yielding.
+% Noticed with coverage enabled we didn't check some yielding paths in CI tests
+% otheriwse.
+%
+decode_large_with_bytes_per_red_test() ->
+ Data = iolist_to_binary([
+ <<"[">>,
+ lists:join(<<",">>, [<<"1">> || _ <- lists:seq(1, 500)]),
+ <<"]">>
+ ]),
+ Result = jiffy:decode(Data, [{bytes_per_red, 20}]),
+ ?assertEqual(500, length(Result)).
+
+encode_large_with_bytes_per_red_test() ->
+ Data = lists:duplicate(500, 1),
+ Encoded = iolist_to_binary(jiffy:encode(Data, [{bytes_per_red, 20}])),
+ ?assertEqual(Data, jiffy:decode(Encoded)).