views:

48

answers:

1

Hello,

I have a strange bug. I launch a PHP Unit test Suite. At the beginning, it executes a big query to initialize the database.

If I put a breakpoint just after the execution of the sql, there is no problem and my tests pass.

If I don't put any break point, they don't pass and say that the tables don't exist!

It works as if the sql query was asynchronous!

Do you have an idea of the bug? Or how to debug that?

Thanks a lot in advance for your help, I'm lost!

Farf

A: 

To debug this, you need to look at the query log - particularly at the sequence of events around the point where the data load finishes, and the first unit test begins. Has a drop database snuck in from somewhere ?

The query log is switched on using a setting in the config file:

MySQL Manual - 5.1.2 Server Command Options

You can switch the log on and off again from within the MySQL command line tool, but the file it writes to needs to be configured in the config file and the server restarted.

I have tripped over a similar problem before in a test environment using replicas - I eventually found that I was writing to the master and reading from the replica. Sometimes, if replication was fast enough, some tests would pass. Be careful that your tests are doing what you think they are doing.

Martin
Could try using a transaction too. more info here - http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-transactions.html
danp