Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit e18e45a

Browse files
authored
Merge pull request #108 from paul-lysak/delay
Configurable delay between container launch and test start
2 parents 5e91ca5 + ba4f6b9 commit e18e45a

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ plugin will attempt to locate it in one of three places with the precedence orde
5656
5757
5) Optional: There are a number of optional Keys that can be set as well if you want to override the default settings:
5858
```
59+
composeContainerPauseBeforeTestSeconds := //Delay between containers start and test execution, seconds. Default is 0 seconds - no delay
5960
composeFile := // Specify the full path to the Compose File to use to create your test instance. It defaults to docker-compose.yml in your resources folder.
6061
composeServiceName := // Specify the name of the service in the Docker Compose file being tested. This setting prevents the service image from being pull down from the Docker Registry. It defaults to the sbt Project name.
6162
composeServiceVersionTask := // The version to tag locally built images with in the docker-compose file. This defaults to the 'version' SettingKey.

src/main/scala/com/tapad/docker/DockerComposeKeys.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import java.io._
66
object DockerComposeKeys extends DockerComposeKeysLocal
77

88
trait DockerComposeKeysLocal {
9+
val composeContainerPauseBeforeTestSeconds = settingKey[Int]("Delay between containers start and test execution, seconds. Default is 0 seconds - no delay")
910
val composeFile = settingKey[String]("Specify the full path to the Compose File to use to create your test instance. It defaults to docker-compose.yml in your resources folder.")
1011
val composeServiceName = settingKey[String]("The name of the service in the Docker Compose file being tested. This setting prevents the service image from being pull down from the Docker Registry. This defaults to the Project name.")
1112
val composeServiceVersionTask = taskKey[String]("The version to tag locally built images with in the docker-compose file. This defaults to the 'version' SettingKey.")

src/main/scala/com/tapad/docker/DockerComposePlugin.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ object DockerComposePlugin extends DockerComposePluginLocal {
6767

6868
//Import these settings so that they can easily be configured from a projects build.sbt
6969
object autoImport {
70+
val composeContainerPauseBeforeTestSeconds = DockerComposeKeys.composeContainerPauseBeforeTestSeconds
7071
val composeFile = DockerComposeKeys.composeFile
7172
val composeServiceName = DockerComposeKeys.composeServiceName
7273
val composeServiceVersionTask = DockerComposeKeys.composeServiceVersionTask
@@ -428,6 +429,14 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
428429
val requiresShutdown = getMatchingRunningInstance(newState, args).isEmpty
429430
val (preTestState, instance) = getTestPassInstance(newState, args)
430431

432+
val seconds = getSetting(composeContainerPauseBeforeTestSeconds)
433+
434+
if (seconds > 0) {
435+
print(s"Sleeping $seconds seconds to get ready for the tests")
436+
Thread.sleep(1000 * seconds)
437+
print("Wake up and starting the tests")
438+
}
439+
431440
//Ensure that if an exception is thrown when building the test code or during the test pass that
432441
//the instance that was started is cleaned up
433442
val finalState = Try {

src/main/scala/com/tapad/docker/DockerComposeSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ trait DockerComposeSettingsLocal extends PrintFormatting {
3232
composeRemoveNetworkOnShutdown := true,
3333
composeRemoveTempFileOnShutdown := true,
3434
composeContainerStartTimeoutSeconds := 500,
35+
composeContainerPauseBeforeTestSeconds := 0,
3536
dockerMachineName := "default",
3637
dockerImageCreationTask := printError("***Warning: The 'dockerImageCreationTask' has not been defined. " +
3738
"Please configure this setting to have Docker images built.***", suppressColorFormatting.value),

0 commit comments

Comments
 (0)