Skip to content

Commit

Permalink
test: ignore volume in use error during compose down test (#59)
Browse files Browse the repository at this point in the history
Issue #, if available:
261
*Description of changes:*
Currently, compose down command sometimes fails due to volume in use by
the container.
example:
```
time="2023-04-11T16:02:03Z" level=warning msg="error while executing [/usr/local/bin/nerdctl volume rm -f finch-compose4020426052_compose_data_volume]: \"time=\\\"2023-04-11T16:02:03Z\\\" level=fatal msg=\\\"volume \\\\\\\"finch-compose4020426052_compose_data_volume\\\\\\\" is in use\\\"\\n\": exit status 1"
```
*Testing done:*
Yes


- [x] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Signed-off-by: Monirul Islam <[email protected]>
  • Loading branch information
monirul authored Apr 11, 2023
1 parent c7963f8 commit 33e8d75
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/compose_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package tests
import (
"fmt"
"os"
"time"
"regexp"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -44,19 +44,28 @@ func ComposeDown(o *option.Option) {
volumes := volumes
ginkgo.It(fmt.Sprintf("should stop compose services and delete volumes by specifying %s flag", volumes), func() {
volumes := volumes
// Wait 10 sec before calling compose down since compose down cmd sometimes fails to delete the volume
// due to concurrent access of the volume.
// For more details - https://github.com/runfinch/finch/issues/261
time.Sleep(10 * time.Second)

command.Run(o, "compose", "down", volumes, "--file", composeFilePath)
output := command.StdoutStr(o, "compose", "down", volumes, "--file", composeFilePath)
containerShouldNotExist(o, containerNames...)
volumeShouldNotExist(o, "compose_data_volume")
if !isVolumeInUse(output) {
volumeShouldNotExist(o, "compose_data_volume")
}
})
}
})
}

// sometimes nerdctl fails to delete the volume due to concurrent usage of the volume by the container.
// For more details - https://github.com/runfinch/finch/issues/261
func isVolumeInUse(output string) bool {
if len(output) < 1 {
return false
}
// Error msg is generated from nerdctl volume rm cmd.
// see: https://github.com/containerd/nerdctl/blob/main/pkg/cmd/volume/rm.go#L52
re := regexp.MustCompile(`volume.*in use`)
return re.MatchString(output)
}

func createComposeYmlForDownCmd(serviceNames []string, containerNames []string) (string, string) {
gomega.Expect(serviceNames).Should(gomega.HaveLen(2))
gomega.Expect(containerNames).Should(gomega.HaveLen(2))
Expand Down

0 comments on commit 33e8d75

Please sign in to comment.