Skip to content

Commit

Permalink
Merge pull request #3416 from okurz/enhance/speedup_tests
Browse files Browse the repository at this point in the history
Enhance/speedup tests
  • Loading branch information
mergify[bot] committed Mar 8, 2021
2 parents c0f9ffe + 0f3ae6d commit 0b1531c
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion t/03-auth.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sub test_auth_method_startup {
$t->get_ok('/login');
}

OpenQA::Test::Database->new->create(skip_fixtures => 1);
OpenQA::Test::Database->new->create;

combined_like { test_auth_method_startup('Fake')->status_is(302) } qr/302 Found/, 'Plugin loaded';

Expand Down
2 changes: 1 addition & 1 deletion t/04-scheduler.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $mock_result->redefine(
return {state => {msg_sent => 1}};
});

my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1);
my $schema = OpenQA::Test::Database->new->create;
my $jobs = $schema->resultset('Jobs');
my $t = Test::Mojo->new('OpenQA::Scheduler');

Expand Down
2 changes: 1 addition & 1 deletion t/05-scheduler-capabilities.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use OpenQA::Test::TimeLimit '10';

setup_mojo_app_with_default_worker_timeout;

my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1);
my $schema = OpenQA::Test::Database->new->create;
my $sent = {};

OpenQA::Scheduler::Model::Jobs->singleton->shuffle_workers(0);
Expand Down
4 changes: 2 additions & 2 deletions t/05-scheduler-full.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env perl

# Copyright (C) 2014-2020 SUSE LLC
# Copyright (C) 2014-2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -56,7 +56,7 @@ setup_mojo_app_with_default_worker_timeout;

# setup directories and database
my $tempdir = setup_fullstack_temp_dir('scheduler');
my $schema = OpenQA::Test::Database->new->create;
my $schema = OpenQA::Test::Database->new->create(fixtures_glob => '01-jobs.pl 02-workers.pl');
my $api_credentials = create_user_for_workers;
my $api_key = $api_credentials->key;
my $api_secret = $api_credentials->secret;
Expand Down
2 changes: 1 addition & 1 deletion t/06-users.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use OpenQA::Test::TimeLimit '10';
use Test::Mojo;
use Test::Warnings ':report_warnings';

OpenQA::Test::Database->new->create(skip_fixtures => 1);
OpenQA::Test::Database->new->create;
my $t = Test::Mojo->new('OpenQA::WebAPI');

subtest 'new users are not ops and admins' => sub {
Expand Down
2 changes: 1 addition & 1 deletion t/12-profiler.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ENV{MOJO_LOG_LEVEL} = 'debug';
$ENV{OPENQA_SQL_DEBUG} = 'true';
$ENV{OPENQA_LOGFILE} = $filename;

OpenQA::Test::Case->new->init_data(skip_fixtures => 1);
OpenQA::Test::Case->new->init_data;

my $t = Test::Mojo->new('OpenQA::WebAPI');

Expand Down
2 changes: 1 addition & 1 deletion t/15-assets.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $mock->redefine(
});

my $schema;
ok($schema = OpenQA::Test::Database->new->create(skip_fixtures => 1), 'create database')
ok($schema = OpenQA::Test::Database->new->create, 'create database')
|| BAIL_OUT('failed to create database');

my $t = Test::Mojo->new('OpenQA::WebAPI');
Expand Down
2 changes: 1 addition & 1 deletion t/21-needles.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ my %settings = (
ARCH => 'x86_64',
);

my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1);
my $schema = OpenQA::Test::Database->new->create;
my $needledir_archlinux = "t/data/openqa/share/tests/archlinux/needles";
my $needledir_fedora = "t/data/openqa/share/tests/fedora/needles";
# create dummy job
Expand Down
2 changes: 1 addition & 1 deletion t/25-bugs.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use OpenQA::Test::TimeLimit '10';
use Test::Mojo;
use Test::Warnings ':report_warnings';

my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1);
my $schema = OpenQA::Test::Database->new->create;
my $t = Test::Mojo->new('OpenQA::WebAPI');
my $bugs = $schema->resultset('Bugs');
my $app = $t->app;
Expand Down
2 changes: 1 addition & 1 deletion t/33-developer_mode.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ my $resultdir = path($ENV{OPENQA_BASEDIR}, 'openqa', 'testresults')->make_path;
ok(-d $resultdir, "resultdir \"$resultdir\" exists");

