Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions ci/image-tests/Checks/ContainerEnvironmentChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ci/image-tests/Checks/ServiceChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ci/image-tests/ImageTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading