aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/test/diameter_stats_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/diameter/test/diameter_stats_SUITE.erl')
-rw-r--r--lib/diameter/test/diameter_stats_SUITE.erl92
1 files changed, 66 insertions, 26 deletions
diff --git a/lib/diameter/test/diameter_stats_SUITE.erl b/lib/diameter/test/diameter_stats_SUITE.erl
index e7807fd360..4a93d4f748 100644
--- a/lib/diameter/test/diameter_stats_SUITE.erl
+++ b/lib/diameter/test/diameter_stats_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -30,11 +30,12 @@
end_per_suite/1]).
%% testcases
--export([an/1,
- twa/1]).
+-export([reg/1,
+ incr/1,
+ read/1,
+ flush/1]).
-define(stat, diameter_stats).
--define(util, diameter_util).
%% ===========================================================================
@@ -49,8 +50,10 @@ groups() ->
[{all, [], tc()}].
tc() ->
- [an,
- twa].
+ [reg,
+ incr,
+ read,
+ flush].
init_per_suite(Config) ->
ok = diameter:start(),
@@ -61,25 +64,62 @@ end_per_suite(_Config) ->
%% ===========================================================================
-an(_) ->
- Ref = {'_', make_ref()},
+reg(_) ->
+ Ref = '$1',
true = ?stat:reg(Ref),
- true = ?stat:reg(Ref), %% duplicate
- ok = ?stat:incr(x),
- ok = ?stat:incr(x, Ref),
- ok = ?stat:incr(y, 2),
- ok = ?stat:incr(y, Ref),
- %% Flushing a pid flushes even stats on the registered reference.
- [{x,2},{y,3}] = lists:sort(?stat:flush()),
- [] = ?stat:flush(Ref),
- [] = ?stat:flush().
-
-twa(_) ->
+ false = ?stat:reg(Ref). %% duplicate
+
+incr(_) ->
+ Ref = '_',
+ Ctr = x,
+ false = ?stat:incr(Ctr), %% not registered,
+ 1 = ?stat:incr(Ctr, Ref, 1), %% only pids need register
+ true = ?stat:reg(Ref),
+ spawn(fun() ->
+ true = ?stat:reg(Ref),
+ 2 = ?stat:incr(Ctr, self(), 2)
+ end),
+ ok = fold(Ctr, Ref, 3), %% folded
+ ?stat:flush([self(), Ref]).
+
+read(_) ->
+ Ref = make_ref(),
+ C1 = {a,b},
+ C2 = {b,a},
+ true = ?stat:reg(Ref),
+ 1 = ?stat:incr(C1),
+ 1 = ?stat:incr(C2),
+ 2 = ?stat:incr(C1),
+ 7 = ?stat:incr(C1, Ref, 7),
+ Self = self(),
+ [{Ref, [{C1,7}]}, {Self, [{C1,2}, {C2,1}]}]
+ = lists:sort(?stat:read([self(), Ref, make_ref()])),
+ [] = ?stat:read([]),
+ [] = ?stat:read([make_ref()]),
+ ?stat:flush([self(), Ref, make_ref()]).
+
+flush(_) ->
Ref = make_ref(),
- ok = ?stat:incr(x, 8),
- ok = ?stat:incr(x, Ref, 7),
- %% Flushing a reference doesn't affect registered pids.
- [{x,7}] = ?stat:flush(Ref),
- [] = ?stat:flush(Ref),
- [{x,8}] = ?stat:flush(),
- [] = ?stat:flush().
+ Ctr = '_',
+ true = ?stat:reg(Ref),
+ 1 = ?stat:incr(Ctr),
+ 3 = ?stat:incr(Ctr, self(), 2),
+ 2 = ?stat:incr(Ctr, Ref, 2),
+ Self = self(),
+ [{Self, [{Ctr, 3}]}] = ?stat:flush([self()]),
+ 1 = ?stat:incr(Ctr),
+ [{Ref, [{Ctr, 2}]}] = ?stat:flush([Ref]),
+ [{Self, [{Ctr, 1}]}] = ?stat:flush([self()]),
+ [] = ?stat:flush([self(), Ref]).
+
+%% ===========================================================================
+
+%% Keep incremented until a fold results in the specified value.
+fold(Ctr, Ref, N) ->
+ case ?stat:incr(Ctr, Ref, 0) of
+ N ->
+ ok;
+ M when M < N ->
+ erlang:yield(),
+ fold(Ctr, Ref, N)
+ end.