Skip to content

Commit 4198d90

Browse files
committed
Enable test setup to run in parallel
1 parent b6f703a commit 4198d90

File tree

4 files changed

+45
-36
lines changed

4 files changed

+45
-36
lines changed

test/e2e/tests/multi_zone_e2e_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
8888

8989
// Create Disk
9090
volName := testNamePrefix + string(uuid.NewUUID())
91-
volId, err := controllerClient.CreateVolume(volName, map[string]string{
91+
volID, err := controllerClient.CreateVolume(volName, map[string]string{
9292
common.ParameterKeyReplicationType: "regional-pd",
9393
}, defaultSizeGb, &csi.TopologyRequirement{
9494
Requisite: []*csi.Topology{
@@ -119,7 +119,7 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
119119

120120
defer func() {
121121
// Delete Disk
122-
controllerClient.DeleteVolume(volId)
122+
controllerClient.DeleteVolume(volID)
123123
Expect(err).To(BeNil(), "DeleteVolume failed")
124124

125125
// Validate Disk Deleted
@@ -134,45 +134,45 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
134134
if i >= 1 {
135135
readOnly = true
136136
}
137-
testAttachWriteReadDetach(volId, volName, testContext.Instance, testContext.Client, readOnly)
137+
testAttachWriteReadDetach(volID, volName, testContext.Instance, testContext.Client, readOnly)
138138
i = i + 1
139139
}
140140

141141
})
142142

143143
})
144144

145-
func testAttachWriteReadDetach(volId string, volName string, instance *remote.InstanceInfo, client *remote.CsiClient, readOnly bool) {
145+
func testAttachWriteReadDetach(volID string, volName string, instance *remote.InstanceInfo, client *remote.CsiClient, readOnly bool) {
146146
var err error
147147

148-
Logf("Starting testAttachWriteReadDetach with volume %v node %v with readonly %v\n", volId, instance.GetNodeID(), readOnly)
148+
Logf("Starting testAttachWriteReadDetach with volume %v node %v with readonly %v\n", volID, instance.GetNodeID(), readOnly)
149149
// Attach Disk
150-
err = client.ControllerPublishVolume(volId, instance.GetNodeID())
151-
Expect(err).To(BeNil(), "ControllerPublishVolume failed with error for disk %v on node %v", volId, instance.GetNodeID())
150+
err = client.ControllerPublishVolume(volID, instance.GetNodeID())
151+
Expect(err).To(BeNil(), "ControllerPublishVolume failed with error for disk %v on node %v", volID, instance.GetNodeID())
152152

153153
defer func() {
154154

155155
// Detach Disk
156-
err = client.ControllerUnpublishVolume(volId, instance.GetNodeID())
156+
err = client.ControllerUnpublishVolume(volID, instance.GetNodeID())
157157
Expect(err).To(BeNil(), "ControllerUnpublishVolume failed with error")
158158
}()
159159

160160
// Stage Disk
161161
stageDir := filepath.Join("/tmp/", volName, "stage")
162-
client.NodeStageVolume(volId, stageDir)
162+
client.NodeStageVolume(volID, stageDir)
163163
Expect(err).To(BeNil(), "NodeStageVolume failed with error")
164164

165165
defer func() {
166166
// Unstage Disk
167-
err = client.NodeUnstageVolume(volId, stageDir)
167+
err = client.NodeUnstageVolume(volID, stageDir)
168168
Expect(err).To(BeNil(), "NodeUnstageVolume failed with error")
169169
err = testutils.RmAll(instance, filepath.Join("/tmp/", volName))
170170
Expect(err).To(BeNil(), "Failed to remove temp directory")
171171
}()
172172

173173
// Mount Disk
174174
publishDir := filepath.Join("/tmp/", volName, "mount")
175-
err = client.NodePublishVolume(volId, stageDir, publishDir)
175+
err = client.NodePublishVolume(volID, stageDir, publishDir)
176176
Expect(err).To(BeNil(), "NodePublishVolume failed with error")
177177
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
178178
Expect(err).To(BeNil(), "Chmod failed with error")
@@ -185,12 +185,12 @@ func testAttachWriteReadDetach(volId string, volName string, instance *remote.In
185185
}
186186

187187
// Unmount Disk
188-
err = client.NodeUnpublishVolume(volId, publishDir)
188+
err = client.NodeUnpublishVolume(volID, publishDir)
189189
Expect(err).To(BeNil(), "NodeUnpublishVolume failed with error")
190190

191191
// Mount disk somewhere else
192192
secondPublishDir := filepath.Join("/tmp/", volName, "secondmount")
193-
err = client.NodePublishVolume(volId, stageDir, secondPublishDir)
193+
err = client.NodePublishVolume(volID, stageDir, secondPublishDir)
194194
Expect(err).To(BeNil(), "NodePublishVolume failed with error")
195195
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
196196
Expect(err).To(BeNil(), "Chmod failed with error")
@@ -202,8 +202,8 @@ func testAttachWriteReadDetach(volId string, volName string, instance *remote.In
202202
Expect(strings.TrimSpace(string(readContents))).To(Equal(testFileContents))
203203

204204
// Unmount Disk
205-
err = client.NodeUnpublishVolume(volId, secondPublishDir)
205+
err = client.NodeUnpublishVolume(volID, secondPublishDir)
206206
Expect(err).To(BeNil(), "NodeUnpublishVolume failed with error")
207207

208-
Logf("Completed testAttachWriteReadDetach with volume %v node %v\n", volId, instance.GetNodeID())
208+
Logf("Completed testAttachWriteReadDetach with volume %v node %v\n", volID, instance.GetNodeID())
209209
}

test/e2e/tests/setup_e2e_test.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func TestE2E(t *testing.T) {
4848

4949
var _ = BeforeSuite(func() {
5050
var err error
51+
tcc := make(chan *remote.TestContext)
52+
defer close(tcc)
53+
5154
zones := []string{"us-central1-c", "us-central1-b"}
5255

5356
rand.Seed(time.Now().UnixNano())
@@ -68,17 +71,25 @@ var _ = BeforeSuite(func() {
6871
Logf("Running in project %v with service account %v\n\n", *project, *serviceAccount)
6972

7073
for _, zone := range zones {
71-
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", zone)
72-
73-
i, err := remote.SetupInstance(*project, zone, nodeID, *serviceAccount, computeService)
74-
Expect(err).To(BeNil())
75-
76-
// Create new driver and client
77-
testContext, err := testutils.GCEClientAndDriverSetup(i)
78-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
79-
80-
testContexts = append(testContexts, testContext)
74+
go func(curZone string) {
75+
defer GinkgoRecover()
76+
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", curZone)
77+
Logf("Setting up node %s\n", nodeID)
78+
79+
i, err := remote.SetupInstance(*project, curZone, nodeID, *serviceAccount, computeService)
80+
Expect(err).To(BeNil())
81+
82+
// Create new driver and client
83+
testContext, err := testutils.GCEClientAndDriverSetup(i)
84+
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
85+
tcc <- testContext
86+
}(zone)
87+
}
8188

89+
for i := 0; i < len(zones); i++ {
90+
tc := <-tcc
91+
Logf("Test Context for node %s set up\n", tc.Instance.GetName())
92+
testContexts = append(testContexts, tc)
8293
}
8394
})
8495

test/e2e/tests/single_zone_e2e_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
4747

4848
// Create Disk
4949
volName := testNamePrefix + string(uuid.NewUUID())
50-
volId, err := client.CreateVolume(volName, nil, defaultSizeGb,
50+
volID, err := client.CreateVolume(volName, nil, defaultSizeGb,
5151
&csi.TopologyRequirement{
5252
Requisite: []*csi.Topology{
5353
{
@@ -67,7 +67,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
6767

6868
defer func() {
6969
// Delete Disk
70-
client.DeleteVolume(volId)
70+
client.DeleteVolume(volID)
7171
Expect(err).To(BeNil(), "DeleteVolume failed")
7272

7373
// Validate Disk Deleted
@@ -76,7 +76,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
7676
}()
7777

7878
// Attach Disk
79-
testAttachWriteReadDetach(volId, volName, instance, client, false /* readOnly */)
79+
testAttachWriteReadDetach(volID, volName, instance, client, false /* readOnly */)
8080

8181
})
8282

@@ -124,7 +124,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
124124

125125
// Create Disk
126126
volName := testNamePrefix + string(uuid.NewUUID())
127-
volId, err := controllerClient.CreateVolume(volName, map[string]string{
127+
volID, err := controllerClient.CreateVolume(volName, map[string]string{
128128
common.ParameterKeyReplicationType: "regional-pd",
129129
}, defaultSizeGb, nil)
130130
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
@@ -146,7 +146,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
146146
}
147147
defer func() {
148148
// Delete Disk
149-
controllerClient.DeleteVolume(volId)
149+
controllerClient.DeleteVolume(volID)
150150
Expect(err).To(BeNil(), "DeleteVolume failed")
151151

152152
// Validate Disk Deleted
@@ -164,7 +164,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
164164

165165
// Create Disk
166166
volName := testNamePrefix + string(uuid.NewUUID())
167-
volId, err := client.CreateVolume(volName, nil, defaultSizeGb, nil)
167+
volID, err := client.CreateVolume(volName, nil, defaultSizeGb, nil)
168168
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
169169

170170
// Validate Disk Created
@@ -177,7 +177,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
177177

178178
defer func() {
179179
// Delete Disk
180-
client.DeleteVolume(volId)
180+
client.DeleteVolume(volID)
181181
Expect(err).To(BeNil(), "DeleteVolume failed")
182182

183183
// Validate Disk Deleted

test/remote/setup-teardown.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ import (
2222

2323
"github.com/golang/glog"
2424
compute "google.golang.org/api/compute/v1"
25-
)
26-
27-
const (
28-
archiveName = "e2e_driver_binaries.tar.gz"
25+
"k8s.io/apimachinery/pkg/util/uuid"
2926
)
3027

3128
// TestContext holds the CSI Client handle to a remotely connected Driver
@@ -75,6 +72,7 @@ func SetupInstance(instanceProject, instanceZone, instanceName, instanceServiceA
7572
// a CSI client to it through SHH tunnelling. It returns a TestContext with both a handle to the instance
7673
// that the driver is on and the CSI Client object to make CSI calls to the remote driver.
7774
func SetupNewDriverAndClient(instance *InstanceInfo, config *ClientConfig) (*TestContext, error) {
75+
archiveName := fmt.Sprintf("e2e_driver_binaries_%s.tar.gz", uuid.NewUUID())
7876
archivePath, err := CreateDriverArchive(archiveName, config.PkgPath, config.BinPath)
7977
if err != nil {
8078
return nil, err

0 commit comments

Comments
 (0)