Skip to content

Commit

Permalink
Fix some flaky tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Wels <[email protected]>
  • Loading branch information
awels committed Nov 19, 2018
1 parent 1dd1986 commit c5eb5b6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
17 changes: 11 additions & 6 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,24 @@ var _ = Describe("DataVolume tests", func() {
By(fmt.Sprint("Verifying events occurred"))
for _, eventReason := range eventReasons {
Eventually(func() bool {
events, err := tests.RunKubectlCommand(f, "get", "events", "-n", dataVolume.Namespace)
Expect(err).NotTo(HaveOccurred())
return strings.Contains(events, eventReason)
events, err := tests.RunKubectlCommand(f, "describe", "dv", dataVolume.Name, "-n", dataVolume.Namespace)
if err == nil {
fmt.Fprintf(GinkgoWriter, "%s", events)
return strings.Contains(events, eventReason)
} else {
fmt.Fprintf(GinkgoWriter, "ERROR: %s\n", err.Error())
return false
}
}, timeout, pollingInterval).Should(BeTrue())
}

err = utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolume)
Expect(err).ToNot(HaveOccurred())

},
table.Entry("succeed when given valid url", utils.TinyCoreIsoURL, cdiv1.Succeeded, "dv-phase-test-1", []string{controller.ImportScheduled, controller.ImportSucceeded}),
table.Entry("fail due to invalid DNS entry", "http://i-made-this-up.kube-system/tinyCore.iso", cdiv1.Failed, "dv-phase-test-2", []string{controller.ImportScheduled}),
table.Entry("fail due to file not found", utils.TinyCoreIsoURL+"not.real.file", cdiv1.Failed, "dv-phase-test-3", []string{controller.ImportScheduled}),
table.Entry("succeed when given valid url", utils.TinyCoreIsoURL, cdiv1.Succeeded, "dv-phase-test-1", []string{controller.ImportSucceeded}),
table.Entry("fail due to invalid DNS entry", "http://i-made-this-up.kube-system/tinyCore.iso", cdiv1.Failed, "dv-phase-test-2", []string{controller.ImportFailed}),
table.Entry("fail due to file not found", utils.TinyCoreIsoURL+"not.real.file", cdiv1.Failed, "dv-phase-test-3", []string{controller.ImportFailed}),
)

table.DescribeTable("with clone source should", func(command string, phase cdiv1.DataVolumePhase, dataVolumeName string) {
Expand Down
5 changes: 5 additions & 0 deletions tests/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"k8s.io/api/core/v1"

"kubevirt.io/containerized-data-importer/tests/framework"
"kubevirt.io/containerized-data-importer/tests/utils"
)
Expand Down Expand Up @@ -44,6 +46,9 @@ var _ = Describe("Upload tests", func() {
err = utils.UploadImageFromNode(f.K8sClient, f.GoCLIPath, token)
Expect(err).ToNot(HaveOccurred())

err = f.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, pvc.Name)
Expect(err).ToNot(HaveOccurred())

By("Verify content")
same := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, testFile, utils.UploadFileMD5)
Expect(same).To(BeTrue())
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func FindPodByPrefix(clientSet *kubernetes.Clientset, namespace, prefix, labelSe
}

func newExecutorPodWithPVC(podName string, pvc *k8sv1.PersistentVolumeClaim) *k8sv1.Pod {
return NewPodWithPVC(podName, "sleep 15; echo I am an executor pod;", pvc)
return NewPodWithPVC(podName, "sleep 30; echo I am an executor pod;", pvc)
}

// WaitTimeoutForPodReady waits for the given pod to be created and ready
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"fmt"

"github.com/onsi/ginkgo"
k8sv1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -129,6 +130,7 @@ func NewPVCDefinition(pvcName string, size string, annotations, labels map[strin
func WaitForPersistentVolumeClaimPhase(clientSet *kubernetes.Clientset, namespace string, phase k8sv1.PersistentVolumeClaimPhase, pvcName string) error {
err := wait.PollImmediate(pvcPollInterval, pvcPhaseTime, func() (bool, error) {
pvc, err := clientSet.CoreV1().PersistentVolumeClaims(namespace).Get(pvcName, metav1.GetOptions{})
fmt.Fprintf(ginkgo.GinkgoWriter, "INFO: Checking PVC phase: %s\n", string(pvc.Status.Phase))
if err != nil || pvc.Status.Phase != phase {
return false, err
}
Expand Down
11 changes: 6 additions & 5 deletions tools/cdi-func-test-file-host-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
)

func main() {
Expand Down Expand Up @@ -52,7 +51,7 @@ func main() {
type formatTable [][]string

func (ft formatTable) initializeTestFiles(inFile, outDir string) error {
var wg sync.WaitGroup
sem := make(chan bool, 3)
errChan := make(chan error, len(ft))

reportError := func(err error, msg string, format ...interface{}) {
Expand All @@ -63,10 +62,10 @@ func (ft formatTable) initializeTestFiles(inFile, outDir string) error {
}

for _, fList := range ft {
wg.Add(1)
sem <- true

go func(i, o string, f []string) {
defer wg.Done()
defer func() { <-sem }()
glog.Infof("Generating file %s\n", f)

ext := strings.Join(f, "")
Expand Down Expand Up @@ -98,7 +97,9 @@ func (ft formatTable) initializeTestFiles(inFile, outDir string) error {
glog.Infof("Generated file %q\n", p)
}(inFile, outDir, fList)
}
wg.Wait()
for i := 0; i < cap(sem); i++ {
sem <- true
}
close(errChan)

if len(errChan) > 0 {
Expand Down

0 comments on commit c5eb5b6

Please sign in to comment.