Skip to content

Commit

Permalink
sanity: connect to CSI driver once per process
Browse files Browse the repository at this point in the history
Connecting once per test made testing flaky. We
could fix this with retries
(#97) but that
requires more discussion, so instead we just connect once per
process instead of once per test case. This was also said to be
faster (#98).

Fixes: #101
  • Loading branch information
pohly committed Aug 30, 2018
1 parent e11d328 commit de0605b
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type SanityContext struct {
Config *Config
Conn *grpc.ClientConn
Secrets *CSISecrets

connAddress string
}

// Test will test the CSI driver at the specified address by
Expand Down Expand Up @@ -92,9 +94,17 @@ func (sc *SanityContext) setup() {
sc.Secrets = &CSISecrets{}
}

By("connecting to CSI driver")
sc.Conn, err = utils.Connect(sc.Config.Address)
Expect(err).NotTo(HaveOccurred())
// It is possible that a test sets sc.Config.Address
// dynamically (and differently!) in a BeforeEach, so only
// reuse the connection if the address is still the same.
if sc.Conn == nil || sc.connAddress != sc.Config.Address {
By("connecting to CSI driver")
sc.Conn, err = utils.Connect(sc.Config.Address)
Expect(err).NotTo(HaveOccurred())
sc.connAddress = sc.Config.Address
} else {
By(fmt.Sprintf("reusing connection to CSI driver at %s", sc.connAddress))
}

By("creating mount and staging directories")
err = createMountTargetLocation(sc.Config.TargetPath)
Expand All @@ -106,10 +116,16 @@ func (sc *SanityContext) setup() {
}

func (sc *SanityContext) teardown() {
if sc.Conn != nil {
sc.Conn.Close()
sc.Conn = nil
}
// We intentionally do not close the connection to the CSI
// driver here because the large amount of connection attempts
// caused test failures
// (https://github.com/kubernetes-csi/csi-test/issues/101). We
// could fix this with retries
// (https://github.com/kubernetes-csi/csi-test/pull/97) but
// that requires more discussion, so instead we just connect
// once per process instead of once per test case. This was
// also said to be faster
// (https://github.com/kubernetes-csi/csi-test/pull/98).
}

func createMountTargetLocation(targetPath string) error {
Expand Down

0 comments on commit de0605b

Please sign in to comment.