~ubuntu-branches/ubuntu/lucid/spamassassin/lucid-updates

1.1.3 by Duncan Findlay
Import upstream version 3.1.0a
1
#!/usr/bin/perl
2
#
3
# Warning: do not run this test on a live server; it will kill your
4
# spamd children ;)
5
6
use lib '.'; use lib 't';
7
use SATest; sa_t_init("spamd_prefork_stress_2");
8
use Test;
9
1.2.2 by Noah Meyerhans
Import upstream version 3.3.0
10
use constant TEST_ENABLED => conf_bool('run_long_tests');
1.1.3 by Duncan Findlay
Import upstream version 3.1.0a
11
our $RUN_THIS_TEST;
12
13
my $pgrep;
14
my $pkill;
15
16
# require pkill and pgrep be installed to run this test
17
BEGIN {
1.2.2 by Noah Meyerhans
Import upstream version 3.3.0
18
  $RUN_THIS_TEST = conf_bool('run_spamd_prefork_stress_test') && TEST_ENABLED;
1.1.3 by Duncan Findlay
Import upstream version 3.1.0a
19
  $pkill = locate_command("pkill");
20
  $pgrep = locate_command("pgrep");
21
  $RUN_THIS_TEST = 0 if !$pkill || !$pgrep;
1.2.2 by Noah Meyerhans
Import upstream version 3.3.0
22
  plan tests => ($SKIP_SPAMD_TESTS || !$RUN_THIS_TEST ? 0 : 14)
1.1.3 by Duncan Findlay
Import upstream version 3.1.0a
23
};
24
25
exit if $SKIP_SPAMD_TESTS;
26
1.2.2 by Noah Meyerhans
Import upstream version 3.3.0
27
print "NOTE: this test requires /usr/bin/pkill, /usr/bin/pgrep, and both\n".
28
    "'run_spamd_prefork_stress_test' and 'run_long_tests' set to 'y'.\n";
1.1.3 by Duncan Findlay
Import upstream version 3.1.0a
29
exit unless $RUN_THIS_TEST;
30
31
system($pgrep, "spamd child");
32
if ($? >> 8 == 0) {
33
  die "not running test: existing 'spamd child' processes would be killed.\n";
34
}
35
36
# ---------------------------------------------------------------------------
37
38
%patterns = (
39
40
q{ X-Spam-Status: Yes, score=}, 'status',
41
q{ X-Spam-Flag: YES}, 'flag',
42
q{ X-Spam-Level: **********}, 'stars',
43
q{ TEST_ENDSNUMS}, 'endsinnums',
44
q{ TEST_NOREALNAME}, 'noreal',
45
46
47
);
48
49
start_spamd("-L -m1 --round-robin");
50
ok ($spamd_pid > 1);
51
ok (spamcrun ("< data/spam/001", \&patterns_run_cb));
52
ok_all_patterns();
53
54
my $i = 0;
55
for ($i = 0; $i < 1999; $i++) {
56
  print "killing [$i]\n";
57
  system ($pkill, "-f", "spamd child");
58
}
59
1.1.7 by Scott Kitterman
Import upstream version 3.2.0
60
sleep 1;        # give it time to start a new one
1.1.3 by Duncan Findlay
Import upstream version 3.1.0a
61
clear_pattern_counters();
62
ok (spamcrun ("< data/spam/001", \&patterns_run_cb));
63
ok_all_patterns();
64
ok (stop_spamd());
65
66