[icinga-checkins] icinga.org: icinga-core/mfriedrich/fixes: Updated tests to check that comment ids are sorted

git at icinga.org git at icinga.org
Sun Jan 10 08:40:18 CET 2010


Module: icinga-core
Branch: mfriedrich/fixes
Commit: 48389d975ff99e05647dd848b4957e103ab806c9
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=48389d975ff99e05647dd848b4957e103ab806c9

Author: Ton Voon <ton.voon at opsera.com>
Date:   Wed Jan  6 11:20:31 2010 +0000

Updated tests to check that comment ids are sorted

---

 t/660status-downtimes-comments.t |   23 +++++++++++++++++++++--
 t/bin/generate_downtimes         |   13 +++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/t/660status-downtimes-comments.t b/t/660status-downtimes-comments.t
index 5593f56..5981a55 100644
--- a/t/660status-downtimes-comments.t
+++ b/t/660status-downtimes-comments.t
@@ -13,6 +13,7 @@ chdir $Bin or die "Cannot chdir";
 my $topdir = "$Bin/..";
 my $cgi_dir = "$topdir/cgi";
 my $status_cgi = "$cgi_dir/status.cgi";
+my $extinfo_cgi = "$cgi_dir/extinfo.cgi";
 my $status_dat = "$Bin/var/status.dat";
 my $generated = "$Bin/var/status-generated.dat";
 my $generator = "$Bin/bin/generate_downtimes";
@@ -22,10 +23,10 @@ my $expected;
 
 
 my $iteration = 1;
-my $iterations_max = 5;
+my $iterations_max = shift @ARGV || 5;
 my $copies;
 
-plan tests => 3 * $iterations_max;
+plan tests => 4 * $iterations_max;
 
 while($iteration <= $iterations_max) {
 	$copies = (10)**($iteration);
@@ -37,6 +38,24 @@ while($iteration <= $iterations_max) {
 	$output = `NAGIOS_CGI_CONFIG=etc/cgi-with-generated-status.cfg REQUEST_METHOD=GET REMOTE_USER=icingaadmin QUERY_STRING="host=host1" $status_cgi`;
 	my $duration = time-$start;
 	like( $output, "/This service has $num_comments comments associated with it/", "Found $num_comments comments in HTML output from status.dat. Took $duration seconds" );
+
+	# Check that the comments ids are sorted
+	$output = `NAGIOS_CGI_CONFIG=etc/cgi-with-generated-status.cfg REQUEST_METHOD=GET REMOTE_USER=nagiosadmin QUERY_STRING="type=2&host=host1&service=Dummy+service" $extinfo_cgi`;
+	check_decrementing_comment_ids();
+
 	$iteration++;
 }
 
+sub check_decrementing_comment_ids {
+	my $last_id;
+	my @ids = $output =~ m/<a href='cmd.cgi\?cmd_typ=4&com_id=(\d+)'>/g;
+	while ($_ = shift @ids) {
+		unless (defined $last_id && $last_id > $_) {
+			fail("Comment ids out of order");
+			return;
+		}
+		$last_id = $_;
+	}
+	ok( "All ids in order" );
+}
+
diff --git a/t/bin/generate_downtimes b/t/bin/generate_downtimes
index 429f2c1..b9476f3 100755
--- a/t/bin/generate_downtimes
+++ b/t/bin/generate_downtimes
@@ -9,6 +9,9 @@ my $max_iterations = shift @ARGV || 1000;
 my $hostname = "host1";
 my $servicename = "Dummy service";
 
+my $servicecomment_id_start=1024;
+my $servicecomment_ids = {};
+
 my $downtime_id = 2596;
 my $starttime = 9000000000;
 my $downtime_template = <<EOF;
@@ -57,6 +60,8 @@ EOF
 
 for(my $i=0; $i < $max_iterations; $i++ ) {
 	my $downtime = $downtime_template;
+	my $service_comment_id = get_random_servicecomment_id();
+	$downtime =~ s/%DOWNTIMEID%/$service_comment_id/g;
 	$downtime =~ s/%DOWNTIMEID1%/$downtime_id/g;
 	$downtime_id++;
 	$downtime =~ s/%DOWNTIMEID2%/$downtime_id/g;
@@ -69,3 +74,11 @@ for(my $i=0; $i < $max_iterations; $i++ ) {
 
 	print $downtime;
 }
+
+sub get_random_servicecomment_id {
+NEXT_ID:
+	my $id = $servicecomment_id_start + int(rand(100*$max_iterations));
+	goto NEXT_ID if exists $servicecomment_ids->{ $id };
+	$servicecomment_ids->{ $id } = 1;
+	return $id;
+}





More information about the icinga-checkins mailing list