From: Dylan William Hardison Date: Thu, 4 Apr 2019 15:25:44 +0000 (-0400) Subject: Bug 1540857 - Change simple ping document id X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e470122fabf5954e2c08fdec5c0b6f0c4bd00ea7;p=thirdparty%2Fbugzilla.git Bug 1540857 - Change simple ping document id --- diff --git a/.circleci/config.yml b/.circleci/config.yml index 41b13594e..9ef319400 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ version: 2 defaults: bmo_slim_image: &bmo_slim_image - image: mozillabteam/bmo-slim:20190322.1 + image: mozillabteam/bmo-slim:20190404.1 user: app mysql_image: &mysql_image diff --git a/Bugzilla/Model/Result/Bug.pm b/Bugzilla/Model/Result/Bug.pm index 4ec5b71ec..42938bd54 100644 --- a/Bugzilla/Model/Result/Bug.pm +++ b/Bugzilla/Model/Result/Bug.pm @@ -8,15 +8,16 @@ package Bugzilla::Model::Result::Bug; use Mojo::Base 'DBIx::Class::Core'; -__PACKAGE__->load_components('Helper::Row::NumifyGet'); +__PACKAGE__->load_components(qw( Helper::Row::NumifyGet InflateColumn::DateTime )); __PACKAGE__->table(Bugzilla::Bug->DB_TABLE); __PACKAGE__->add_columns(Bugzilla::Bug->DB_COLUMN_NAMES); __PACKAGE__->add_columns( - '+bug_id' => {is_numeric => 1}, - '+reporter' => {is_numeric => 1}, - '+qa_contact' => {is_numeric => 1}, + '+bug_id' => {is_numeric => 1}, + '+reporter' => {is_numeric => 1}, + '+qa_contact' => {is_numeric => 1}, '+assigned_to' => {is_numeric => 1}, + '+delta_ts' => {data_type => 'timestamp'}, ); __PACKAGE__->set_primary_key(Bugzilla::Bug->ID_FIELD); diff --git a/Bugzilla/Report/Ping/Simple.pm b/Bugzilla/Report/Ping/Simple.pm index e3363872e..94f0de67a 100644 --- a/Bugzilla/Report/Ping/Simple.pm +++ b/Bugzilla/Report/Ping/Simple.pm @@ -86,7 +86,13 @@ sub prepare { flags => [map { $self->_prepare_flag($_) } $bug->flags->all], }; - return ($bug->id, $doc); + return ($self->_prepare_doc_id($bug), $doc); +} + +sub _prepare_doc_id { + my ($self, $bug) = @_; + + return sprintf("%d-%d", $bug->id, $bug->delta_ts->epoch); } sub _prepare_flag { diff --git a/Dockerfile b/Dockerfile index dd37244cc..935bba7e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mozillabteam/bmo-slim:20190322.1 +FROM mozillabteam/bmo-slim:20190404.1 ARG CI ARG CIRCLE_SHA1 diff --git a/Makefile.PL b/Makefile.PL index fc586951e..12621b364 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -100,19 +100,6 @@ my %requires = ( ); my %build_requires = ('ExtUtils::MakeMaker' => '7.22',); -my %test_requires = ( - 'Capture::Tiny' => 0, - 'DBD::SQLite' => '1.29', - 'Perl::Critic::Freenode' => 0, - 'Perl::Tidy' => '20180220', - 'Pod::Coverage' => 0, - 'Test::More' => 0, - 'Test::Perl::Critic::Progressive' => 0, - 'Test::Selenium::Firefox' => 0, - 'Selenium::Remote::Driver' => 1.31, - 'Test::WWW::Selenium' => 0, - 'Test2::V0' => 0, -); my %recommends = (Safe => '2.30',); # Windows requires some additional modules. @@ -248,11 +235,11 @@ my %optional_features = ( }, sqlite => { description => 'SQLite database support', - prereqs => {runtime => {requires => {'DBD::SQLite' => '1.29'}}}, + prereqs => {runtime => {requires => {'DBD::SQLite' => '1.29', 'DateTime::Format::SQLite' => '0.11'}}}, }, mysql => { description => 'MySQL database support', - prereqs => {runtime => {requires => {'DBD::mysql' => '4.037'}}} + prereqs => {runtime => {requires => {'DBD::mysql' => '4.037', 'DateTime::Format::MySQL' => '0.06'}}} }, jsonrpc => { description => 'JSON-RPC Interface', @@ -371,6 +358,21 @@ for my $file (glob 'extensions/*/Config.pm') { } } +my %test_requires = ( + %{ $optional_features{sqlite}{prereqs}{runtime}{requires} }, + 'Capture::Tiny' => 0, + 'DBD::SQLite' => '1.29', + 'Perl::Critic::Freenode' => 0, + 'Perl::Tidy' => '20180220', + 'Pod::Coverage' => 0, + 'Test::More' => 0, + 'Test::Perl::Critic::Progressive' => 0, + 'Test::Selenium::Firefox' => 0, + 'Selenium::Remote::Driver' => 1.31, + 'Test::WWW::Selenium' => 0, + 'Test2::V0' => 0, +); + # BMO Customization my @bmo_features = grep { is_bmo_feature($_) } keys %optional_features; diff --git a/t/report-ping-simple.t b/t/report-ping-simple.t index f1f532b4a..f2cf56dec 100644 --- a/t/report-ping-simple.t +++ b/t/report-ping-simple.t @@ -12,12 +12,16 @@ use lib qw( . lib local/lib/perl5 ); BEGIN { unlink('data/db/report_ping_simple') if -f 'data/db/report_ping_simple'; $ENV{test_db_name} = 'report_ping_simple'; + # Our code will store dates in localtime with sqlite. + # So for these tests to pass, everything should be UTC. + $ENV{TZ} = 'UTC'; } use Bugzilla::Test::MockDB; use Bugzilla::Test::MockParams (password_complexity => 'no_constraints'); use Bugzilla::Test::Util qw(create_bug create_user); use Bugzilla; +use Bugzilla::Util qw(datetime_from); use Bugzilla::Constants; use Bugzilla::Hook; BEGIN { Bugzilla->extensions } @@ -30,14 +34,27 @@ use ok 'Bugzilla::Report::Ping::Simple'; Bugzilla->dbh->model->resultset('Keyword') ->create({name => 'regression', description => 'the regression keyword'}); +# Our code will store dates in localtime with sqlite. +# So for these tests to pass, everything should be UTC. +my $UTC = DateTime::TimeZone->new(name => 'UTC'); +Bugzilla->local_timezone($UTC); +my $User = mock 'Bugzilla::User' => ( + override => [ timezone => sub { $UTC } ] +); + my $user = create_user('reportuser@invalid.tld', '*'); Bugzilla->set_user($user); -create_bug( - short_desc => "test bug $_", - comment => "Hello, world: $_", - provided $_ % 3 == 0, keywords => ['regression'], - assigned_to => 'reportuser@invalid.tld' -) for (1..250); + +my %time; +for (1..250) { + my $bug = create_bug( + short_desc => "test bug $_", + comment => "Hello, world: $_", + provided $_ % 3 == 0, keywords => ['regression'], + assigned_to => 'reportuser@invalid.tld' + ); + $time{ $bug->id } = datetime_from($bug->delta_ts)->epoch; +} my $report = Bugzilla::Report::Ping::Simple->new( base_url => 'http://localhost', @@ -54,7 +71,8 @@ is($rs->first->id, 1, "first bug of page 1 is 1"); my ($first, $second, $third, @rest) = $rs->all; { my ($id, $doc) = $report->prepare( $first ); - is($id, 1, "doc id is 1"); + + is($id, "1-$time{1}", "doc id is correct"); is($doc->{product}, 'Firefox'); is($doc->{keywords}, []); is([map { "$_" } $report->validate($doc)], [], "No errors for first doc"); @@ -62,7 +80,7 @@ my ($first, $second, $third, @rest) = $rs->all; { my ($id, $doc) = $report->prepare( $third ); - is($id, 3, "doc id is 3"); + is($id, "3-$time{3}", "doc id is correct"); is($doc->{product}, 'Firefox'); is($doc->{keywords}, ['regression']); }