Skip to content

Commit

Permalink
Merge branch 'os-autoinst:master' into refactor_use_openqa_git
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson authored Aug 14, 2024
2 parents c81d797 + f0932be commit bf6079b
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 56 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/perl-critic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: 'Perl critic'

on: [push, pull_request]

jobs:
perl-critic-checks:
runs-on: ubuntu-latest
name: "Perlcritic"
container:
image: perldocker/perl-tester
steps:
- uses: actions/checkout@v4
- run: make test-critic
9 changes: 0 additions & 9 deletions .perlcriticrc

This file was deleted.

1 change: 1 addition & 0 deletions .perlcriticrc
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ endif

.PHONY: test-critic
test-critic:
PERL5LIB=lib/perlcritic:$$PERL5LIB perlcritic lib
tools/perlcritic lib

.PHONY: test-tidy-compile
test-tidy-compile:
Expand Down
13 changes: 13 additions & 0 deletions external/os-autoinst-common/.github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: 'Unit Tests'

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
container:
image: perldocker/perl-tester
steps:
- uses: actions/checkout@v4
- run: make test-t
2 changes: 1 addition & 1 deletion external/os-autoinst-common/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = [email protected]:os-autoinst/os-autoinst-common.git
branch = master
commit = 9a505a76f9835862211cdf59e07e2a3865320f49
commit = 26141c03953330b0d7219391eeeea9142ee00208
parent = 549ee3ba37e2e65335466e39899ac4321028a01a
method = merge
cmdver = 0.4.6
4 changes: 2 additions & 2 deletions external/os-autoinst-common/.perlcriticrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ severity = 1

# == Custom Policies
# -- Useless quotes on hashes
[HashKeyQuotes]
[OpenQA::HashKeyQuotes]
severity = 5

# -- Superfluous use strict/warning.
[RedundantStrictWarning]
[OpenQA::RedundantStrictWarning]
equivalent_modules = Test::Most
6 changes: 5 additions & 1 deletion external/os-autoinst-common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ update-deps:
tools/update-deps --cpanfile cpanfile

.PHONY: test
test: test-tidy test-critic test-yaml test-author
test: test-tidy test-critic test-yaml test-author test-t

.PHONY: test-tidy
test-tidy:
Expand All @@ -25,3 +25,7 @@ test-yaml:
.PHONY: test-author
test-author:
prove -l -r xt/

.PHONY: test-t
test-t:
prove -l -r t/
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package Perl::Critic::Policy::ArgumentInUseStrictWarnings;
package Perl::Critic::Policy::OpenQA::ArgumentInUseStrictWarnings;

use strict;
use warnings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package Perl::Critic::Policy::HashKeyQuotes;
package Perl::Critic::Policy::OpenQA::HashKeyQuotes;

