jenkins-bot has submitted this change and it was merged. Change subject: Merge branch 'master' into deployment ......................................................................
Merge branch 'master' into deployment cc437c9 Don't delete pending data for failed:review 2caa19b Fix all db subclasses sharing a PDO and delete tests Change-Id: Ice426b3e460db2e1143cb3c3257d4cba31c93c6c --- D Tests/DamagedDatabaseTest.php D Tests/PendingQueueConsumerTest.php D Tests/TestingDatabase.php 3 files changed, 0 insertions(+), 309 deletions(-) Approvals: Ejegg: Looks good to me, approved jenkins-bot: Verified diff --git a/Tests/DamagedDatabaseTest.php b/Tests/DamagedDatabaseTest.php deleted file mode 100644 index 595712a..0000000 --- a/Tests/DamagedDatabaseTest.php +++ /dev/null @@ -1,141 +0,0 @@ -<<<<<<< HEAD (55fc9f Revert "Revert "Check payments_init for 'failed' in pending ) -======= -<?php - -namespace SmashPig\Tests; - -use PDO; -use SmashPig\Core\Context; -use SmashPig\Core\DataStores\DamagedDatabase; - -class DamagedDatabaseTest extends BaseSmashPigUnitTestCase { - - /** - * @var DamagedDatabase - */ - protected $db; - - public function setUp() { - parent::setUp(); - $config = SmashPigDatabaseTestConfiguration::instance(); - Context::initWithLogger( $config ); - $this->db = DamagedDatabase::get(); - $this->db->createTable(); - } - - public function tearDown() { - TestingDatabase::clearStatics( $this->db ); - parent::tearDown(); - } - - protected static function getTestMessage( $uniq = null ) { - if ( !$uniq ) { - $uniq = mt_rand(); - } - return array( - 'gateway' => 'test', - 'gateway_txn_id' => "txn-{$uniq}", - 'order_id' => "order-{$uniq}", - 'gateway_account' => 'default', - 'date' => 1468973648, - 'amount' => 123, - 'currency' => 'EUR', - ); - } - - public function testStoreMessage() { - $message = self::getTestMessage(); - $queue = 'test_queue'; - $err = 'ERROR MESSAGE'; - $trace = "Foo.php line 25\nBar.php line 99"; - - $this->db->storeMessage( $message, $queue, $err, $trace ); - - // Confirm work without using the API. - $pdo = $this->db->getDatabase(); - $result = $pdo->query( " - SELECT * FROM damaged - WHERE gateway='test' - AND order_id = '{$message['order_id']}'" ); - $rows = $result->fetchAll( PDO::FETCH_ASSOC ); - $this->assertEquals( 1, count( $rows ), - 'One row stored and retrieved.' ); - $expected = array( - 'id' => '1', - # NOTE: This is a db-specific string, sqlite3 in this case, and - # you'll have different formatting if using any other database. - 'original_date' => '20160720001408', - 'gateway' => 'test', - 'order_id' => $message['order_id'], - 'gateway_txn_id' => $message['gateway_txn_id'], - 'message' => json_encode( $message ), - 'original_queue' => $queue, - 'error' => $err, - 'trace' => $trace, - 'retry_date' => null, - ); - unset( $rows[0]['damaged_date'] ); - $this->assertEquals( $expected, $rows[0], - 'Stored message had expected contents' ); - } - - public function testFetchRetryMessages() { - $message = self::getTestMessage(); - $this->db->storeMessage( $message, 'test_queue', '', '', time() - 1 ); - - $fetched = $this->db->fetchRetryMessages( 10 ); - - $this->assertNotNull( $fetched, - 'No record retrieved by fetchRetryMessages.' ); - - $expected = $message + array( - 'damaged_id' => 1, - 'original_queue' => 'test_queue' - ); - $this->assertEquals( $expected, $fetched[0], - 'Fetched record does not matches stored message.' ); - } - - public function testDeleteMessage() { - $uniq = mt_rand(); - $queue = 'test_queue'; - $message1 = $this->getTestMessage( $uniq ); - // Store a second message for a good time, and make sure we delete the - // right one. - $message2 = $this->getTestMessage( $uniq ); - - $this->db->storeMessage( $message1, $queue ); - // store message 2 with a - $this->db->storeMessage( $message2, $queue ); - - // Confirm work without using the API. - $pdo = $this->db->getDatabase(); - $result = $pdo->query( " - SELECT * FROM damaged - WHERE gateway='test' - AND order_id = '{$message1['order_id']}'" ); - $rows = $result->fetchAll( PDO::FETCH_ASSOC ); - $this->assertEquals( 2, count( $rows ), - 'Both records were stored.' ); - $this->assertNotNull( $rows[0]['id'], - 'Record includes a primary row id' ); - $this->assertNotEquals( $rows[0]['id'], $rows[1]['id'], - 'Records have unique primary ids' ); - - $message2['damaged_id'] = $rows[1]['id']; - $this->db->deleteMessage( $message2 ); - - // Confirm work without using the API. - $pdo = $this->db->getDatabase(); - $result = $pdo->query( " - SELECT * FROM damaged - WHERE gateway='test' - AND order_id = '{$message1['order_id']}'" ); - $rowsAfter = $result->fetchAll( PDO::FETCH_ASSOC ); - $this->assertEquals( 1, count( $rowsAfter ), - 'Not only one row deleted.' ); - $this->assertEquals( $rowsAfter[0]['id'], $rows[0]['id'], - 'Deleted the wrong row.' ); - } -} ->>>>>>> BRANCH (2caa19 Fix all db subclasses sharing a PDO) diff --git a/Tests/PendingQueueConsumerTest.php b/Tests/PendingQueueConsumerTest.php deleted file mode 100644 index 7103dcd..0000000 --- a/Tests/PendingQueueConsumerTest.php +++ /dev/null @@ -1,148 +0,0 @@ -<<<<<<< HEAD (55fc9f Revert "Revert "Check payments_init for 'failed' in pending ) -======= -<?php - -namespace SmashPig\Tests; - -use SmashPig\Core\Context; -use SmashPig\Core\DataStores\PaymentsInitialDatabase; -use SmashPig\Core\DataStores\PendingDatabase; -use SmashPig\Core\QueueConsumers\PendingQueueConsumer; - -class PendingQueueConsumerTest extends BaseSmashPigUnitTestCase { - - /** - * @var PendingDatabase - */ - protected $pendingDb; - - /** - * @var PaymentsInitialDatabase - */ - protected $paymentsInitialDb; - - public function setUp() { - parent::setUp(); - // Merge db and queue test configs. - $config = TestingConfiguration::loadConfigWithFileOverrides( array( - __DIR__ . '/data/config_smashpig_db.yaml', - __DIR__ . '/data/config_queue.yaml', - ) ); - Context::initWithLogger( $config ); - - $this->pendingDb = PendingDatabase::get(); - $this->pendingDb->createTable(); - $this->paymentsInitialDb = PaymentsInitialDatabase::get(); - $this->paymentsInitialDb->createTable(); - } - - public function tearDown() { - // FIXME: huh. I guess we should use class names to avoid possible - // incomplete destruction in the case that paymentsInitialDb was never - // initialized. - TestingDatabase::clearStatics( $this->paymentsInitialDb ); - TestingDatabase::clearStatics( $this->pendingDb ); - - parent::tearDown(); - } - - /** - * We consume a message normally if there's nothing in the payments_initial - * table. - */ - public function testPendingMessageNotInInitial() { - $consumer = new PendingQueueConsumer( 'pending', 1000, 1000 ); - $message = self::generateRandomPendingMessage(); - - $consumer->processMessage( $message ); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - $message['gateway'], $message['order_id'] ); - - $this->assertNotNull( $fetched, - 'Message was consumed and stored in the pending database.' ); - - unset( $fetched['pending_id'] ); - $this->assertEquals( $message, $fetched, - 'Stored message is equal to the consumed message.' ); - } - - /** - * We consume a message normally if the corresponding payments_initial row - * is still pending. - */ - public function testPendingMessageInitialPending() { - $initRow = PaymentsInitialDatabaseTest::generateTestMessage(); - $initRow['payments_final_status'] = 'pending'; - - $this->paymentsInitialDb->storeMessage( $initRow ); - - $message = self::generatePendingMessageFromInitial( $initRow ); - $consumer = new PendingQueueConsumer( 'pending', 1000, 1000 ); - - $consumer->processMessage( $message ); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - $message['gateway'], $message['order_id'] ); - - $this->assertNotNull( $fetched, - 'Message was consumed and stored in the pending database.' ); - - unset( $fetched['pending_id'] ); - $this->assertEquals( $message, $fetched, - 'Stored message is equal to the consumed message.' ); - } - - /** - * We refuse to consume a message and drop it if the corresponding - * payments_initial row is failed. - */ - public function testPendingMessageInitialFailed() { - $initRow = PaymentsInitialDatabaseTest::generateTestMessage(); - $initRow['payments_final_status'] = 'failed'; - $initRow['validation_action'] = 'reject'; - - $this->paymentsInitialDb->storeMessage( $initRow ); - - $message = self::generatePendingMessageFromInitial( $initRow ); - $consumer = new PendingQueueConsumer( 'pending', 1000, 1000 ); - - $consumer->processMessage( $message ); - - $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( - $message['gateway'], $message['order_id'] ); - - $this->assertNull( $fetched, - 'Message consumed and not stored in the pending database.' ); - } - - public static function generateRandomPendingMessage() { - $message = array( - 'gateway' => 'test', - 'date' => time(), - 'order_id' => mt_rand(), - 'cousin' => 'itt', - 'kookiness' => mt_rand(), - ); - return $message; - } - - /** - * Create an incoming pending message corresponding to a given - * payments_initial row. - * - * @param array $initialRow - * @return array Message suitable for the pending queue. - */ - public static function generatePendingMessageFromInitial( $initialRow ) { - $message = array( - 'gateway' => $initialRow['gateway'], - 'date' => $initialRow['date'], - 'order_id' => $initialRow['order_id'], - 'cousin' => 'itt', - 'kookiness' => mt_rand(), - ); - return $message; - } -} ->>>>>>> BRANCH (2caa19 Fix all db subclasses sharing a PDO) diff --git a/Tests/TestingDatabase.php b/Tests/TestingDatabase.php deleted file mode 100644 index 2726efd..0000000 --- a/Tests/TestingDatabase.php +++ /dev/null @@ -1,20 +0,0 @@ -<<<<<<< HEAD (55fc9f Revert "Revert "Check payments_init for 'failed' in pending ) -======= -<?php - -namespace SmashPig\Tests; - -class TestingDatabase { - /** - * @param string|object $classish Database class to reset, as a qualified - * class name or example object. Must be a subtype of SmashPigDatabase for - * the statics to make sense. - */ - public static function clearStatics( $classish ) { - $klass = new \ReflectionClass( $classish ); - $dbProperty = $klass->getProperty( 'dbs' ); - $dbProperty->setAccessible( true ); - $dbProperty->setValue( array() ); - } -} ->>>>>>> BRANCH (2caa19 Fix all db subclasses sharing a PDO) -- To view, visit https://gerrit.wikimedia.org/r/317561 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ice426b3e460db2e1143cb3c3257d4cba31c93c6c Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: deployment Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits