summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-25 10:38:45 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-25 10:38:45 +0000
commit48e05803fd9066677aec1e0881bbbf312ac5ce3b (patch)
treebb5227b06d56d05ca4077966518fadc35f1086ad /modules/simpletest
parentdc17b0f2cde258f2057510968c33b1e66e13ed86 (diff)
downloadbrdo-48e05803fd9066677aec1e0881bbbf312ac5ce3b.tar.gz
brdo-48e05803fd9066677aec1e0881bbbf312ac5ce3b.tar.bz2
- Patch #669794 by andypost, Josh Waihi, aspilicious: critical task: use savepoints for nested transactions.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/database_test.test18
1 files changed, 16 insertions, 2 deletions
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 3dc48b727..c09d9a312 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -2908,6 +2908,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
*/
protected function transactionOuterLayer($suffix, $rollback = FALSE) {
$connection = Database::getConnection();
+ $depth = $connection->transactionDepth();
$txn = db_transaction();
// Insert a single row into the testing table.
@@ -2925,6 +2926,13 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
$this->transactionInnerLayer($suffix, $rollback);
$this->assertTrue($connection->inTransaction(), t('In transaction after calling nested transaction.'));
+
+ if ($rollback) {
+ // Roll back the transaction, if requested.
+ // This rollback should propagate to the last savepoint.
+ $txn->rollback();
+ $this->assertTrue(($connection->transactionDepth() == $depth), t('Transaction has rolled back to the last savepoint after calling rollback().'));
+ }
}
/**
@@ -2939,12 +2947,18 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
protected function transactionInnerLayer($suffix, $rollback = FALSE) {
$connection = Database::getConnection();
+ $this->assertTrue($connection->inTransaction(), t('In transaction in nested transaction.'));
+
+ $depth = $connection->transactionDepth();
// Start a transaction. If we're being called from ->transactionOuterLayer,
// then we're already in a transaction. Normally, that would make starting
// a transaction here dangerous, but the database API handles this problem
// for us by tracking the nesting and avoiding the danger.
$txn = db_transaction();
+ $depth2 = $connection->transactionDepth();
+ $this->assertTrue($depth < $depth2, t('Transaction depth is has increased with new transaction.'));
+
// Insert a single row into the testing table.
db_insert('test')
->fields(array(
@@ -2957,9 +2971,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
if ($rollback) {
// Roll back the transaction, if requested.
- // This rollback should propagate to the the outer transaction, if present.
+ // This rollback should propagate to the last savepoint.
$txn->rollback();
- $this->assertTrue($txn->willRollback(), t('Transaction is scheduled to roll back after calling rollback().'));
+ $this->assertTrue(($connection->transactionDepth() == $depth), t('Transaction has rolled back to the last savepoint after calling rollback().'));
}
}