Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- startup_and_termination_test_() ->
- { "######### test startup and termination #########",
- setup,
- fun() ->
- ok
- end,
- fun(_Args) ->
- ok
- end,
- fun(_Args) -> [
- ?_test(test_init()),
- ?_test(test_stop())
- ]
- end }.
- test_init() ->
- ?debugMsg("-- starting init --"),
- Precision = 10,
- StepSize = 0.1, %1.0/Precision
- CheckInterval = 1000,
- MaxCpu = 0.9,
- MinFreeMemory = 256,
- Timer = checking_timer,
- M = em:new(),
- em:strict(M, timer, apply_after, [CheckInterval, heat_map_zone_recalc_inf_mgr, check_state, []], {return, {ok, Timer}}),
- em:replay(M),
- {ok, InitState} = heat_map_zone_recalc_inf_mgr:init([Precision, CheckInterval, MaxCpu, MinFreeMemory]),
- em:verify(M),
- ?assertEqual(Precision, InitState#state.precision),
- ?assertEqual(StepSize, InitState#state.step_size),
- ?assertEqual(CheckInterval, InitState#state.checking_interval),
- ?assertEqual(MaxCpu, InitState#state.max_cpu),
- ?assertEqual(MinFreeMemory, InitState#state.min_free_memory),
- ?assertEqual(Timer, InitState#state.checking_timer),
- ?assertNotEqual(undefined, ets:info(InitState#state.removed_avatars)),
- ?assertNotEqual(undefined, ets:info(InitState#state.added_avatars)),
- ets:delete(InitState#state.removed_avatars),
- ets:delete(InitState#state.added_avatars),
- ?debugMsg("-- finished init --"),
- ok.
- test_stop() ->
- ?debugMsg("-- starting stop --"),
- Timer = checking_timer,
- RemovedTable = ets:new(removed_avatars, [set]),
- AddedTable = ets:new(added_avatars, [set]),
- State = #state{checking_timer = Timer, added_avatars = AddedTable, removed_avatars = RemovedTable},
- M = em:new(),
- em:strict(M, timer, cancel, [Timer]),
- em:replay(M),
- ?assertEqual(ok, heat_map_zone_recalc_inf_mgr:stop(normal, State)),
- em:verify(M),
- ?assertEqual(undefined, ets:info(RemovedTable)),
- ?assertEqual(undefined, ets:info(AddedTable)),
- ?debugMsg("-- finished stop --"),
- ok.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement