Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change testing to focus on chronos bookkeeping
The previous testing approach with the timer_expiry module (now gone) actually tested the Erlang timers a lot more than it tested the chronos functionality. chronos has been refactored to have a chronos_command module that is mocked using EQC to test that chronos works. The testing of chronos' bookkeeping has been changed to use eqc_component, which makes it a lot easier to understand what is going on. In addition to the eqc_component test three tests have been added which covers that chronos actually triggers things, that restarting a timer works as expected and that you can cancel a timer and not see anything being triggered. The test has been simplified to only start one server as it did not add anything but more bookkeeping in the test. A new `start/0` function has been added to allow starting nameless servers. The README has been updated with sections on how to test with EQC mocking, linking approach and a small road-map. When a chronos server exists it will no longer cancel all the timers. This is not necessary since all timers have the chroons server pid as the destination and will be removed automatically when the process stops.
- Loading branch information
Showing
5 changed files
with
387 additions
and
186 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{application, chronos, [ | ||
{description, "chronos - a timer utility for Erlang"}, | ||
{vsn, "0.1.4"}, | ||
{modules, ['chronos']}, | ||
{vsn, git}, | ||
{modules, [chronos, chronos_command]}, | ||
{registered, []}, | ||
{applications, [kernel,stdlib]} | ||
]}. | ||
]}. |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-module(chronos_command). | ||
|
||
|
||
-export([start_timer/2, | ||
cancel_timer/1, | ||
execute_callback/1]). | ||
|
||
|
||
-spec start_timer(non_neg_integer, chronos:timer_name()) -> | ||
'ok' | {'error', term()}. | ||
start_timer(Duration, TimerName) -> | ||
erlang:start_timer(Duration, self(), TimerName). | ||
|
||
-spec cancel_timer(reference()) -> non_neg_integer() | 'false'. | ||
cancel_timer(TRef) -> | ||
erlang:cancel_timer(TRef). | ||
|
||
-spec execute_callback(chronos:callback()) -> 'ok'. | ||
execute_callback({Mod, Fun, Args}) -> | ||
% We spawn a function to execute the apply because we want to protect the timer | ||
% server against errors. Might need to log this. | ||
spawn ( fun() -> | ||
erlang:apply(Mod, Fun, Args) | ||
end ). | ||
|
||
|
||
|
Oops, something went wrong.