tags:

views:

152

answers:

2

I am trying to write an automated test script for testing a MySQL Event that I created, and I am wondering if there is a way to execute some kind of command to force the Event to execute immediately. The Event is set to run daily at midnight, but I don't want the automated test script to have to wait for the Event to trigger.

One way I can think of is to ALTER the Event to have it execute one-time 5 seconds into the future, but I'd like to know if there is a more elegant way to do get it to execute.

A: 

if it is based on the system time, change that, and see if your event fires, then change the system time back.

KM
That is one way to get it to work...but I'd be a bit cautious about changing the system time for the tester. Especially since I've run into problems with MySQL databases and changing the system time.For example, if you change around the system time on a slave MySQL server in a replicated system, the time change breaks the replication process.
A: 
  1. Move all the code within the event into a stored procedure
  2. Make the event only call the stored procedure
  3. Test the stored procedure with the CALL syntax.
Evert
I actually prefer this solution to changing the system time...Is it generally considered good practice to have events call stored procedures rather than executing queries as part of the event's definition?
I've personally never used events, but this appears to be a good indicator this is a good practice :)
Evert