|Do you know where your variables are?|
Re: Testing transactionsby roboticus (Canon)
|on Jan 24, 2008 at 12:18 UTC||Need Help??|
For a simple method, have your test code open *two* handles to the database. Then start the first transaction on one item, then start the second transaction, and switch back and forth as desired.
Slightly better might be two create two threads or processes and insert some time delays at various points to "usually" interleave the bits you want to test. (Usually because it won't be deterministic, as timing variations will come into play. But usually this is good enough.)
If "good enough" isn't good enough ;^), you could always add mutexes, semaphores, or even directory creation/removal to enforce interleaving.
However, I haven't used Dbix::Class before, so I don't know if anything in it would invalidate what I said. I'm also assuming that your transactions have multiple steps that you control.
The techniques I suggested won't work for testing transactions that use a single call to the database. For that, you may want to write your own DBD class so you can monitor which actions occur when, and put in your own delays and/or semaphores or state variables to encourage actions to occur in the desired order for testing.
I hope this is useful....