You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2005/06/08 05:36:49 UTC

svn commit: r189511 - in /spamassassin/trunk/t: data/testplugin.pm spamd_prefork_stress_3.t

Author: jm
Date: Tue Jun  7 20:36:48 2005
New Revision: 189511

URL: http://svn.apache.org/viewcvs?rev=189511&view=rev
Log:
new stress test for prefork code, using random workloads

Added:
    spamassassin/trunk/t/spamd_prefork_stress_3.t   (with props)
Modified:
    spamassassin/trunk/t/data/testplugin.pm

Modified: spamassassin/trunk/t/data/testplugin.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/data/testplugin.pm?rev=189511&r1=189510&r2=189511&view=diff
==============================================================================
--- spamassassin/trunk/t/data/testplugin.pm (original)
+++ spamassassin/trunk/t/data/testplugin.pm Tue Jun  7 20:36:48 2005
@@ -28,6 +28,7 @@
 
   # the important bit!
   $self->register_eval_rule ("check_test_plugin");
+  $self->register_eval_rule ("sleep_based_on_header");
 
   print "registered myTestPlugin: $self\n";
   return $self;
@@ -49,6 +50,19 @@
     open (OUT, ">$file") or warn;
     print OUT ++$count;
     close OUT or warn;
+  }
+
+  return 1;
+}
+
+sub sleep_based_on_header {
+  my ($self, $permsgstatus) = @_;
+  my $secs = $permsgstatus->{msg}->get_header("Sleep-Time");
+  chop $secs;
+
+  if ($secs) {
+    warn "sleeping for $secs seconds...";
+    sleep ($secs+0);
   }
 
   return 1;

Added: spamassassin/trunk/t/spamd_prefork_stress_3.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/spamd_prefork_stress_3.t?rev=189511&view=auto
==============================================================================
--- spamassassin/trunk/t/spamd_prefork_stress_3.t (added)
+++ spamassassin/trunk/t/spamd_prefork_stress_3.t Tue Jun  7 20:36:48 2005
@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("spamd_prefork_stress_3");
+use Test;
+
+our $RUN_THIS_TEST;
+
+BEGIN {
+  $RUN_THIS_TEST = conf_bool('run_spamd_prefork_stress_test');
+  plan tests => ($SKIP_SPAMD_TESTS || !$RUN_THIS_TEST ? 0 : 291)
+};
+
+exit if $SKIP_SPAMD_TESTS;
+
+print "NOTE: this test requires 'run_spamd_prefork_stress_test' set to 'y'.\n";
+exit unless $RUN_THIS_TEST;
+
+# ---------------------------------------------------------------------------
+
+tstlocalrules ('
+        loadplugin myTestPlugin ../../data/testplugin.pm
+        header PLUGIN_SLEEP eval:sleep_based_on_header()
+');
+
+
+%patterns = (
+
+q{ X-Spam-Status: Yes, score=}, 'status',
+q{ X-Spam-Flag: YES}, 'flag',
+q{ X-Spam-Level: **********}, 'stars',
+q{ FROM_ENDS_IN_NUMS}, 'endsinnums',
+q{ NO_REAL_NAME}, 'noreal',
+
+);
+
+my $tmpnum = 0;
+start_spamd("-L -m5");
+ok ($spamd_pid > 1);
+
+srand ($$); print "srand: $$\n";
+
+ok (spamcrun ("< data/spam/001", \&patterns_run_cb));
+ok_all_patterns();
+
+test_fg(); ok_all_patterns();
+test_bg();
+foreach $i (0 .. 5) {
+  foreach $i (0 .. 20) {
+    test_bg();
+  }
+  test_fg(); ok_all_patterns();
+  test_fg(); ok_all_patterns();
+  test_fg(); ok_all_patterns();
+  test_fg(); ok_all_patterns();
+}
+
+test_fg(); ok_all_patterns();
+ok (stop_spamd());
+
+
+
+sub test_fg {
+  clear_pattern_counters();
+  my $secs = (int rand 5) + 1;
+  my $tmpf = mk_mail($secs);
+  ok (spamcrun ("<$tmpf", \&patterns_run_cb));
+  unlink $tmpf;
+  clean_pending_unlinks();
+}
+
+sub test_bg {
+  my $secs = (int rand 5) + 1;
+  my $tmpf = mk_mail($secs);
+  ok (spamcrun_background ("<$tmpf", {}));
+  push (@pending_unlinks, $tmpf);
+}
+
+sub mk_mail {
+  my $secs = shift;
+
+  my $tmpf = "log/tmp.$testname.$tmpnum"; $tmpnum++;
+
+  open (IN, "<data/spam/001");
+  open (OUT, ">$tmpf") or die "cannot write $tmpf";
+  print OUT "Sleep-Time: $secs\n";
+  while (<IN>) {
+    print OUT;
+  }
+  close OUT;
+  close IN;
+  return $tmpf;
+}
+
+sub clean_pending_unlinks {
+  unlink @pending_unlinks;
+  @pending_unlinks = ();
+}
+
+

Propchange: spamassassin/trunk/t/spamd_prefork_stress_3.t
------------------------------------------------------------------------------
    svn:executable = *