# setup database without fixtures and special admin users 'Demo' and 'otherdeveloper'
my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1, schema_name => 'public', drop_schema => 1);
my $schema = OpenQA::Test::Database->new->create(schema_name => 'public', drop_schema => 1);
my $users = $schema->resultset('Users');
$users->create(
{
Expand Down
4 changes: 1 addition & 3 deletions t/36-job_group_defaults.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use OpenQA::Test::TimeLimit '6';
use OpenQA::Test::Case;
use OpenQA::JobGroupDefaults;

# init test case
my $test_case = OpenQA::Test::Case->new;
$test_case->init_data(skip_fixtures => 1);
OpenQA::Test::Case->new->init_data;
my $t = Test::Mojo->new('OpenQA::WebAPI');

# get resultsets
Expand Down
4 changes: 1 addition & 3 deletions t/39-scheduled_products-table.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use OpenQA::Test::TimeLimit '6';
use OpenQA::Test::Case;
use OpenQA::Utils;

# init test case
my $test_case = OpenQA::Test::Case->new;
$test_case->init_data(skip_fixtures => 1);
OpenQA::Test::Case->new->init_data;
my $t = Test::Mojo->new('OpenQA::WebAPI');

my $schema = $t->app->schema;
Expand Down
2 changes: 1 addition & 1 deletion t/41-audit-log.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use OpenQA::Test::TimeLimit '10';

# init test case
my $test_case = OpenQA::Test::Case->new(config_directory => "$FindBin::Bin/data/41-audit-log");
my $schema = $test_case->init_data(skip_fixtures => 1);
my $schema = $test_case->init_data;
my $t = Test::Mojo->new('OpenQA::WebAPI');

# get resultsets
Expand Down
2 changes: 1 addition & 1 deletion t/43-scheduling-and-worker-scalability.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mock_service_ports;

# setup basedir, config dir and database
my $tempdir = setup_fullstack_temp_dir('scalability');
my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1);
my $schema = OpenQA::Test::Database->new->create;
my $workers = $schema->resultset('Workers');
my $jobs = $schema->resultset('Jobs');

Expand Down
2 changes: 1 addition & 1 deletion t/api/15-search.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common
use OpenQA::Test::TimeLimit '8';
use OpenQA::Test::Case;

OpenQA::Test::Case->new->init_data(skip_fixtures => 1);
OpenQA::Test::Case->new->init_data;
my $t = Test::Mojo->new('OpenQA::WebAPI');
$t->app->config->{rate_limits}->{search} = 10;

Expand Down
2 changes: 1 addition & 1 deletion t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib";
use OpenQA::Test::Database;
use OpenQA::Test::TimeLimit '8';

OpenQA::Test::Database->new->create(skip_fixtures => 1);
OpenQA::Test::Database->new->create;
Test::Mojo->new('OpenQA::WebAPI')->get_ok('/')->status_is(200)->content_like(qr/Welcome to openQA/i);

done_testing;
2 changes: 1 addition & 1 deletion t/full-stack.t
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ my $tempdir = setup_fullstack_temp_dir('full-stack.d');
my $sharedir = setup_share_dir($ENV{OPENQA_BASEDIR});

# initialize database, start daemons
my $schema = OpenQA::Test::Database->new->create(skip_fixtures => 1, schema_name => 'public', drop_schema => 1);
my $schema = OpenQA::Test::Database->new->create(schema_name => 'public', drop_schema => 1);
ok(Mojolicious::Commands->start_app('OpenQA::WebAPI', 'eval', '1+0'), 'assets are prefetched');
mock_service_ports;
my $mojoport = service_port 'websocket';
Expand Down
7 changes: 3 additions & 4 deletions t/lib/OpenQA/Test/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ sub create {
}

$schema->deploy;
$self->insert_fixtures($schema, $options{fixtures_glob}) unless $options{skip_fixtures};

$self->insert_fixtures($schema, $options{fixtures_glob}) if $options{fixtures_glob};
return $schema;
}

Expand Down Expand Up @@ -136,14 +135,14 @@ Deploy schema & load fixtures
# Creates an test database from DBIC OpenQA::Schema with or without fixtures
my $schema = Test::Database->new->create;
my $schema = Test::Database->new->create(skip_fixtures => 1);
my $schema = Test::Database->new->create(fixtures_glob => '01-jobs.pl 02-foo.pl');
=head1 METHODS
=head2 create (%args)
Create new database from DBIC schema.
Use skip_fixtures to prevent loading fixtures.
Use fixtures_glob to select fixtures to load from files.
=head2 insert_fixtures
Expand Down
5 changes: 3 additions & 2 deletions t/ui/01-list.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common
use Date::Format 'time2str';
use Test::Mojo;
use Test::Warnings ':report_warnings';
use OpenQA::Test::TimeLimit '20';
use OpenQA::Test::TimeLimit '40';
use OpenQA::Test::Case;
use OpenQA::Test::Database;

