Skip to content

Commit 407a956

Browse files
committed
driver: docker-compose, action: run: fix a bug when handling a signal, when no default container
1 parent e046b08 commit 407a956

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Implemented Ctrl+C (SigInt) to work for action: run for both drivers (docker and docker-compose).
44
The change in the run action for docker-compose driver is that now Dojo first explicitly invokes the pull action
55
and then it invokes the run action.
6+
* Driver: docker-compose, action: run: fix a bug when handling a signal. Previously, when default container was
7+
not (yet) created, there was a panic. But, it may happen that the default container is not created while
8+
other containers are created. From now on, Dojo will not panic and it will stop the other containers.
69

710
### 0.8.0 (2020-Jan-01)
811

docker_compose_driver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ func (dc DockerComposeDriver) HandleSignal(mergedConfig Config, runID string) in
528528
}
529529

530530
defaultContainerID := dc.getDefaultContainerID(names)
531+
// it may happen that the default container is not created, but other containers are
531532
es := dc.stop(mergedConfig, runID, defaultContainerID)
532533
dc.Logger.Log("info", "Stopping on signal finished")
533534
return es
@@ -568,6 +569,7 @@ func (dc DockerComposeDriver) HandleMultipleSignal(mergedConfig Config, runID st
568569
}
569570

570571
defaultContainerID := dc.getDefaultContainerID(names)
572+
// it may happen that the default container is not created, but other containers are
571573
es := dc.kill(mergedConfig, runID, defaultContainerID)
572574
dc.Logger.Log("info", "Stopping on multiple signals finished")
573575
return es
@@ -588,7 +590,8 @@ func (dc DockerComposeDriver) getDefaultContainerID(containersNames []string) st
588590
return contanerInfo.ID
589591
}
590592
}
591-
panic(fmt.Errorf("default container not found. Were the containers created?"))
593+
dc.Logger.Log("info", "Default container not found")
594+
return ""
592595
}
593596

594597
// example output of docker-compose ps:

docker_compose_driver_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,9 @@ func Test_getDefaultContainerID_notCreated(t *testing.T) {
531531
shellS := NewMockedShellServiceNotInteractive(logger)
532532
driver := NewDockerComposeDriver(shellS, fs, logger)
533533

534-
defer func() {
535-
r := recover()
536-
assert.Contains(t, r.(error).Error(), "default container not found. Were the containers created?")
537-
}()
538-
539534
names := []string{}
540535
id := driver.getDefaultContainerID(names)
541536
assert.Equal(t, "", id)
542-
t.Fatal("Expected panic")
543537
}
544538

545539
func Test_checkContainerIsRunning(t *testing.T) {

0 commit comments

Comments
 (0)