Skip to content

Commit

Permalink
Merge 51218db into 76a720c
Browse files Browse the repository at this point in the history
  • Loading branch information
HenningCash committed May 23, 2019
2 parents 76a720c + 51218db commit 55575a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ class ContainerService(
*/
fun startIdeContainer(answer: Answer) {
// either take existing container or create a new one
val containerId = this.getIdeContainer(answer) ?: this.createIdeContainer(answer)
// make sure the container is running. Also existing ones could have been stopped
if (!isContainerRunning(containerId)) {
var containerId = this.getIdeContainer(answer)
if (containerId == null) {
containerId = this.createIdeContainer(answer)
docker.startContainer(containerId)
// prepare the environment after the container has started
this.prepareIdeContainer(containerId, answer)
} else if (!isContainerRunning(containerId)) {
// make sure the container is running. Also existing ones could have been stopped
docker.startContainer(containerId)
}
// prepare the environment after the container has started
this.prepareIdeContainer(containerId, answer)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import de.code_freak.codefreak.SpringTest
import de.code_freak.codefreak.entity.Answer
import de.code_freak.codefreak.util.TarUtil
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.hasSize
import org.hamcrest.Matchers.not
Expand Down Expand Up @@ -68,6 +69,18 @@ internal class ContainerServiceTest : SpringTest() {
assertThat(dirContent, not(containsString("root")))
}

@Test
fun `files are not overridden in existing IDE containers`() {
`when`(answer.files).thenReturn(TarUtil.createTarFromDirectory(ClassPathResource("tasks/c-simple").file))
containerService.startIdeContainer(answer)
val containerId = getIdeContainer(answer).id()
containerService.exec(containerId, arrayOf("sh", "-c", "echo 'foo' >> main.c"))
val fileContentBefore = containerService.exec(containerId, arrayOf("cat", "main.c"))
containerService.startIdeContainer(answer)
val fileContentAfter = containerService.exec(containerId, arrayOf("cat", "main.c"))
assertThat(fileContentAfter, `is`(fileContentBefore))
}

@Test
fun `idle containers are shut down automatically`() {
containerService.startIdeContainer(answer)
Expand Down

0 comments on commit 55575a6

Please sign in to comment.