Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/OpenQA/WebAPI/Plugin/MemoryLimit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
# SPDX-License-Identifier: GPL-2.0-or-later

package OpenQA::WebAPI::Plugin::MemoryLimit;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Base 'Mojolicious::Plugin', -signatures;

use BSD::Resource 'getrusage';
use Mojo::IOLoop;

# Stop prefork workers gracefully once they reach a certain size
sub register {
my ($self, $app) = @_;

sub register ($self, $app, $conf) {
my $max = $app->config->{global}{max_rss_limit};
return unless $max && $max > 0;

Expand Down
13 changes: 13 additions & 0 deletions t/api/14-plugin_memory_limit.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

use Test::Most;
use Mojolicious;

use_ok('OpenQA::WebAPI::Plugin::MemoryLimit');

my $app = Mojolicious->new;
$app->config->{global}{max_rss_limit} = 42;
OpenQA::WebAPI::Plugin::MemoryLimit->register($app, undef);

Copy link
Contributor

@Martchus Martchus Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Mojo::IOLoop->start;

I guess you can set the conditions so the code under test will stop the loop automatically. And you should make the interval configurable to avoid wasting 5 seconds until that would happen.

done_testing;