use strict;
use warnings;
Expand All @@ -22,8 +22,12 @@ sub applies_to { return qw(PPI::Token::Quote::Single PPI::Token::Quote::Double)
sub violates ($self, $elem, $document) {
# skip anything that's not a hash key
return () unless is_hash_key($elem);
# skip if it has a sibling, e.g. $h{'foo' . 'bar'}
return () if $elem->snext_sibling or $elem->sprevious_sibling;

# only some PPI::Token::Quote::* classes implement literal
my $k = $elem->can('literal') ? $elem->literal : $elem->string;

my $k = $elem->literal;
# skip anything that has a special symbol in the content
return () unless $k =~ m/^\w+$/;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package Perl::Critic::Policy::RedundantStrictWarning;
package Perl::Critic::Policy::OpenQA::RedundantStrictWarning;

use strict;
use warnings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package Perl::Critic::Policy::SpaceAfterSubroutineName;
package Perl::Critic::Policy::OpenQA::SpaceAfterSubroutineName;

use strict;
use warnings;
Expand Down Expand Up @@ -68,6 +68,8 @@ sub check_complete_sub ($self, $elem, @tokens) {
# 5. Whitespace - must be 1
# 6. Structure - the actual code block

my $nsib = $elem->snext_sibling;
my $psib = $elem->sprevious_sibling;
return () if _is_surrounded_by_one_space($tokens[2]) && _is_surrounded_by_one_space($tokens[4]);
return $self->report_violation($elem);
}
Expand All @@ -77,7 +79,8 @@ sub _is_block ($token) {
}

sub _is_only_one_space ($token) {
return $token->isa('PPI::Token::Whitespace') && $token->content eq ' ';
# We also allow line breaks, e.g. perltidy forces to break up long subroutine headers
return $token->isa('PPI::Token::Whitespace') && $token->content =~ m/^[ \n]$/;
}

sub _is_surrounded_by_one_space ($token) {
Expand Down
11 changes: 11 additions & 0 deletions external/os-autoinst-common/t/10-perlcritic.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/perl
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

use strict;
use warnings;
use FindBin '$Bin';
use lib "$Bin/../lib/perlcritic";
use Test::Perl::Critic::Policy qw/ all_policies_ok /;

all_policies_ok();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## name Passing
## failures 0
## cut

use strict;
use warnings;

## name Failing
## failures 1
## cut

use warnings 'redefined';
19 changes: 19 additions & 0 deletions external/os-autoinst-common/t/OpenQA/HashKeyQuotes.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
my %h;
## name Passing
## failures 0
## cut

$h{bare} = 1;
$h{"line\nbreak"} = 2;
$h{'special!'} = 3;
$h{'concatenate_' . 'strings'} = 4;
$h{bare2 } = 5;

## name Failing
## failures 4
## cut

$h{'single'} = 1;
$h{ 'single' } = 2;
$h{"double"} = 3;
$h{"double2" } = 4;
16 changes: 16 additions & 0 deletions external/os-autoinst-common/t/OpenQA/RedundantStrictWarning.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## name Passing
## failures 0
## cut

use Mojo::Base 'DBIx::Class::Core';

## name Passing
## failures 0
## TODO It can be neessary to use two modules that both enable strict
## cut

use Mojo::Base 'DBIx::Class::Core';

use Moose;
extends 'OpenQA::Schema::Result::Jobs';

31 changes: 31 additions & 0 deletions external/os-autoinst-common/t/OpenQA/SpaceAfterSubroutineName.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## name Passing
## failures 0
## cut

sub long ($self, $jobid, $job_labels, $aggregated, $failed_modules, $actually_failed_modules,
$todo = undef)
{
}

sub long2
($x, $y) {
}

sub a ($x) {
}

## name Failing
## failures 4
## cut

sub foo($x) {
}

sub foo ($x){
}

sub foo ($x) {
}

sub foo ($x) {
}
6 changes: 5 additions & 1 deletion external/os-autoinst-common/tools/perlcritic
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# perlcritic with auto-injection of custom perlcritic rules.
use strict;
use warnings;
use v5.10;
use experimental 'signatures';
use FindBin '$Bin';

Expand All @@ -16,5 +17,8 @@ sub extra_include_paths (@extra_paths) {
}

$ENV{PERL5LIB} = join(':', (extra_include_paths('lib/perlcritic'), $ENV{PERL5LIB} // ''));

unless (@ARGV) {
say "Usage: $0 files-or-directories";
exit;
}
exec 'perlcritic', @ARGV;
2 changes: 1 addition & 1 deletion lib/OpenQA/Schema/Result/JobNextPrevious.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package OpenQA::Schema::Result::JobNextPrevious;


## no critic (OpenQA::RedundantStrictWarning)
use Mojo::Base 'DBIx::Class::Core';

use Moose;
Expand Down
1 change: 1 addition & 0 deletions lib/OpenQA/Schema/Result/Needles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package OpenQA::Schema::Result::Needles;

## no critic (OpenQA::RedundantStrictWarning)
use 5.018;

use Mojo::Base 'DBIx::Class::Core', -signatures;
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenQA/Schema/Result/ScheduledProducts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package OpenQA::Schema::Result::ScheduledProducts;


## no critic (OpenQA::RedundantStrictWarning)
use Mojo::Base 'DBIx::Class::Core', -signatures;

use Mojo::Base -base, -signatures;
Expand Down
1 change: 1 addition & 0 deletions lib/OpenQA/WebAPI/Controller/Admin/AuditLog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


package OpenQA::WebAPI::Controller::Admin::AuditLog;
## no critic (OpenQA::RedundantStrictWarning)
use Mojo::Base 'Mojolicious::Controller';

use 5.018;
Expand Down
32 changes: 0 additions & 32 deletions lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm

This file was deleted.

6 changes: 6 additions & 0 deletions t/05-scheduler-full.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ plan skip_all => "set FULLSTACK=1 (be careful)" unless $ENV{FULLSTACK};
setup_mojo_app_with_default_worker_timeout;
OpenQA::Setup::read_config(OpenQA::App->singleton);

# fake "/proc/loadavg" to ensure the test works under a heavy load
my $load_avg_file = tempfile('worker-overall-load-avg-XXXXX');
my $load_avg_file_realpath = $load_avg_file->realpath;
$load_avg_file->spew('0.93 0.95 3.25 2/2207 1212');
$ENV{OPENQA_LOAD_AVG_FILE} = $load_avg_file_realpath;

# setup directories and database
my $tempdir = setup_fullstack_temp_dir('scheduler');
my $schema = OpenQA::Test::Database->new->create(fixtures_glob => '01-jobs.pl 02-workers.pl');
Expand Down
8 changes: 7 additions & 1 deletion t/43-scheduling-and-worker-scalability.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Test::MockModule;
use Time::HiRes 'sleep';
use File::Path 'make_path';
use Scalar::Util 'looks_like_number';
use Mojo::File 'path';
use Mojo::File qw(path tempfile);
use Mojo::Util 'dumper';
use IPC::Run qw(start);
use FindBin;
Expand Down Expand Up @@ -41,6 +41,12 @@ BEGIN {
setup_mojo_app_with_default_worker_timeout;
OpenQA::Setup::read_config(OpenQA::App->singleton);

# fake "/proc/loadavg" to ensure the test works under a heavy load
my $load_avg_file = tempfile('worker-overall-load-avg-XXXXX');
my $load_avg_file_realpath = $load_avg_file->realpath;
$load_avg_file->spew('0.93 0.95 3.25 2/2207 1212');
$ENV{OPENQA_LOAD_AVG_FILE} = $load_avg_file_realpath;

# read number of workers to spawn from environment variable; skip test entirely if variable not present
# similar to other fullstack tests
my $worker_count = $ENV{SCALABILITY_TEST_WORKER_COUNT};
Expand Down
1 change: 1 addition & 0 deletions tools/perlcritic

0 comments on commit bf6079b

Please sign in to comment.