summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Huß <roland@ro14nd.de>2022-09-13 09:08:21 +0200
committerGitHub <noreply@github.com>2022-09-13 09:08:21 +0200
commit01d3af64e016e1c8a6a6f02adf4618237f0737b4 (patch)
tree9f3a46ea77c5a7543027dd666674b41c27a71de6
parent7943f46f620b0cf4452d64d7d9ff3da7abe9cd65 (diff)
parentd3c30cea288b5d8aec4818695e830056d440ff30 (diff)
Merge pull request #10 from NicholasBHubbard/master
Add tests for processname, processprefix, and nostatus.
-rw-r--r--t/process_name.t159
1 files changed, 159 insertions, 0 deletions
diff --git a/t/process_name.t b/t/process_name.t
new file mode 100644
index 0000000..f2b62a7
--- /dev/null
+++ b/t/process_name.t
@@ -0,0 +1,159 @@
+#!/usr/bin/perl
+
+# Test the process naming options: processname, processprefix, and nostatus.
+
+use Test::More tests => 6;
+use Schedule::Cron;
+use strict;
+use warnings;
+
+my $orig_proc_name = $0;
+
+my $dispatch_1 = sub {
+ my $test_msg = 'process name suffixed with debug status by default';
+ my $process_name_rx = '^Schedule::Cron MainLoop - next: '.scalar(localtime).'$';
+ if ($0 =~ /$process_name_rx/) {
+ die "1-$test_msg\n";
+ }
+ else {
+ die "0-$test_msg\n";
+ }
+};
+my $cron = Schedule::Cron->new(
+ $dispatch_1,
+ nofork => 1,
+);
+$cron->add_entry('* * * * * 0-59');
+eval {
+ $cron->run();
+};
+my $error = $@;
+chomp $error;
+my ($ok, $msg) = split '-', $error, 2;
+ok $ok, $msg;
+$0 = $orig_proc_name;
+
+my $dispatch_2 = sub {
+ my $test_msg = q(process name doesn't change with nostatus);
+ if ($0 eq $orig_proc_name) {
+ die "1-$test_msg\n";
+ }
+ else {
+ die "0-$test_msg\n";
+ }
+};
+$cron = Schedule::Cron->new(
+ $dispatch_2,
+ nofork => 1,
+ nostatus => 1
+);
+$cron->add_entry('* * * * * 0-59');
+eval {
+ $cron->run();
+};
+$error = $@;
+chomp $error;
+($ok, $msg) = split '-', $error, 2;
+ok $ok, $msg;
+$0 = $orig_proc_name;
+
+my $dispatch_3 = sub {
+ my $test_msg = 'nostatus overrides processprefix';
+ if ($0 eq $orig_proc_name) {
+ die "1-$test_msg\n";
+ }
+ else {
+ print "\$0 = $0\n";
+ die "0-$test_msg\n";
+ }
+};
+$cron = Schedule::Cron->new(
+ $dispatch_3,
+ nofork => 1,
+ nostatus => 1,
+ processprefix => 'foo'
+);
+$cron->add_entry('* * * * * 0-59');
+eval {
+ $cron->run();
+};
+$error = $@;
+chomp $error;
+($ok, $msg) = split '-', $error, 2;
+ok $ok, $msg;
+$0 = $orig_proc_name;
+
+my $dispatch_4 = sub {
+ my $test_msg = 'process name prefixed with string when using processprefix';
+ my $rx = '^foo MainLoop - next: '.scalar(localtime).'$';
+ if ($0 =~ /$rx/) {
+ die "1-$test_msg\n";
+ }
+ else {
+ die "0-test_msg\n";
+ }
+};
+$cron = Schedule::Cron->new(
+ $dispatch_4,
+ nofork => 1,
+ processprefix => 'foo'
+);
+$cron->add_entry('* * * * * 0-59');
+eval {
+ $cron->run();
+};
+$error = $@;
+chomp $error;
+($ok, $msg) = split '-', $error, 2;
+ok $ok, $msg;
+$0 = $orig_proc_name;
+
+my $dispatch_5 = sub {
+ my $test_msg = 'process name set to constant string when using processname';
+ if ($0 eq 'foo') {
+ die "1-$test_msg\n";
+ }
+ else {
+ die "0-$test_msg\n";
+ }
+};
+$cron = Schedule::Cron->new(
+ $dispatch_5,
+ nofork => 1,
+ processname => 'foo'
+);
+$cron->add_entry('* * * * * 0-59');
+eval {
+ $cron->run();
+};
+$error = $@;
+chomp $error;
+($ok, $msg) = split '-', $error, 2;
+ok $ok, $msg;
+$0 = $orig_proc_name;
+
+my $dispatch_6 = sub {
+ my $test_msg = 'processname overrides nostatus and processprefix';
+ if ($0 eq 'foo') {
+ die "1-$test_msg\n";
+ }
+ else {
+ die "0-$test_msg\n";
+ }
+};
+$cron = Schedule::Cron->new(
+ $dispatch_6,
+ nofork => 1,
+ processname => 'foo',
+ nostatus => 1,
+ processprefix => 'bar'
+);
+$cron->add_entry('* * * * * 0-59');
+eval {
+ $cron->run();
+};
+$error = $@;
+chomp $error;
+($ok, $msg) = split '-', $error, 2;
+ok $ok, $msg;
+$0 = $orig_proc_name;