Testing a class that relies on timers
I have a class
RoutineManager
that uses another class TimerScheduler
to schedule different actions. This means that the timers decide the order of some function calls. I now need to test this. At first, I thought "oh I'll just mock the scheduler and make sure the functions get called", but quickly realised they won't be called in the correct order without the timers (which is the most important thing to test!). Does anyone have any suggestions of what I could do to test this? The only thing I can think of is changing the input to be in milliseconds instead of hours to make it quicker. However, I'm not sure timers are very reliable when you go down to single digit milliseconds or less (could be wrong), so it feels a bit hacky and potentially slow.11 Replies
The reason I use timers is because the entire idea of the program is to let users schedule the brightness/temperature of their smart lights in a layered and flexible way
timer *A is for setting the smart lights to the brightness/temperature for that block,
while timer *B is for setting the brightness/temperature to something else, since that block is no longer active
start and stop
...maybe a FakeScheduler that sorts the input based on time and executes one after another
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Hmm I wonder how this would be when you add a new routine in the middle of everything, or just generally change something
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Oh right I didn't use those words before. A routine is a block in the image. Basically a time span with a certain brightness/temperature
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
During initialization, all the routines are scheduled, but if a user then later adds a new one, it needs to be scheduled properly as well, and it might happen at any time
hmm
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hm
will think about it a bit