Yeti
Yeti

Reputation: 5818

How to simulate "MYSQL has gone away" error?

I'm running lots of cron job and once in a while there is a MYSQL has gone away error.

I've now written some code to handle the error, but how do I simulate the error on my localhost so that the code can be tested thoroughly?

Upvotes: 9

Views: 3343

Answers (3)

Gordon
Gordon

Reputation: 317177

Mock the (affected method in the) Database adapter and have it raise the error. That's the usual approach when unit-testing code that has dependencies on external resources. If you are not using PHPUnit yet, this is a great opportunity to get started with it.

Further reading

Upvotes: 3

Toby Allen
Toby Allen

Reputation: 11211

If it was on another machine you could unplug the network cable!

Upvotes: 5

nickf
nickf

Reputation: 546393

Kill a long-running thread.

See: KILL syntax

The documentation about that error also lists different causes, so you could emulate some of them (eg: change the timeout to be very low, etc).

Upvotes: 11

Related Questions