Stress tests

FossilOrigin-Name: a99b17e4812b46eab344023c64ed6cecea81f81ba945da3823d4accb3b337350
This commit is contained in:
nekobit 2022-10-17 19:18:46 +00:00
parent a6a730649d
commit d0eaca6439
6 changed files with 135 additions and 0 deletions

17
test/stress/account_page.pl Executable file
View File

@ -0,0 +1,17 @@
#!/bin/perl
BEGIN { push @INC, '.' }
use strict;
use warnings;
use helpers;
my ($url) = helpers::prompt_instance_info();
my $account = helpers::prompt('The Account', '?');
my $num = helpers::prompt('# of requests');
helpers::stress_test('Main account page', $url, $num, '@' . $account);
helpers::stress_test('Scrobbles', $url, $num, '@' . $account . '/scrobbles');
helpers::stress_test('Pinned statuses', $url, $num, '@' . $account . '/pinned');
helpers::stress_test('Media', $url, $num, '@' . $account . '/media');
helpers::stress_test('Following', $url, $num, '@' . $account . '/following');
helpers::stress_test('Followers', $url, $num, '@' . $account . '/followers');
helpers::stress_test('Statuses', $url, $num, '@' . $account . '/statuses');

View File

@ -0,0 +1,10 @@
#!/bin/perl
BEGIN { push @INC, '.' }
use strict;
use warnings;
use helpers;
my ($url) = helpers::prompt_instance_info();
my $num = helpers::prompt('# of requests');
helpers::stress_test('Federated timeline', $url, $num, 'federated');

70
test/stress/helpers.pm Normal file
View File

@ -0,0 +1,70 @@
package helpers;
use strict;
use warnings;
use threads;
use Exporter 'import';
our @EXPORT_OK = qw( prompt );
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("TreebirdTest/1.0 ");
sub prompt
{
my ($msg, $suffix) = @_;
print $msg . ($suffix || ':') . ' ';
my $answer = <STDIN>;
chomp($answer);
$answer;
}
sub prompt_instance_info
{
my $instance = prompt('Instance domain (http://localhost [blank], treebird.social)');
unless ($instance)
{
$instance = 'http://localhost';
}
elsif (rindex($instance, 'http://', 0) + rindex($instance, 'https://', 0) == -2)
{
$instance = 'https://' . $instance;
}
return (
$instance . '/'
);
}
sub stress_test
{
my ($name, $url, $num, $path) = @_;
my $fullurl = $url . $path;
my @threads;
print "Sending requests to \"$fullurl\" for case \"$name\": ";
foreach (0..$num)
{
print(".");
push @threads, async {
my $req = HTTP::Request->new(GET => $fullurl);
$ua->request($req);
};
}
foreach my $thread (@threads) {
my $res = $thread->join;
unless ($res->is_success)
{
print "\n========================\n";
print "Test stress case \"$name\" failed!";
print "\n========================\n";
exit(1);
}
}
}
1;

View File

@ -0,0 +1,10 @@
#!/bin/perl
BEGIN { push @INC, '.' }
use strict;
use warnings;
use helpers;
my ($url) = helpers::prompt_instance_info();
my $num = helpers::prompt('# of requests');
helpers::stress_test('Home timeline', $url, $num, '');

View File

@ -0,0 +1,10 @@
#!/bin/perl
BEGIN { push @INC, '.' }
use strict;
use warnings;
use helpers;
my ($url) = helpers::prompt_instance_info();
my $num = helpers::prompt('# of requests');
helpers::stress_test('Local instance timeline', $url, $num, 'local');

View File

@ -0,0 +1,18 @@
#!/bin/perl
BEGIN { push @INC, '.' }
use strict;
use warnings;
use helpers;
my ($url) = helpers::prompt_instance_info();
my $num = helpers::prompt('# of requests per each page');
helpers::stress_test('About page', $url, $num, 'about');
helpers::stress_test('License page', $url, $num, 'about/license');
helpers::stress_test('Login page', $url, $num, 'login');
helpers::stress_test('Search page', $url, $num, 'search');
helpers::stress_test('Emoji picker page', $url, $num, 'emoji_picker');
helpers::stress_test('Config page', $url, $num, 'config');
helpers::stress_test('General page for Config', $url, $num, 'config/general');
helpers::stress_test('Appearance page for Config', $url, $num, 'config/appearance');