Skip to content

Commit d4e890c

Browse files
committed
fix: Timeout in test case on Mac OS X
1 parent 132e9c3 commit d4e890c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

test/jq_tests.erl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,31 @@ timeout_t_() ->
108108
"while(. < 42; . * 2)"),
109109
TO = fun() -> {error, {timeout, _}} = jq:process_json(Program, "-2", 10) end,
110110
OK = fun() -> {ok, [<<"64">>]} = jq:process_json(Program, "2", 10000) end,
111-
NrOfSubProcesses = 30,
111+
NrOfSubProcesses = 10,
112112
TimeoutAndThenNot =
113113
fun () ->
114114
OK(),
115115
TO(),
116116
OK(),
117117
Parent = self(),
118+
ct:pal("Starting concurrent processes that will timeout. Implementation module ~p", [jq:implementation_module()]),
118119
Pids = [ spawn_link(fun() ->
120+
% ct:pal("Starting process ~p ~p", [X, self()]),
119121
OK(),
120122
TO(),
121123
OK(),
122124
Parent ! self() end) ||
123-
_ <- lists:seq(1, NrOfSubProcesses)],
124-
timer:sleep(500),
125-
lists:sum([ receive X -> 1 end || X <- Pids])
125+
X <- lists:seq(1, NrOfSubProcesses)],
126+
ct:pal("Starting to wait for processes"),
127+
Sum = lists:sum([ begin
128+
% erlang:display({'Process finnished timeout', X}),
129+
receive X -> 1 end
130+
end || X <- Pids]),
131+
ct:pal("Done with concurrent timeout test"),
132+
Sum
126133
end,
127-
{timeout, 60, [
134+
%% Timout setting does not seem to be working on Mac OS (a bug?)
135+
{timeout, 3000, [
128136
?_assertMatch({ok, [<<"64">>]},
129137
jq:process_json(Program, "2", 10000))
130138
, ?_assertMatch({ok, [<<"64">>]},
@@ -323,6 +331,7 @@ port_program_valgrind_test_() ->
323331
-endif.
324332

325333
setup_nif() ->
334+
ct:pal("Setup NIF, Schedulers online ~p", [erlang:system_info(schedulers_online)]),
326335
PrevImpMod = jq:implementation_module(),
327336
jq:set_implementation_module(jq_nif),
328337
PrevImpMod.
@@ -337,6 +346,7 @@ trigger_global_gc() ->
337346

338347

339348
cleanup_nif(PrevImpMod) ->
349+
ct:pal("Cleanup NIF ~p", [erlang:system_info(schedulers_online)]),
340350
%% For some reason this seems to clean up NIF resources that are previously
341351
%% passed to timer:apply_after in the parameters list
342352
trigger_global_gc(),
@@ -348,7 +358,7 @@ cleanup_nif(PrevImpMod) ->
348358
receive timeout_done -> ok end,
349359
OuterSelf ! fixed
350360
end,
351-
NrOfSpawns = 1000,
361+
NrOfSpawns = 150,
352362
[spawn(TimerFun) || _ <- lists:seq(1, NrOfSpawns)],
353363
[receive fixed -> ok end || _ <- lists:seq(1, NrOfSpawns)],
354364
trigger_global_gc(),
@@ -357,11 +367,13 @@ cleanup_nif(PrevImpMod) ->
357367
jq:set_implementation_module(PrevImpMod).
358368

359369
setup_port() ->
370+
ct:pal("Setup Port, Schedulers online ~p", [erlang:system_info(schedulers_online)]),
360371
PrevImpMod = jq:implementation_module(),
361372
jq:set_implementation_module(jq_port),
362373
PrevImpMod.
363374

364375
cleanup_port(PrevImpMod) ->
376+
ct:pal("Cleanup Port"),
365377
application:stop(jq),
366378
jq:set_implementation_module(PrevImpMod).
367379

0 commit comments

Comments
 (0)