Skip to content

Commit e87aca6

Browse files
committed
rework set_first_release + add first script to tests
this change will prevent the race between setting all releases to first=0 and then setting first=1 based on a query that depends on previous put to finish on ES level. it adds a run of MetaCPAN::Script::First to the setup test, to ensure all releases are indexed correctly ('first'-wise) before running the other tests.
1 parent 8e55db0 commit e87aca6

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

lib/MetaCPAN/Document/Distribution.pm

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,19 @@ sub releases {
3737

3838
sub set_first_release {
3939
my $self = shift;
40-
$self->unset_first_release;
41-
my $release = $self->releases->sort( ["date"] )->first;
42-
return unless $release;
43-
return $release if $release->first;
44-
$release->_set_first(1);
45-
$release->put;
46-
return $release;
47-
}
4840

49-
sub unset_first_release {
50-
my $self = shift;
51-
my $releases
52-
= $self->releases->filter( { term => { first => 'true' }, } )
53-
->size(200)->scroll;
54-
while ( my $release = $releases->next ) {
55-
$release->_set_first(0);
56-
$release->update;
41+
my @releases = $self->releases->sort( ["date"] )->all;
42+
43+
my $first = shift @releases;
44+
$first->_set_first(1);
45+
$first->put;
46+
47+
for my $rel (@releases) {
48+
$rel->_set_first(0);
49+
$rel->put;
5750
}
58-
$self->index->refresh if $releases->total;
59-
return $releases->total;
51+
52+
return $first;
6053
}
6154

6255
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Script/Release.pm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ sub import_archive {
275275
# update 'first' value
276276
$document->set_first;
277277
$document->put;
278-
279-
sleep 2
280-
if defined $ENV{'METACPAN_SERVER_CONFIG_LOCAL_SUFFIX'}
281-
and $ENV{'METACPAN_SERVER_CONFIG_LOCAL_SUFFIX'} eq 'testing';
282278
}
283279

284280
sub _build_backpan_index {

t/00_setup.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ copy( $src_dir->file('bugs.tsv'), $fakecpan_dir->file('bugs.tsv') );
8181

8282
$server->index_releases;
8383
$server->set_latest;
84+
$server->set_first;
8485
$server->index_authors;
8586
$server->index_cpantesters;
8687

t/lib/MetaCPAN/TestServer.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use CPAN::Repository::Perms;
66
use MetaCPAN::Script::Author;
77
use MetaCPAN::Script::CPANTesters ();
88
use MetaCPAN::Script::Latest;
9+
use MetaCPAN::Script::First;
910
use MetaCPAN::Script::Mapping;
1011
use MetaCPAN::Script::Release;
1112
use MetaCPAN::Server ();
@@ -184,6 +185,13 @@ sub set_latest {
184185
'latest' );
185186
}
186187

188+
sub set_first {
189+
my $self = shift;
190+
local @ARGV = ('first');
191+
ok( MetaCPAN::Script::First->new_with_options( $self->_config )->run,
192+
'first' );
193+
}
194+
187195
sub index_authors {
188196
my $self = shift;
189197

0 commit comments

Comments
 (0)