Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update process_relation_test, and make it and ets_r_t run without eunit.
- Loading branch information
1 parent
10df17f
commit 645cd2c
Showing
3 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
-module(ets_race_tests). | |||
|
|||
-compile(export_all). | |||
|
|||
-include("triq.hrl"). | |||
-include("unit.hrl"). | |||
|
|||
% ../../../../../jerl -sname erj -pz ../../../../../triq/ebin | |||
% c(ets_race_tests, [{i, "../../../../../triq/include"}]). | |||
% ets_race_tests:test(). | |||
|
|||
%%%========== Entry point: ==================== | |||
test() -> | |||
eunit_test(?MODULE). | |||
|
|||
give_away_die_race_test() -> | |||
N = 10000, | |||
expect_to_leave_N_tables(0, | |||
fun() -> | |||
[give_away_die_race() | |||
|| _ <- lists:seq(1,N)] | |||
end). | |||
|
|||
give_away_die_race() -> | |||
Pid = spawn(fun() -> ok end), | |||
%Tab = ets:new(foo, [{heir, Pid, here_you_are}]), | |||
Tab = ets:new(foo, []), | |||
try ets:give_away(Tab, Pid, here_you_are) | |||
catch _:badarg -> ets:delete(Tab) | |||
end. | |||
|
|||
|
|||
|
|||
|
|||
expect_to_leave_N_tables(N, Action) when is_integer(N), | |||
is_function(Action,0) -> | |||
Before = ets:all(), | |||
Action(), | |||
timer:sleep(500), | |||
After = ets:all(), | |||
?assertEqual(N, length(After -- Before)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
-ifndef(_unit_hrl_included_). | |||
-define(_unit_hrl_included_,yes). | |||
|
|||
eunit_test(Module) -> | |||
TestFunctions = [F || {F,0} <- Module:module_info(exports), | |||
lists:suffix("_test", atom_to_list(F))], | |||
io:format("========== Running test suite ~s ==========\n", [Module]), | |||
Results = | |||
lists:map(fun(F) -> | |||
io:format("---------- Running test ~s ----------\n", [F]), | |||
Res = try Module:F(), | |||
true | |||
catch _:Err -> | |||
io:format("*** Exception: ~p\n", [Err]), | |||
false | |||
end, | |||
io:format(" ----- Test ~s ~s -----\n", | |||
[F, case Res of | |||
true -> "SUCCEEDED"; | |||
false -> "FAILED" | |||
end]), | |||
{F,Res} | |||
end, | |||
TestFunctions), | |||
FailedTests = [F || {F,Res} <- Results, not Res], | |||
io:format(" ===== Test suite ~s: Tests: ~p Failed: ~p =====\n", | |||
[Module, length(TestFunctions), length(FailedTests)]), | |||
case FailedTests of | |||
[] -> | |||
ok; | |||
_ -> | |||
error({test_suite_failed, Module, FailedTests}) | |||
end. | |||
|
|||
-define(assertEqual(Expected,Actual), | |||
(fun(X,X) -> ok; | |||
(Exp,Act) -> error({assertion_failed, | |||
{line,?LINE}, | |||
{expr, ??Actual}, | |||
{expected_value, Exp}, | |||
{actual_value, Act}}) | |||
end)(Expected,Actual)). | |||
|
|||
-endif. |