Skip to content

Commit

Permalink
Move simulating load to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Aug 13, 2024
1 parent f0932be commit e5bed5f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
8 changes: 2 additions & 6 deletions t/05-scheduler-full.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use OpenQA::Test::Utils qw(
create_webapi setup_share_dir create_websocket_server
stop_service unstable_worker
unresponsive_worker broken_worker rejective_worker
wait_for
wait_for simulate_load
);
use OpenQA::Test::TimeLimit '150';

Expand All @@ -45,11 +45,7 @@ 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;
my $load_avg_file = simulate_load('0.93 0.95 3.25 2/2207 1212', '05-scheduler-full');

# setup directories and database
my $tempdir = setup_fullstack_temp_dir('scheduler');
Expand Down
7 changes: 2 additions & 5 deletions t/24-worker-overall.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use FindBin;
use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib";
use Mojo::Base -signatures;
use OpenQA::Test::TimeLimit '10';
use OpenQA::Test::Utils qw(simulate_load);
use Data::Dumper;
use Mojo::File qw(tempdir tempfile path);
use Mojo::Util 'scope_guard';
Expand All @@ -28,11 +29,7 @@ $ENV{OPENQA_CONFIG} = "$FindBin::Bin/data/24-worker-overall";
# file specified via OPENQA_LOGFILE instead of stdout/stderr.
$ENV{OPENQA_LOGFILE} = undef;

# fake "/proc/loadavg"
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 10.25 2/2207 1212');
$ENV{OPENQA_LOAD_AVG_FILE} = $load_avg_file_realpath;
my $load_avg_file = simulate_load('0.93 0.95 10.25 2/2207 1212', 'worker-overall-load-avg');

# define fake isotovideo
{
Expand Down
14 changes: 5 additions & 9 deletions t/43-scheduling-and-worker-scalability.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use OpenQA::Utils qw(service_port);
require OpenQA::Test::Database;
use OpenQA::Jobs::Constants;
use OpenQA::Log qw(setup_log);
use OpenQA::Test::Utils
qw(mock_service_ports setup_mojo_app_with_default_worker_timeout),
qw(create_user_for_workers create_webapi create_websocket_server),
qw(stop_service setup_fullstack_temp_dir);
use OpenQA::Test::Utils qw(
mock_service_ports setup_mojo_app_with_default_worker_timeout
create_user_for_workers create_webapi create_websocket_server
stop_service setup_fullstack_temp_dir simulate_load);
use OpenQA::Test::TimeLimit '20';
use OpenQA::Utils 'testcasedir';

Expand All @@ -41,11 +41,7 @@ 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;
my $load_avg_file = simulate_load('0.93 0.95 3.25 2/2207 1212', '43-scheduling-and-worker-scalability');

# read number of workers to spawn from environment variable; skip test entirely if variable not present
# similar to other fullstack tests
Expand Down
28 changes: 19 additions & 9 deletions t/lib/OpenQA/Test/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ BEGIN {
}

our (@EXPORT, @EXPORT_OK);
@EXPORT_OK = (
qw(mock_service_ports setup_mojo_app_with_default_worker_timeout),
qw(redirect_output create_user_for_workers),
qw(create_webapi create_websocket_server create_scheduler create_live_view_handler),
qw(unresponsive_worker broken_worker rejective_worker setup_share_dir setup_fullstack_temp_dir run_gru_job),
qw(stop_service start_worker unstable_worker fake_asset_server),
qw(cache_minion_worker cache_worker_service shared_hash embed_server_for_testing),
qw(run_cmd test_cmd wait_for wait_for_or_bail_out perform_minion_jobs),
qw(prepare_clean_needles_dir prepare_default_needle mock_io_loop assume_all_assets_exist schedule_iso)
@EXPORT_OK = qw(
mock_service_ports setup_mojo_app_with_default_worker_timeout
redirect_output create_user_for_workers
create_webapi create_websocket_server create_scheduler create_live_view_handler
unresponsive_worker broken_worker rejective_worker setup_share_dir setup_fullstack_temp_dir run_gru_job
stop_service start_worker unstable_worker fake_asset_server
cache_minion_worker cache_worker_service shared_hash embed_server_for_testing
run_cmd test_cmd wait_for wait_for_or_bail_out perform_minion_jobs
prepare_clean_needles_dir prepare_default_needle mock_io_loop assume_all_assets_exist schedule_iso
simulate_load
);

# The function OpenQA::Utils::service_port method hardcodes ports in a
Expand Down Expand Up @@ -667,4 +668,13 @@ sub schedule_iso ($t, $args, $status = 200, $query_params = {}, $msg = undef) {
$t->post_ok(Mojo::URL->new('/api/v1/isos')->query($query_params), form => $args)->status_is($status, $msg)->tx->res;
}

sub simulate_load ($load, $from) {
# fake "/proc/loadavg" to ensure the test works under a heavy load
my $load_avg_file = tempfile("$from-XXXXX");
my $load_avg_file_realpath = $load_avg_file->realpath;
$load_avg_file->spew($load);
$ENV{OPENQA_LOAD_AVG_FILE} = $load_avg_file_realpath;
return $load_avg_file;
}

1;

0 comments on commit e5bed5f

Please sign in to comment.