diff --git a/ci/image-tests/Checks/ContainerEnvironmentChecks.php b/ci/image-tests/Checks/ContainerEnvironmentChecks.php index cb67f3c68..04fc34062 100644 --- a/ci/image-tests/Checks/ContainerEnvironmentChecks.php +++ b/ci/image-tests/Checks/ContainerEnvironmentChecks.php @@ -42,8 +42,7 @@ public function testTimeZoneFromTheEnvironment(): void /** * TZ=Europe/Berlin: cron runs a job for the current hour in Berlin, which is not the hour in UTC. The job comes from - * Hooks/ and is there before cron starts; the test works out its hours, see ImageTestCase::cronHours(). - * SERVICE_CRON_OPTS: cron logs the job at its log level, through syslog-ng into the file of LOG_STDOUT. Only in the + * Hooks/ and is there before cron starts; the test works out its hours, see ImageTestCase::cronHours(). Only in the * images that start cron. */ public function testCronRunsJobsInTheTimeZoneFromTheEnvironment(): void @@ -57,13 +56,29 @@ public function testCronRunsJobsInTheTimeZoneFromTheEnvironment(): void $this->waitFor(function () use ($container): void { self::assertSame("ran\n", $this->stdout('cat /tmp/image-tests/cron-job 2>&1 || true', $container)); }, 25, 3); + } + + /** + * SERVICE_CRON_OPTS: cron logs the job of the environment container at the log level of the variable, through + * syslog-ng into the file of LOG_STDOUT. At the default level, Debian logs only "CMD (echo ran ...)" and BusyBox + * only "USER root pid ... cmd echo ran ...", so the lines that the test looks for come from the variable: the end of + * the job with its process id (-L 15), the steps of BusyBox (-l 0). Only in the images that start cron. + */ + public function testCronLogsAtTheLevelFromTheEnvironment(): void + { + if (!in_array('cron', self::services(), true)) { + self::markTestSkipped('The image does not start cron.'); + } + + $container = $this->environmentContainer(); + // cron runs the job at the start of a minute, in the hours of ImageTestCase::cronHours() $this->waitFor(function () use ($container): void { self::assertMatchesRegularExpression( - self::image()->isAlpine() ? '/crond\[\d+\]: USER root pid +\d+ cmd echo ran/' : '/CRON\[\d+\]: \(root\) END \(\[\d+\] echo ran/', + self::image()->isAlpine() ? '/crond\[\d+\]: +job: \d+ echo ran/' : '/CRON\[\d+\]: \(root\) END \(\[\d+\] echo ran/', $this->stdout('cat ' . static::ENVIRONMENT['LOG_STDOUT'], $container), 'SERVICE_CRON_OPTS=' . self::cronOptions(), ); - }, 10, 1); + }, 25, 3); } /** diff --git a/ci/image-tests/Checks/ServiceChecks.php b/ci/image-tests/Checks/ServiceChecks.php index e12cd6b9b..48f9a3446 100644 --- a/ci/image-tests/Checks/ServiceChecks.php +++ b/ci/image-tests/Checks/ServiceChecks.php @@ -102,7 +102,7 @@ public static function serviceOptions(): iterable * What the SERVICE_*_OPTS of the environment container do: supervisord logs at the level "trace"; syslog-ng writes * its process id to the file of --pidfile; sshd listens on port 2222; Apache defines IMAGE_TEST, for which the * configuration from Hooks/ sends a header; PHP-FPM names the session cookie IMAGETEST. The log level of cron is - * checked by ContainerEnvironmentChecks. + * checked by ContainerEnvironmentChecks::testCronLogsAtTheLevelFromTheEnvironment(). */ #[DataProvider('serviceOptions')] public function testServiceOptionsFromTheEnvironment(string $service): void diff --git a/ci/image-tests/ImageTestCase.php b/ci/image-tests/ImageTestCase.php index cdda8d80f..b7f94f8c7 100644 --- a/ci/image-tests/ImageTestCase.php +++ b/ci/image-tests/ImageTestCase.php @@ -310,8 +310,8 @@ protected function environmentContainer(): Container } /** - * A log level option of cron in Debian and Ubuntu, of BusyBox crond in Alpine, at which cron logs each job it runs: - * Debian also logs its end, BusyBox its start. + * A log level option of cron in Debian and Ubuntu, of BusyBox crond in Alpine, at which cron logs more of each job + * than at its default level: Debian also its end with its process id, BusyBox also its steps. */ protected static function cronOptions(): string {