Skip to content

Commit fad5f47

Browse files
pohlylpabon
authored andcommitted
sanity: connect to CSI driver once per process
Connecting once per test made testing flaky. We could fix this with retries (kubernetes-csi#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 (kubernetes-csi#98). Fixes: kubernetes-csi#101
1 parent ce66f45 commit fad5f47

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

pkg/sanity/sanity.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type SanityContext struct {
6060
Config *Config
6161
Conn *grpc.ClientConn
6262
Secrets *CSISecrets
63+
64+
connAddress string
6365
}
6466

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

95-
By("connecting to CSI driver")
96-
sc.Conn, err = utils.Connect(sc.Config.Address)
97-
Expect(err).NotTo(HaveOccurred())
97+
// It is possible that a test sets sc.Config.Address
98+
// dynamically (and differently!) in a BeforeEach, so only
99+
// reuse the connection if the address is still the same.
100+
if sc.Conn == nil || sc.connAddress != sc.Config.Address {
101+
By("connecting to CSI driver")
102+
sc.Conn, err = utils.Connect(sc.Config.Address)
103+
Expect(err).NotTo(HaveOccurred())
104+
sc.connAddress = sc.Config.Address
105+
} else {
106+
By(fmt.Sprintf("reusing connection to CSI driver at %s", sc.connAddress))
107+
}
98108

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

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

115131
func createMountTargetLocation(targetPath string) error {

0 commit comments

Comments
 (0)