Skip to content

Commit a3c0dd7

Browse files
authored
Merge pull request #410 from Art4/add-redmine-server-health-check-for-redmine-services
Add health check for redmine services
2 parents 066212f + f93c4fc commit a3c0dd7

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.7"
2-
31
services:
42
php:
53
build: # Info to build the Docker image
@@ -25,7 +23,6 @@ services:
2523
- ./.docker/redmine-dev_data/sqlite:/usr/src/redmine/sqlite
2624

2725
# Make sure the following services are configured in:
28-
# - /tests/RedmineExtension/RedmineInstance.php
2926
# - /tests/Behat/behat.yml
3027

3128
redmine-50103:

tests/RedmineExtension/BehatHookTracer.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ final class BehatHookTracer implements InstanceRegistration
2222
*/
2323
private static array $instances = [];
2424

25-
/**
26-
* @return RedmineVersion[]
27-
*/
28-
public static function getSupportedRedmineVersions(): array
29-
{
30-
return RedmineInstance::getSupportedVersions();
31-
}
32-
3325
public static function getRedmineInstance(RedmineVersion $redmineVersion): RedmineInstance
3426
{
3527
if (static::$tracer === null) {

tests/RedmineExtension/RedmineInstance.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,11 @@
1010

1111
final class RedmineInstance
1212
{
13-
/**
14-
* Make sure that supported versions have a service in /docker-composer.yml
15-
* and are configured in /tests/Behat/behat.yml
16-
*/
17-
public static function getSupportedVersions(): array
18-
{
19-
return [
20-
RedmineVersion::V5_1_3,
21-
RedmineVersion::V5_0_9,
22-
RedmineVersion::V4_2_10,
23-
];
24-
}
25-
2613
/**
2714
* @param InstanceRegistration $tracer Required to ensure that RedmineInstance is created while Test Runner is running
2815
*/
2916
public static function create(InstanceRegistration $tracer, RedmineVersion $version): void
3017
{
31-
if (! in_array($version, static::getSupportedVersions())) {
32-
throw new InvalidArgumentException('Redmine ' . $version->asString() . ' is not supported.');
33-
}
34-
3518
$tracer->registerInstance(new self($tracer, $version));
3619
}
3720

@@ -77,6 +60,8 @@ private function __construct(InstanceRegistration $tracer, RedmineVersion $versi
7760
$this->redmineUrl = 'http://redmine-' . $versionId . ':3000';
7861
$this->apiKey = sha1($versionId . (string) time());
7962

63+
$this->runHealthChecks($version);
64+
8065
$this->createDatabaseBackup();
8166
$this->createFilesBackup();
8267
$this->runDatabaseMigration();
@@ -104,6 +89,33 @@ public function getApiKey(): string
10489
return $this->apiKey;
10590
}
10691

92+
private function runHealthChecks(RedmineVersion $version): void
93+
{
94+
$ch = curl_init($this->redmineUrl);
95+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
96+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
97+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
98+
$data = curl_exec($ch);
99+
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
100+
curl_close($ch);
101+
102+
if ($data === false || $statusCode !== 200) {
103+
throw new InvalidArgumentException(sprintf(
104+
'Could not connect to Redmine server at %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.',
105+
$this->redmineUrl,
106+
$version->asString(),
107+
));
108+
}
109+
110+
if (! file_exists($this->rootPath . $this->workingDB)) {
111+
throw new InvalidArgumentException(sprintf(
112+
'Could not find database file in %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.',
113+
$this->rootPath . $this->workingDB,
114+
$version->asString(),
115+
));
116+
}
117+
}
118+
107119
public function reset(InstanceRegistration $tracer): void
108120
{
109121
if ($tracer !== $this->tracer) {

0 commit comments

Comments
 (0)