Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.93 KB | None | 0 0
  1. startup_and_termination_test_() ->
  2.   { "######### test startup and termination #########",
  3.     setup,
  4.     fun() ->
  5.       ok
  6.     end,
  7.     fun(_Args) ->
  8.       ok
  9.     end,
  10.     fun(_Args) -> [
  11.       ?_test(test_init()),
  12.       ?_test(test_stop())
  13.     ]
  14.     end }.
  15.  
  16.  
  17. test_init() ->
  18.   ?debugMsg("-- starting init --"),
  19.   Precision = 10,
  20.   StepSize = 0.1, %1.0/Precision
  21.   CheckInterval = 1000,
  22.   MaxCpu = 0.9,
  23.   MinFreeMemory = 256,
  24.   Timer = checking_timer,
  25.   M = em:new(),
  26.   em:strict(M, timer, apply_after, [CheckInterval, heat_map_zone_recalc_inf_mgr, check_state, []], {return, {ok, Timer}}),
  27.   em:replay(M),
  28.   {ok, InitState} = heat_map_zone_recalc_inf_mgr:init([Precision, CheckInterval, MaxCpu, MinFreeMemory]),
  29.   em:verify(M),
  30.   ?assertEqual(Precision, InitState#state.precision),
  31.   ?assertEqual(StepSize, InitState#state.step_size),
  32.   ?assertEqual(CheckInterval, InitState#state.checking_interval),
  33.   ?assertEqual(MaxCpu, InitState#state.max_cpu),
  34.   ?assertEqual(MinFreeMemory, InitState#state.min_free_memory),
  35.   ?assertEqual(Timer, InitState#state.checking_timer),
  36.   ?assertNotEqual(undefined, ets:info(InitState#state.removed_avatars)),
  37.   ?assertNotEqual(undefined, ets:info(InitState#state.added_avatars)),
  38.  
  39.   ets:delete(InitState#state.removed_avatars),
  40.   ets:delete(InitState#state.added_avatars),
  41.   ?debugMsg("-- finished init --"),
  42.   ok.
  43.  
  44. test_stop() ->
  45.   ?debugMsg("-- starting stop --"),
  46.   Timer = checking_timer,
  47.   RemovedTable = ets:new(removed_avatars, [set]),
  48.   AddedTable = ets:new(added_avatars, [set]),
  49.   State = #state{checking_timer = Timer, added_avatars = AddedTable, removed_avatars = RemovedTable},
  50.   M = em:new(),
  51.   em:strict(M, timer, cancel, [Timer]),
  52.   em:replay(M),
  53.   ?assertEqual(ok, heat_map_zone_recalc_inf_mgr:stop(normal, State)),
  54.   em:verify(M),
  55.   ?assertEqual(undefined, ets:info(RemovedTable)),
  56.   ?assertEqual(undefined, ets:info(AddedTable)),
  57.   ?debugMsg("-- finished stop --"),
  58.   ok.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement