Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ignore volume in use error during compose down test #59

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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