jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399185 )

Change subject: Merge branch 'master' into deployment
......................................................................


Merge branch 'master' into deployment

91352b2 T183153: Removed Prometheus duplicate key output from DonationStats
f50237c Apply drupal formatting to AntifraudQueueConsumer.php
6fe8564 Extend risk score limiting to cover components of the score
aa0c142 Top out risk score at 100 million.
389ac7c Better requeue on db locks

Change-Id: Ie3b730f4b9fdc5c981f1ccc1eeb03d8c28d21473
---
M sites/all/modules/queue2civicrm/fredge/AntifraudQueueConsumer.php
D sites/all/modules/queue2civicrm/tests/phpunit/AntifraudQueueTest.php
D sites/all/modules/queue2civicrm/tests/phpunit/DonationStatsTest.php
3 files changed, 0 insertions(+), 372 deletions(-)

Approvals:
  jenkins-bot: Verified
  Ejegg: Looks good to me, approved



diff --git a/sites/all/modules/queue2civicrm/fredge/AntifraudQueueConsumer.php 
b/sites/all/modules/queue2civicrm/fredge/AntifraudQueueConsumer.php
index 8a7b88c..a0aa736 100644
--- a/sites/all/modules/queue2civicrm/fredge/AntifraudQueueConsumer.php
+++ b/sites/all/modules/queue2civicrm/fredge/AntifraudQueueConsumer.php
@@ -75,53 +75,6 @@
     $id = 0;
     $inserting = TRUE;
 
-<<<<<<< HEAD   (42a65d Revert "Reset deploy branch to match production")
-               $dbs = wmf_civicrm_get_dbs();
-               $dbs->push( 'fredge' );
-               $query = 'SELECT id FROM payments_fraud WHERE 
contribution_tracking_id = :ct_id AND order_id = :order_id LIMIT 1';
-               $result = db_query( $query, array(
-                       ':ct_id' => $msg['contribution_tracking_id'],
-                       ':order_id' => $msg['order_id']
-               ) );
-               if ( $result->rowCount() === 1 ) {
-                       $id = $result->fetch()->id;
-                       $inserting = false;
-               }
-               $data = fredge_prep_data( $msg, 'payments_fraud', 
$logIdentifier, $inserting );
-               //now all you have to do is insert the actual message data.
-               if ( $inserting ) {
-                       $id = db_insert( 'payments_fraud' )
-                               ->fields( $data )
-                               ->execute();
-               } else {
-                       db_update( 'payments_fraud' )
-                               ->fields( $data )
-                               ->condition( 'id', $id )
-                               ->execute();
-               }
-               if ( $id ) {
-                       foreach ( $msg['score_breakdown'] as $test => $score ) {
-                         if ($score > 100000000) {
-                           $score = 100000000;
-        }
-                               $breakdown = array(
-                                       'payments_fraud_id' => $id,
-                                       'filter_name' => $test,
-                                       'risk_score' => $score,
-                               );
-                               // validate the data. none of these fields 
would be converted, so no need
-                               // to store the output
-                               fredge_prep_data( $breakdown, 
'payments_fraud_breakdown', $logIdentifier, true );
-                               db_merge( 'payments_fraud_breakdown' )->key( 
array(
-                                       'payments_fraud_id' => $id,
-                                       'filter_name' => $test,
-                               ) )->fields( array(
-                                       'risk_score' => $score,
-                               ) )->execute();
-                       }
-               }
-       }
-=======
     $dbs = wmf_civicrm_get_dbs();
     $dbs->push('fredge');
     $query = 'SELECT id FROM payments_fraud WHERE contribution_tracking_id = 
:ct_id AND order_id = :order_id LIMIT 1';
@@ -168,5 +121,4 @@
       }
     }
   }
->>>>>>> BRANCH (91352b T183153: Removed Prometheus duplicate key output from 
Donati)
 }
