jenkins-bot has submitted this change and it was merged.
Change subject: Bug: incorect row insert with phpunit temp tables
......................................................................
Bug: incorect row insert with phpunit temp tables
I wrote this unit test for a followup patch that does blob
encoding of the binary values. It turned up an unrelated bug
that prevented inserting more than 2 levels deep in unit test
tables being doubled as temp tables in a unit test.
Patch adds a test and fixes the bug, which was a simple oversight
and made the query different than the one used in prod via
insertSelect
Change-Id: I106c905d56702541803c008e6d9fa8bd5f7c39ec
---
M includes/Repository/TreeRepository.php
A tests/phpunit/Repository/TreeRepositoryDbTest.php
2 files changed, 85 insertions(+), 2 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Repository/TreeRepository.php
b/includes/Repository/TreeRepository.php
index 549ebf2..aced0a7 100644
--- a/includes/Repository/TreeRepository.php
+++ b/includes/Repository/TreeRepository.php
@@ -138,7 +138,7 @@
// @todo: needs to be done for ALL depths, not
just one
$rows = $dbw->select(
$this->tableName,
- array( 'tree_depth' ),
+ array( 'tree_depth', 'tree_ancestor_id'
),
array( 'tree_descendant_id' =>
$ancestor->getBinary() ),
__METHOD__
);
@@ -149,7 +149,7 @@
$this->tableName,
array(
'tree_descendant_id' =>
$descendant->getBinary(),
- 'tree_ancestor_id' =>
$ancestor->getBinary(),
+ 'tree_ancestor_id' =>
$row->tree_ancestor_id,
'tree_depth' =>
$row->tree_depth + 1,
),
__METHOD__
diff --git a/tests/phpunit/Repository/TreeRepositoryDbTest.php
b/tests/phpunit/Repository/TreeRepositoryDbTest.php
new file mode 100644
index 0000000..a439b8a
--- /dev/null
+++ b/tests/phpunit/Repository/TreeRepositoryDbTest.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Flow\Tests\Repository;
+
+use Flow\Container;
+use Flow\Data\BagOStuff\BufferedBagOStuff;
+use Flow\Data\BufferedCache;
+use Flow\Model\UUID;
+use Flow\Repository\TreeRepository;
+use Flow\Tests\FlowTestCase;
+
+/**
+ * @group Flow
+ * @group Database
+ */
+class TreeRepositorydbTest extends FlowTestCase {
+ protected $tablesUsed = array( 'flow_tree_node' );
+
+ public function testSomething() {
+ // meaningless set of ids used for repeatability
+ $ids = array_map( array( 'Flow\Model\UUID', 'create' ), array(
+ "s3z44zhp93j5vvc8", "s3z44zhqt7yt8220",
"s46w00pmmw0otc0q",
+ "s3qvc7cnor86wvb4", "s3qvc7bbcxr3f340",
+ "s3gre9r27pobtg0n", "s3cdl3dfqf8brx18",
"s3cdl3dhajnz43r0",
+ ) );
+
+ // Use 2 repos with 2 caches, the one you insert with reads
from cache
+ // the other reads from db due to different cache
+ $cache[] = new BufferedCache( new BufferedBagOStuff( new
\HashBagOStuff() ), 600 );
+ $cache[] = new BufferedCache( new BufferedBagOStuff( new
\HashBagOStuff() ), 600 );
+ $dbf = Container::get( 'db.factory' );
+ $repo[] = new TreeRepository( $dbf, $cache[0] );
+ $repo[] = new TreeRepository( $dbf, $cache[1] );
+
+ // id0 as new root
+ wfDebugLog( 'Flow', "\n\n************** id0 as new root
************" );
+ $repo[0]->insert( $ids[0] );
+ $this->assertEquals(
+ array( $ids[0] ),
+ $repo[0]->findRootPath( $ids[0] )
+ );
+ $this->assertEquals(
+ array( $ids[0] ),
+ $repo[1]->findRootPath( $ids[0] )
+ );
+
+ // id1 as child of id0
+ wfDebugLog( 'Flow', "\n\n************** id1 as child of id0
************" );
+ $repo[0]->insert( $ids[1], $ids[0] );
+ $this->assertEquals(
+ array( $ids[0], $ids[1] ),
+ $repo[0]->findRootPath( $ids[1] )
+ );
+ $this->assertEquals(
+ array( $ids[0], $ids[1] ),
+ $repo[1]->findRootPath( $ids[1] )
+ );
+
+ // id2 as child of id0
+ wfDebugLog( 'Flow', "\n\n************** id2 as child of id0
************" );
+ $repo[0]->insert( $ids[2], $ids[0] );
+ $this->assertEquals(
+ array( $ids[0], $ids[2] ),
+ $repo[0]->findRootPath( $ids[2] )
+ );
+ $this->assertEquals(
+ array( $ids[0], $ids[2] ),
+ $repo[1]->findRootPath( $ids[2] )
+ );
+
+ // id3 as child of id1
+ wfDebugLog( 'Flow', "\n\n************** id3 as child of id1
************" );
+ $repo[0]->insert( $ids[3], $ids[1] );
+ $this->assertEquals(
+ array( $ids[0], $ids[1], $ids[3] ),
+ $repo[0]->findRootPath( $ids[3] )
+ );
+ $this->assertEquals(
+ array( $ids[0], $ids[1], $ids[3] ),
+ $repo[1]->findRootPath( $ids[3] )
+ );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/171854
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I106c905d56702541803c008e6d9fa8bd5f7c39ec
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits