Hi everyone,
I've setup the versionable behavior for 'Address' table, but when I'm trying to run PHPUnit tests i've got following error:
SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
I have 2 'test*' methods on my testCase. If I leave only 1 then it works, if > 1 - then i gets that error.
Here is the code:
class UserTest extends DbTestCase {
protected $object;
protected function setUp()
{
// zf bootstrap here and doctrine connect
parent::setUp();
// clean/create tmp tables
$this->_prepareDB();
$this->object = new User;
}
public function testGetFullUsername()
{
$model = new User;
$model->email = $email . time();
...
$model->Supplier->Address->firstname = $first_name;
$model->Supplier->Address->lastname = $last_name;
...
$model->UserRight[0]->role = 'Supplier';
$model->UserRight[0]->resource = '*';
$model->UserRight[0]->privilege = '';
$model->save();
}
// it can be even the same
public function testRoles()
{
$model = new User;
$model->email = $email . time();
...
$model->Supplier->Address->firstname = $first_name;
$model->Supplier->Address->lastname = $last_name;
...
$model->UserRight[0]->role = 'Supplier';
$model->UserRight[0]->resource = '*';
$model->UserRight[0]->privilege = '';
$model->save();
}
}
When PHPunit runs the second method transactions ends and starts another one:
// 1st method
// thread id: 412
START TRANSACTION
INSERT INTO user (...) VALUES (...)
INSERT INTO a开发者_开发问答ddress (...) VALUES ('...')
INSERT INTO address_version (...) VALUES (...)
INSERT INTO supplier (...) VALUES (...)
INSERT INTO user_right (...) VALUES (..)
commit
// 2nd method
// thread id: 413
START TRANSACTION
INSERT INTO user (...) VALUES (...)
INSERT INTO address (..) VALUES (...)
// then new thread created (server disconnects), id: 414
CONNECT xxxxx@localhost on xxxx__tmp_testing
START TRANSACTION
INSERT INTO address_version (...) VALUES (...)
rollback
rollback
It drops the connection, but I don't know why. If I remove 'Versionable' behavior - then it works!
Can You please help me. I'm really stack with it and don't know the error reason :(
Thanks for Your attention!
UPDATE:
The reason was in "versionable" plugin. We have to disable it in phpunit tests: $account->Distributor->Address->getListener()->setOption('disabled', true); Versionable attached to 'Address' model It fixes the problem.
I had the same problem with lot's of REPLACE/INSERT-queries.
I could workaround the problem with initializing persistent connections in phpunit.
// {{{ getConnection()
/**
* gets database connection
*/
protected function getConnection() {
$pdo = new pdo("mysql:dbname=depage_phpunit;host=localhost", "root", "", array(
\PDO::ATTR_PERSISTENT => true,
));
return $this->createDefaultDBConnection($pdo, 'testdb');
}
// }}}
精彩评论