Skip to content

Commit 70b0f36

Browse files
TamLyNhatMikaka27
authored andcommitted
Add test for chunk_step crash after decreasing log size
1 parent 2a9372f commit 70b0f36

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/kernel/test/disk_log_SUITE.erl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@
8585

8686
change_attribute/1,
8787

88-
otp_6278/1, otp_10131/1, otp_16768/1, otp_16809/1]).
88+
otp_6278/1, otp_10131/1, otp_16768/1, otp_16809/1,
89+
90+
decrease_size_with_chunk_step/1]).
8991

9092
-export([head_fun/1, hf/0, lserv/1,
9193
measure/0, init_m/1, xx/0]).
@@ -159,7 +161,7 @@ groups() ->
159161
{change_size, [],
160162
[change_size_before, change_size_during,
161163
change_size_after, default_size, change_size2,
162-
change_size_truncate]}].
164+
change_size_truncate, decrease_size_with_chunk_step]}].
163165

164166
init_per_suite(Config) ->
165167
Config.
@@ -4203,6 +4205,28 @@ otp_16809(Conf) when is_list(Conf) ->
42034205
HeadFunc2 = info(Log, head, undef),
42044206
ok = disk_log:close(Log).
42054207

4208+
decrease_size_with_chunk_step(Conf) when is_list(Conf) ->
4209+
Dir = ?privdir(Conf),
4210+
Log = test,
4211+
File = filename:join(Dir, lists:concat([Log, ".LOG"])),
4212+
{ok, test} = disk_log:open([{size, {1000, 3}}, {name,Log},{type, wrap},
4213+
{file, File}, {notify, true}]),
4214+
eof = disk_log:chunk(Log,start,1),
4215+
{error, end_of_log} = disk_log:chunk_step(Log,start,1),
4216+
[disk_log:log(Log, X) || X <- lists:seq(1, 1000)],
4217+
ok = disk_log:close(Log),
4218+
{ok, test} = disk_log:open([{name, Log}, {type, wrap}, {file, File},
4219+
{notify, true}]),
4220+
%% Decrease maximum number of files from 10 to 2.
4221+
ok = disk_log:change_size(Log, {1000, 2}),
4222+
%% The exception error of rem/2 operator should not occur in here.
4223+
{ok, _} = disk_log:chunk_step(Log, start, 1),
4224+
%% Continue to append the items to the log in order to make sure it can work
4225+
%% as normal.
4226+
[disk_log:log(Log, X) || X <- lists:seq(1, 5000)],
4227+
ok = disk_log:close(Log),
4228+
del(File, 2).
4229+
42064230
mark(FileName, What) ->
42074231
{ok,Fd} = file:open(FileName, [raw, binary, read, write]),
42084232
{ok,_} = file:position(Fd, 4),

0 commit comments

Comments
 (0)