Adding remove-feature to Cron-Class (#6)

* Adding functions to remove a specific schedule (by the given name) or all scheduled tasks from the Cron class.

* Update libcron/include/libcron/Task.h

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>

* Update libcron/include/libcron/Task.h

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>

* Update libcron/include/libcron/Cron.h

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>

* Update libcron/include/libcron/Cron.h

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>

* Update libcron/include/libcron/Cron.h

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>

* Adding Multithreading support via template, adding documentation

* Apply suggestions from code review

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>

* Finishing suggestions from code-review (renaming elements)

Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>
This commit is contained in:
Heinz-Peter Liechtenecker
2020-09-02 15:57:14 +02:00
committed by GitHub
parent 440f5099ba
commit 76da315c13
4 changed files with 248 additions and 20 deletions

View File

@@ -334,4 +334,71 @@ SCENARIO("Multiple ticks per second")
}
}
}
SCENARIO("Tasks can be added and removed from the scheduler")
{
GIVEN("A Cron instance with no task")
{
Cron<> c;
auto expired = false;
WHEN("Adding 5 tasks that runs every second")
{
REQUIRE(c.add_schedule("Task-1", "* * * * * ?",
[&expired]()
{
expired = true;
})
);
REQUIRE(c.add_schedule("Task-2", "* * * * * ?",
[&expired]()
{
expired = true;
})
);
REQUIRE(c.add_schedule("Task-3", "* * * * * ?",
[&expired]()
{
expired = true;
})
);
REQUIRE(c.add_schedule("Task-4", "* * * * * ?",
[&expired]()
{
expired = true;
})
);
REQUIRE(c.add_schedule("Task-5", "* * * * * ?",
[&expired]()
{
expired = true;
})
);
THEN("Count is 5")
{
REQUIRE(c.count() == 5);
}
AND_THEN("Removing all scheduled tasks")
{
c.clear_schedules();
REQUIRE(c.count() == 0);
}
AND_THEN("Removing a task that does not exist")
{
c.remove_schedule("Task-6");
REQUIRE(c.count() == 5);
}
AND_THEN("Removing a task that does exist")
{
c.remove_schedule("Task-5");
REQUIRE(c.count() == 4);
}
}
}
}