From d0eaca64391d87a7f68f95be66135cd7806bb6fa Mon Sep 17 00:00:00 2001 From: nekobit Date: Mon, 17 Oct 2022 19:18:46 +0000 Subject: [PATCH] Stress tests FossilOrigin-Name: a99b17e4812b46eab344023c64ed6cecea81f81ba945da3823d4accb3b337350 --- test/stress/account_page.pl | 17 ++++++++ test/stress/federated_timeline.pl | 10 +++++ test/stress/helpers.pm | 70 +++++++++++++++++++++++++++++++ test/stress/home_timeline.pl | 10 +++++ test/stress/local_timeline.pl | 10 +++++ test/stress/static_pages.pl | 18 ++++++++ 6 files changed, 135 insertions(+) create mode 100755 test/stress/account_page.pl create mode 100644 test/stress/federated_timeline.pl create mode 100644 test/stress/helpers.pm create mode 100644 test/stress/home_timeline.pl create mode 100644 test/stress/local_timeline.pl create mode 100644 test/stress/static_pages.pl diff --git a/test/stress/account_page.pl b/test/stress/account_page.pl new file mode 100755 index 0000000..632c741 --- /dev/null +++ b/test/stress/account_page.pl @@ -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'); diff --git a/test/stress/federated_timeline.pl b/test/stress/federated_timeline.pl new file mode 100644 index 0000000..982bdc2 --- /dev/null +++ b/test/stress/federated_timeline.pl @@ -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'); diff --git a/test/stress/helpers.pm b/test/stress/helpers.pm new file mode 100644 index 0000000..3f82d2f --- /dev/null +++ b/test/stress/helpers.pm @@ -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 = ; + 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; diff --git a/test/stress/home_timeline.pl b/test/stress/home_timeline.pl new file mode 100644 index 0000000..5fe37e1 --- /dev/null +++ b/test/stress/home_timeline.pl @@ -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, ''); diff --git a/test/stress/local_timeline.pl b/test/stress/local_timeline.pl new file mode 100644 index 0000000..aaa9be8 --- /dev/null +++ b/test/stress/local_timeline.pl @@ -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'); diff --git a/test/stress/static_pages.pl b/test/stress/static_pages.pl new file mode 100644 index 0000000..28ef1d1 --- /dev/null +++ b/test/stress/static_pages.pl @@ -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'); +