my $test_case = OpenQA::Test::Case->new;
my $schema_name = OpenQA::Test::Database->generate_schema_name;
my $schema = $test_case->init_data(schema_name => $schema_name);
my $fixtures = '01-jobs.pl 03-users.pl 04-products.pl 05-job_modules.pl 06-job_dependencies.pl';
my $schema = $test_case->init_data(schema_name => $schema_name, fixtures_glob => $fixtures);

use OpenQA::SeleniumTest;

Expand Down
5 changes: 2 additions & 3 deletions t/ui/07-file.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2014-2020 SUSE LLC
# Copyright (C) 2014-2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -24,8 +24,7 @@ use Mojo::File 'path';
use OpenQA::Test::TimeLimit '8';
use OpenQA::Test::Case;

my $test_case = OpenQA::Test::Case->new;
$test_case->init_data(fixures_glob => '01-jobs.t');
OpenQA::Test::Case->new->init_data(fixtures_glob => '01-jobs.pl 05-job_modules.pl 07-needles.pl');

my $t = Test::Mojo->new('OpenQA::WebAPI');

Expand Down
2 changes: 1 addition & 1 deletion t/ui/15-search.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use OpenQA::Client;

use OpenQA::SeleniumTest;

OpenQA::Test::Case->new->init_data(skip_fixtures => 1);
OpenQA::Test::Case->new->init_data;

plan skip_all => $OpenQA::SeleniumTest::drivermissing unless my $driver = call_driver;

Expand Down
2 changes: 1 addition & 1 deletion t/ui/23-audit-log.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use OpenQA::Client;

use OpenQA::SeleniumTest;

OpenQA::Test::Case->new->init_data(skip_fixtures => 1);
OpenQA::Test::Case->new->init_data;
plan skip_all => $OpenQA::SeleniumTest::drivermissing unless my $driver = call_driver;

sub wait_for_data_table {
Expand Down
5 changes: 3 additions & 2 deletions t/ui/26-jobs_restart.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2018-2020 SUSE LLC
# Copyright (C) 2018-2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -27,7 +27,8 @@ use Date::Format 'time2str';

my $test_case = OpenQA::Test::Case->new;
my $schema_name = OpenQA::Test::Database->generate_schema_name;
my $schema = $test_case->init_data(schema_name => $schema_name);
my $fixtures = '01-jobs.pl 06-job_dependencies.pl';
my $schema = $test_case->init_data(schema_name => $schema_name, fixtures_glob => $fixtures);

sub prepare_database {
my $jobs = $schema->resultset('Jobs');
Expand Down
16 changes: 7 additions & 9 deletions t/ui/27-plugin_obs_rsync_status_details.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019-2020 SUSE LLC
# Copyright (C) 2019-2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -19,7 +19,7 @@ use FindBin;
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common/lib";
use Test::Warnings;
use Test::Mojo;
use OpenQA::Test::TimeLimit '50';
use OpenQA::Test::TimeLimit '60';
use OpenQA::Test::Database;
use OpenQA::Test::Case;
use OpenQA::Test::Utils 'wait_for_or_bail_out';
Expand All @@ -35,7 +35,8 @@ use Mojo::IOLoop::ReadWriteProcess 'process';
use Mojo::IOLoop::ReadWriteProcess::Session 'session';
use Time::HiRes 'sleep';

OpenQA::Test::Case->new->init_data();
my $fixtures = '01-jobs.pl 03-users.pl';
OpenQA::Test::Case->new->init_data(fixtures_glob => $fixtures);

$SIG{INT} = sub {
session->clean;
Expand Down Expand Up @@ -90,10 +91,9 @@ sub start_server {
wait_for_or_bail_out { _port($port) } 'worker';
}

sub stop_server {
# now kill the worker
$server_instance->stop();
}
sub stop_server { $server_instance->stop }

END { stop_server }

my $url = "http://127.0.0.1:$port/public/build/%%PROJECT/_result";

Expand Down Expand Up @@ -228,6 +228,4 @@ foreach my $proj (sort keys %params) {
}
}

stop_server();
kill_driver();
done_testing();

0 comments on commit 0b1531c

Please sign in to comment.