This blog post is about the test cases for timer app using PhantomJS and test machine created. The tests involves creation of timer files, checking if the timer files are created and runs at the specified time. The test machine is set to UTC 2020–01–01 15:30:00 time initially.
Here is a detailed info about how to run tests in cockpit.
The test begins by checking for error messages when the user inputs are invalid.
The test checks if yearly_timer runs on 2020–01–01 16:00 and 2021–01–01 01:22 by checking the outputs of systemctl list-timers on 2020–01–01 15:30 and 2020–01–01 16:10 respectively.
Monthly timers are used to repeat events on mentioned dates every month.
The monthly timer tests checks if monthly_timer runs on Jan 6th 2020 at 16:00, Jan 8th 2020 at 21:12 and similarly on the next months Feb 6th and March 8th as well. We assert that the outputs are correct.
self.assertIn("Sun 2020-03-08 21:12", m.execute("LC_ALL=C systemctl list-timers"))
Avoid end of the month days as they don’t repeat every month.
Weekly timers are used to repeat events on the mentioned week-days every week.
Weekly timer runs on every week’s Friday at 12:45 and Sunday at 20:12. We test if it runs on Fri 2020–03–13 12:45, Sun 2020–03–15 20:12 and its subsequent week as well.
Daily timers are used to repeat events on the mentioned hours and minutes every day.
Daily timer runs on 2020–03–17 at 02:40 and 21:15 and we check again on 2020–04–10 at 02:40 and 21:15 to see if repeats daily.
Hourly timers are used to repeat events on the mentioned minutes every hour.
We check hourly_timer runs at 5 min and 26 min past 3 am and 4 am of 2020–04–10 for hourly repeats.
Timer that doesn’t repeat
We set a no_repeat_timer to be run exactly on Fri 2020–04–10 23:59. This timer only runs on the specified time only and it doesn’t repeat.
self.assertIn("Fri 2020-04-10 23:59", m.execute("LC_ALL=C systemctl list-timers")
A boot timer is setup which starts 2 seconds after boot.
We make the test machine reboot and checks if the file /tmp/hello was created.