diff options
author | Sverker Eriksson <[email protected]> | 2017-04-04 15:10:16 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2017-04-04 15:10:16 +0200 |
commit | 781fbe4f35ef6d9281a6310a595260fdec0ed2ec (patch) | |
tree | d5748786739b4e6df965eeeee9dd446ae59a2065 | |
parent | be959b91c655a5f7ab89034e285d17465f0912b1 (diff) | |
download | otp-781fbe4f35ef6d9281a6310a595260fdec0ed2ec.tar.gz otp-781fbe4f35ef6d9281a6310a595260fdec0ed2ec.tar.bz2 otp-781fbe4f35ef6d9281a6310a595260fdec0ed2ec.zip |
stdlib: Limit ets_SUITE:smp_select_replace
to run 3*3 seconds to avoid timeout on slow machines.
-rw-r--r-- | lib/stdlib/test/ets_SUITE.erl | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index f11ad01c16..2dfd481665 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -5637,40 +5637,43 @@ smp_select_delete(Config) when is_list(Config) -> ets:delete(T). smp_select_replace(Config) when is_list(Config) -> - lists:foreach( - fun (TableType) -> - T = ets_new(smp_select_replace, [TableType, named_table, public, - {write_concurrency, true}]), - WorkerCount = 20, - CounterIterations = 10000, - InitF = fun (_) -> no_state end, - ExecF = fun (State) -> - lists:foreach( - fun F(IterId) -> - CounterId = rand:uniform(WorkerCount), - Match = [{{'$1', '$2'}, - [{'=:=', '$1', CounterId}], - [{{'$1', {'+', '$2', 1}}}]}], - case ets:select_replace(T, Match) of - 1 -> ok; - 0 -> - ets:insert_new(T, {CounterId, 1}) orelse - F(IterId) - end - end, - lists:seq(1, CounterIterations)), - State - end, - FiniF = fun (State) -> State end, - run_sched_workers(InitF, ExecF, FiniF, WorkerCount), - FinalCounts = ets:select(T, [{{'_', '$1'}, [], ['$1']}]), - TotalIterations = WorkerCount * CounterIterations * erlang:system_info(schedulers), - TotalIterations = lists:sum(FinalCounts), - WorkerCount = ets:select_delete(T, [{{'_', '_'}, [], [true]}]), - 0 = ets:info(T, size), - ets:delete(T) - end, - [ordered_set, set, duplicate_bag]). + repeat_for_opts(fun smp_select_replace_do/1, + [[set,ordered_set,duplicate_bag]]). + +smp_select_replace_do(Opts) -> + T = ets_new(smp_select_replace, + [public, {write_concurrency, true} | Opts]), + ObjCount = 20, + InitF = fun (_) -> 0 end, + ExecF = fun (Cnt0) -> + CounterId = rand:uniform(ObjCount), + Match = [{{'$1', '$2'}, + [{'=:=', '$1', CounterId}], + [{{'$1', {'+', '$2', 1}}}]}], + Cnt1 = case ets:select_replace(T, Match) of + 1 -> Cnt0+1; + 0 -> + ets:insert_new(T, {CounterId, 0}), + Cnt0 + end, + receive stop -> + [end_of_work | Cnt1] + after 0 -> + Cnt1 + end + end, + FiniF = fun (Cnt) -> Cnt end, + Pids = run_sched_workers(InitF, ExecF, FiniF, infinite), + receive after 3*1000 -> ok end, + [P ! stop || P <- Pids], + Results = wait_pids(Pids), + FinalCounts = ets:select(T, [{{'_', '$1'}, [], ['$1']}]), + Total = lists:sum(FinalCounts), + Total = lists:sum(Results), + ObjCount = ets:select_delete(T, [{{'_', '_'}, [], [true]}]), + 0 = ets:info(T, size), + true = ets:delete(T), + ok. %% Test different types. types(Config) when is_list(Config) -> @@ -5906,7 +5909,7 @@ run_sched_workers(InitF,ExecF,FiniF,Laps) -> erlang:system_info(schedulers)). run_workers_do(InitF,ExecF,FiniF,Laps, NumOfProcs) -> - io:format("smp starting ~p workers\n",[NumOfProcs]), + io:format("starting ~p workers\n",[NumOfProcs]), Seeds = [{ProcN,rand:uniform(9999)} || ProcN <- lists:seq(1,NumOfProcs)], Parent = self(), Pids = [my_spawn_link(fun()-> worker(Seed,InitF,ExecF,FiniF,Laps,Parent,NumOfProcs) end) |