diff --git 
a/sites/all/modules/queue2civicrm/tests/phpunit/AntifraudQueueTest.php 
b/sites/all/modules/queue2civicrm/tests/phpunit/AntifraudQueueTest.php
deleted file mode 100644
index 03284e1..0000000
--- a/sites/all/modules/queue2civicrm/tests/phpunit/AntifraudQueueTest.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<<<<<<< HEAD   (42a65d Revert "Reset deploy branch to match production")
-=======
-<?php
-use queue2civicrm\fredge\AntifraudQueueConsumer;
-
-/**
- * @group Queue2Civicrm
- */
-class AntifraudQueueTest extends BaseWmfDrupalPhpUnitTestCase {
-
-       /**
-        * @var AntifraudQueueConsumer
-        */
-       protected $consumer;
-
-       public function setUp() {
-               parent::setUp();
-               $this->consumer = new AntifraudQueueConsumer(
-                       'payments-antifraud'
-               );
-       }
-
-       public function testValidMessage() {
-               $message = json_decode(
-                       file_get_contents( __DIR__ . 
'/../data/payments-antifraud.json'),
-                       true
-               );
-               $ctId = mt_rand();
-               $oId = $ctId . '.0';
-               $message['contribution_tracking_id'] = $ctId;
-               $message['order_id'] = $oId;
-               $this->consumer->processMessage( $message );
-
-               $this->compareMessageWithDb( $message, 
$message['score_breakdown'] );
-       }
-
-  /**
-   * If the risk score is more than 100 million it should be set to 100 mil.
-   *
-   * This is effectively 'infinite risk' and our db can't cope with
-   * real value! '3.5848273556811E+38'
-   */
-  public function testFraudMessageWithOutOfRangeScore() {
-    $message = json_decode(
-      file_get_contents(__DIR__ . '/../data/payments-antifraud-high.json'),
-      TRUE
-    );
-    $ctId = mt_rand();
-    $oId = $ctId . '.0';
-    $message['contribution_tracking_id'] = $ctId;
-    $message['order_id'] = $oId;
-    $this->consumer->processMessage($message);
-
-    $message['risk_score'] = 100000000;
-
-    $this->compareMessageWithDb($message, $message['score_breakdown']);
-  }
-
-    /**
-        * The first message for a ct_id / order_id pair needs to be complete
-        *
-        * @expectedException FredgeDataValidationException
-        */
-       public function testIncompleteMessage() {
-               $message = json_decode(
-                       file_get_contents( __DIR__ . 
'/../data/payments-antifraud.json'),
-                       true
-               );
-               unset( $message['user_ip'] );
-               $this->consumer->processMessage( $message );
-       }
-
-       public function testCombinedMessage() {
-               $message1 = json_decode(
-                       file_get_contents( __DIR__ . 
'/../data/payments-antifraud.json'),
-                       true
-               );
-               $message2 = json_decode(
-                       file_get_contents( __DIR__ . 
'/../data/payments-antifraud.json'),
-                       true
-               );
-               $ctId = mt_rand();
-               $oId = $ctId . '.0';
-               $message1['contribution_tracking_id'] = $ctId;
-               $message2['contribution_tracking_id'] = $ctId;
-               $message1['order_id'] = $oId;
-               $message2['order_id'] = $oId;
-               $message1['score_breakdown'] = array_slice(
-                       $message1['score_breakdown'], 0, 4
-               );
-               $message2['score_breakdown'] = array_slice(
-                       $message2['score_breakdown'], 4, 4
-               );
-               $this->consumer->processMessage( $message1 );
-
-               $dbEntries = $this->getDbEntries( $ctId, $oId );
-               $this->assertEquals( 4, count( $dbEntries ) );
-
-               $this->consumer->processMessage( $message2 );
-
-               $breakdown = array_merge(
-                       $message1['score_breakdown'], 
$message2['score_breakdown']
-               );
-
-               $this->compareMessageWithDb( $message1, $breakdown );
-       }
-
-       protected function compareMessageWithDb( $common, $breakdown ) {
-               $dbEntries = $this->getDbEntries(
-                       $common['contribution_tracking_id'], $common['order_id']
-               );
-               $this->assertEquals( count($breakdown), count( $dbEntries ) );
-               $fields = array(
-                       'gateway',  'validation_action', 'payment_method',
-                       'risk_score', 'server'
-               );
-               foreach ( $fields as $field ) {
-                       $this->assertEquals( $common[$field], 
$dbEntries[0][$field] );
-               }
-               $this->assertEquals( ip2long( $common['user_ip'] ), 
$dbEntries[0]['user_ip'] );
-               $this->assertEquals(
-                       $common['date'], wmf_common_date_civicrm_to_unix( 
$dbEntries[0]['date'] )
-               );
-               foreach ( $dbEntries as $score ) {
-                       $name = $score['filter_name'];
-                       $expectedScore = $breakdown[$name] <= 100000000 ? 
$breakdown[$name] : 100000000;
-                       $this->assertEquals(
-        $expectedScore, $score['fb_risk_score'], "Mismatched $name score"
-                       );
-               }
-       }
-
-       protected function getDbEntries( $ctId, $orderId ) {
-               $query = Database::getConnection( 'default', 'fredge' )
-                       ->select( 'payments_fraud', 'f' );
-               $query->join(
-                       'payments_fraud_breakdown', 'fb', 'fb.payments_fraud_id 
= f.id'
-               );
-               return $query
-                       ->fields( 'f', array(
-                               'contribution_tracking_id', 'gateway', 
'order_id',
-                               'validation_action', 'user_ip', 
'payment_method',
-                               'risk_score', 'server', 'date'
-                       ) )
-                       ->fields( 'fb', array( 'filter_name', 'risk_score' ) )
-                       ->condition( 'contribution_tracking_id', $ctId )
-                       ->condition( 'order_id', $orderId )
-                       ->execute()
-                       ->fetchAll( PDO::FETCH_ASSOC );
-       }
-}
->>>>>>> BRANCH (91352b T183153: Removed Prometheus duplicate key output from 
Donati)
diff --git 
a/sites/all/modules/queue2civicrm/tests/phpunit/DonationStatsTest.php 
b/sites/all/modules/queue2civicrm/tests/phpunit/DonationStatsTest.php
deleted file mode 100644
index 156b1a4..0000000
--- a/sites/all/modules/queue2civicrm/tests/phpunit/DonationStatsTest.php
+++ /dev/null
@@ -1,172 +0,0 @@
-<<<<<<< HEAD   (42a65d Revert "Reset deploy branch to match production")
-=======
-<?php
-
-/**
- * The tests for the testOverallAverage*() methods are admittedly a little 
confusing due to the
- * DonationStats API not allowing access to individual stat values once 
recorded.
- *
- * However! fear not because even though testing averages to confirm 
individual records appears
- * counter-intuitive, we are only adding a single donation per test meaning 
the averages will be
- * identical be the individual values used per test because `avg(1) == 1`
- *
- * @group Queue2Civicrm
- * @group DonationStats
- */
-class DonationStatsTest extends BaseWmfDrupalPhpUnitTestCase {
-
-  protected $statsFilename;
-
-  protected $statsFilePath;
-
-  protected $statsFileExtension;
-
-  public function setUp() {
-    parent::setUp();
-    $this->setupStatsCollector();
-  }
-
-  public function testOverallAverageGatewayTransactionAgeRecorded() {
-    $message = [
-      'gateway' => "ACME_PAYMENTS",
-    ];
-    $contribution = [
-      //simulate a transaction date 1 hour earlier from now()
-      'receive_date' => \SmashPig\Core\UtcDate::getUtcDatabaseString('-1 
hour'),
-    ];
-
-    $DonationStats = new DonationStats();
-    $DonationStats->recordDonationStats($message, $contribution);
-    $OverallAverageGatewayTransactionAge = 
$DonationStats->getOverallAverageGatewayTransactionAge();
-
-    //compare recorded stats data with expected age in seconds (3600 seconds = 
1 hour)
-    $this->assertEquals(3600, $OverallAverageGatewayTransactionAge);
-  }
-
-  public function testOverallAverageMessageEnqueuedAgeRecordedWhenPresent() {
-    $message = [
-      'gateway' => "ACME_PAYMENTS",
-      // populating 'source_enqueued_time' with a timestamp one hour earlier 
from now()
-      'source_enqueued_time' => \SmashPig\Core\UtcDate::getUtcTimestamp('-1 
hour'),
-    ];
-    $contribution = [
-      'receive_date' => \SmashPig\Core\UtcDate::getUtcDatabaseString('-1 
hour'),
-    ];
-
-    $DonationStats = new DonationStats();
-    $DonationStats->recordDonationStats($message, $contribution);
-    $OverallAverageMessageEnqueuedAge = 
$DonationStats->getOverallAverageMessageEnqueuedAge();
-
-    //compare written stats data with expected age in seconds (3600 seconds = 
1 hour)
-    $this->assertEquals(3600, $OverallAverageMessageEnqueuedAge);
-  }
-
-  public function 
testOverallAverageMessageEnqueuedAgeNotRecordedWhenNotPresent() {
-    $message = [
-      'gateway' => "ACME_PAYMENTS",
-      // omitting 'source_enqueued_time'
-    ];
-    $contribution = [
-      'receive_date' => \SmashPig\Core\UtcDate::getUtcDatabaseString(),
-    ];
-
-    $DonationStats = new DonationStats();
-    $DonationStats->recordDonationStats($message, $contribution);
-    $OverallAverageMessageEnqueuedAge = 
$DonationStats->getOverallAverageMessageEnqueuedAge();
-
-    $this->assertNull($OverallAverageMessageEnqueuedAge);
-  }
-
-  public function testExportingStatsToFile() {
-    $this->setUpStatsOutFileProperties();
-    $message = [
-      'gateway' => "ACME_PAYMENTS",
-    ];
-    $contribution = [
-      'receive_date' => \SmashPig\Core\UtcDate::getUtcDatabaseString(),
-    ];
-
-    // test output file does not currently exist
-    $this->assertFileNotExists($this->statsFilePath . $this->statsFilename . 
$this->statsFileExtension);
-
-    $DonationStats = new DonationStats();
-    $DonationStats->recordDonationStats($message, $contribution);
-    $DonationStats->prometheusOutputFileName = $this->statsFilename;
-    $DonationStats->prometheusOutputFilePath = rtrim($this->statsFilePath, 
'/');
-    $DonationStats->export();
-
-    //test output file has been created
-    $this->assertFileExists($this->statsFilePath . $this->statsFilename . 
$this->statsFileExtension);
-
-    // clean up
-    $this->removeStatsOutFile();
-  }
-
-  public function testExportedStatsValues() {
-    $this->setUpStatsOutFileProperties();
-    $message = [
-      'gateway' => "ACME_PAYMENTS",
-    ];
-    $contribution = [
-      //simulate a transaction date 1 hour earlier from now()
-      'receive_date' => \SmashPig\Core\UtcDate::getUtcDatabaseString('-1 
hour'),
-    ];
-
-    $DonationStats = new DonationStats();
-    $DonationStats->recordDonationStats($message, $contribution);
-    $DonationStats->prometheusOutputFileName = $this->statsFilename;
-    $DonationStats->prometheusOutputFilePath = rtrim($this->statsFilePath, 
'/');
-    $DonationStats->export();
-
-    $expectedStats = [
-      'donations_gateway_ACME_PAYMENTS' => 1,
-      'donations_overall_donations' => 1,
-      'donations_overall_average_transaction_age' => 3600, // should be -1 
hour from now (3600 secs)
-      'donations_average_transaction_age_ACME_PAYMENTS' => 3600,
-    ];
-
-    $statsFileFullPath = $this->statsFilePath . $this->statsFilename . 
$this->statsFileExtension;
-    $statsWrittenAssocArray = [];
-    $statsWritten = rtrim(file_get_contents($statsFileFullPath)); // remove 
trailing \n
-    $statsWrittenLinesArray = explode("\n", $statsWritten);
-    foreach ($statsWrittenLinesArray as $statsLine) {
-      list($name, $value) = explode(' ', $statsLine);
-      $statsWrittenAssocArray[$name] = $value;
-    }
-
-    //compare written stats data with expected
-    $this->assertEquals($expectedStats, $statsWrittenAssocArray);
-
-    // clean up
-    $this->removeStatsOutFile();
-  }
-
-  public function tearDown() {
-    parent::tearDown();
-  }
-
-  private function setUpStatsOutFileProperties() {
-    $this->statsFilename = "test_stats";
-    $this->statsFilePath = CRM_Utils_File::tempdir();
-    $this->statsFileExtension = '.prom';
-  }
-
-  private function removeStatsOutFile() {
-    unlink($this->statsFilePath . $this->statsFilename . 
$this->statsFileExtension);
-    rmdir($this->statsFilePath);
-  }
-
-  /**
-   * Stats Collector singleton (used internally by DonationStats) needs 
resetting before each test.
-   *
-   * DonationQueueTest indirectly records stats when calling
-   * DonationQueueConsumer::processMessage() so we clear all instances before 
each run to test
-   * from a known starting point.
-   *
-   * @see DonationQueueTest
-   */
-  private function setupStatsCollector() {
-    \Statistics\Collector\Collector::tearDown(TRUE);
-  }
-}
->>>>>>> BRANCH (91352b T183153: Removed Prometheus duplicate key output from 
Donati)

-- 
To view, visit https://gerrit.wikimedia.org/r/399185
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3b730f4b9fdc5c981f1ccc1eeb03d8c28d21473
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Jgleeson <jglee...@wikimedia.org>
Gerrit-Reviewer: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to