Skip to content

Commit 208e5d7

Browse files
committed
Fix test
1 parent 70405cd commit 208e5d7

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

test/osiris_log_SUITE.erl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ read_ahead(Config) ->
414414
W1;
415415
(read, #{r := R0, tracer := T}) ->
416416
%% first chunk, we read the header and the chunk
417-
{ok, R1} = osiris_log:send_file(CS, R0),
418-
{ok, Read} = gen_tcp:recv(SS, 0),
419417
Entries = [<<"hiiiiiiiii">>, <<"hooooooo">>],
420418
[_, _, D, _] = fake_chunk(Entries, ?LINE, 1, 100),
419+
{ok, R1} = osiris_log:send_file(CS, R0),
420+
{ok, Read} = recv(SS, byte_size(iolist_to_binary(D)) + HS),
421421
?assertEqual(iolist_to_binary(D), binary:part(Read, HS, byte_size(Read) - HS)),
422422
?assertEqual(2, length(osiris_tracer:calls(T))),
423423
R1
@@ -427,9 +427,9 @@ read_ahead(Config) ->
427427
W1;
428428
(read, #{r := R0, tracer := T}) ->
429429
%% small chunk, we read it ahead already
430-
{ok, R1} = osiris_log:send_file(CS, R0),
431-
{ok, Read} = gen_tcp:recv(SS, 0),
432430
[_, _, D, _] = fake_chunk([<<"hi">>, <<"ho">>], ?LINE, 1, 100),
431+
{ok, R1} = osiris_log:send_file(CS, R0),
432+
{ok, Read} = recv(SS, byte_size(iolist_to_binary(D)) + HS),
433433
?assertEqual(iolist_to_binary(D), binary:part(Read, HS, byte_size(Read) - HS)),
434434
?assertEqual(0, length(osiris_tracer:calls(T))),
435435
R1
@@ -440,10 +440,10 @@ read_ahead(Config) ->
440440
W1;
441441
(read, #{r := R0, tracer := T}) ->
442442
%% large chunk, we will need to read from the file system
443-
{ok, R1} = osiris_log:send_file(CS, R0),
444-
{ok, Read} = gen_tcp:recv(SS, 0),
445443
Entries = [<<"foo">>, binary:copy(<<"b">>, RAL * 2)],
446444
[_, _, D, _] = fake_chunk(Entries, ?LINE, 1, 100),
445+
{ok, R1} = osiris_log:send_file(CS, R0),
446+
{ok, Read} = recv(SS, byte_size(iolist_to_binary(D)) + HS),
447447
?assertEqual(iolist_to_binary(D), binary:part(Read, HS, byte_size(Read) - HS)),
448448
?assertEqual(0, length(osiris_tracer:calls(T, file, pread))),
449449
?assertEqual(1, length(osiris_tracer:calls(T, file, sendfile))),
@@ -2383,3 +2383,19 @@ fake_chunk(Blobs, Ts, Epoch, NextChId, FSize) ->
23832383
element(1,
23842384
osiris_log:make_chunk(Blobs, <<>>, 0, Ts, Epoch, NextChId,
23852385
FSize)).
2386+
2387+
recv(Socket, Expected) ->
2388+
recv(Socket, Expected, <<>>).
2389+
2390+
recv(_Socket, 0, Acc) ->
2391+
Acc;
2392+
recv(Socket, Expected, Acc) ->
2393+
case gen_tcp:recv(Socket, Expected, 10_000) of
2394+
{ok, Data} when byte_size(Data) == Expected ->
2395+
{ok, Data};
2396+
{ok, Data} when byte_size(Data) < Expected ->
2397+
{ok, recv(Socket, Expected - byte_size(Data),
2398+
<<Acc/binary, Data/binary>>)};
2399+
Other ->
2400+
Other
2401+
end.

0 commit comments

Comments
 (0)