Skip to content

Commit b6f703a

Browse files
committed
Test contexts are now initialized once on startup instead of per-test
1 parent d69d75e commit b6f703a

File tree

4 files changed

+32
-68
lines changed

4 files changed

+32
-68
lines changed

test/e2e/tests/multi_zone_e2e_test.go

+6-20
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,11 @@ import (
3131

3232
var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
3333
BeforeEach(func() {
34-
Expect(len(testInstances)).To(BeNumerically(">", 1))
34+
Expect(len(testContexts)).To(BeNumerically(">", 1))
3535
})
3636

3737
It("Should get reasonable topology from nodes with NodeGetInfo", func() {
38-
for _, instance := range testInstances {
39-
testContext, err := testutils.GCEClientAndDriverSetup(instance)
40-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
41-
defer func() {
42-
err := remote.TeardownDriverAndClient(testContext)
43-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
44-
}()
45-
38+
for _, testContext := range testContexts {
4639
resp, err := testContext.Client.NodeGetInfo()
4740
Expect(err).To(BeNil())
4841

@@ -65,24 +58,17 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
6558
It("Should successfully run through entire lifecycle of an RePD volume on instances in 2 zones", func() {
6659
// Create new driver and client
6760

68-
Expect(testInstances).NotTo(BeEmpty())
61+
Expect(testContexts).NotTo(BeEmpty())
6962

7063
zoneToContext := map[string]*remote.TestContext{}
7164
zones := []string{}
7265

73-
for _, i := range testInstances {
74-
_, z, _ := i.GetIdentity()
66+
for _, tc := range testContexts {
67+
_, z, _ := tc.Instance.GetIdentity()
7568
// Zone hasn't been seen before
7669
if _, ok := zoneToContext[z]; !ok {
77-
c, err := testutils.GCEClientAndDriverSetup(i)
78-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
79-
zoneToContext[z] = c
70+
zoneToContext[z] = tc
8071
zones = append(zones, z)
81-
82-
defer func() {
83-
err := remote.TeardownDriverAndClient(c)
84-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
85-
}()
8672
}
8773
if len(zoneToContext) == 2 {
8874
break

test/e2e/tests/setup_e2e_test.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535
runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")
3636
deleteInstances = flag.Bool("delete-instances", false, "Delete the instances after tests run")
3737

38-
testInstances = []*remote.InstanceInfo{}
38+
testContexts = []*remote.TestContext{}
3939
computeService *compute.Service
4040
betaComputeService *computebeta.Service
4141
)
@@ -73,22 +73,28 @@ var _ = BeforeSuite(func() {
7373
i, err := remote.SetupInstance(*project, zone, nodeID, *serviceAccount, computeService)
7474
Expect(err).To(BeNil())
7575

76-
testInstances = append(testInstances, i)
77-
}
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)
7881

82+
}
7983
})
8084

8185
var _ = AfterSuite(func() {
82-
/*
83-
err := node.client.CloseConn()
84-
if err != nil {
85-
Logf("Failed to close the client")
86-
} else {
87-
Logf("Closed the client")
88-
*/
89-
for _, i := range testInstances {
86+
87+
for _, tc := range testContexts {
88+
err := remote.TeardownDriverAndClient(tc)
89+
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
9090
if *deleteInstances {
91-
i.DeleteInstance()
91+
tc.Instance.DeleteInstance()
9292
}
9393
}
9494
})
95+
96+
func getRandomTestContext() *remote.TestContext {
97+
Expect(testContexts).ToNot(BeEmpty())
98+
rn := rand.Intn(len(testContexts))
99+
return testContexts[rn]
100+
}

test/e2e/tests/single_zone_e2e_test.go

+7-34
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"k8s.io/apimachinery/pkg/util/uuid"
2222
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
2323
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
24-
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
25-
remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
2624

2725
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
2826
. "github.com/onsi/ginkgo"
@@ -41,14 +39,7 @@ const (
4139
var _ = Describe("GCE PD CSI Driver", func() {
4240

4341
It("Should create->attach->stage->mount volume and check if it is writable, then unmount->unstage->detach->delete and check disk is deleted", func() {
44-
// Create new driver and client
45-
Expect(testInstances).NotTo(BeEmpty())
46-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
47-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
48-
defer func() {
49-
err := remote.TeardownDriverAndClient(testContext)
50-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
51-
}()
42+
testContext := getRandomTestContext()
5243

5344
p, z, _ := testContext.Instance.GetIdentity()
5445
client := testContext.Client
@@ -90,14 +81,8 @@ var _ = Describe("GCE PD CSI Driver", func() {
9081
})
9182

9283
It("Should create disks in correct zones when topology is specified", func() {
93-
///
94-
Expect(testInstances).NotTo(BeEmpty())
95-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
96-
Expect(err).To(BeNil(), "Failed to set up new driver and client")
97-
defer func() {
98-
err := remote.TeardownDriverAndClient(testContext)
99-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
100-
}()
84+
Expect(testContexts).ToNot(BeEmpty())
85+
testContext := getRandomTestContext()
10186

10287
p, _, _ := testContext.Instance.GetIdentity()
10388

@@ -126,14 +111,8 @@ var _ = Describe("GCE PD CSI Driver", func() {
126111
})
127112

128113
It("Should successfully create RePD in two zones in the drivers region when none are specified", func() {
129-
// Create new driver and client
130-
Expect(testInstances).NotTo(BeEmpty())
131-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
132-
Expect(err).To(BeNil(), "Failed to set up new driver and client")
133-
defer func() {
134-
err := remote.TeardownDriverAndClient(testContext)
135-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
136-
}()
114+
Expect(testContexts).ToNot(BeEmpty())
115+
testContext := getRandomTestContext()
137116

138117
controllerInstance := testContext.Instance
139118
controllerClient := testContext.Client
@@ -177,14 +156,8 @@ var _ = Describe("GCE PD CSI Driver", func() {
177156
})
178157

179158
It("Should create and delete disk with default zone", func() {
180-
// Create new driver and client
181-
Expect(testInstances).NotTo(BeEmpty())
182-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
183-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
184-
defer func() {
185-
err := remote.TeardownDriverAndClient(testContext)
186-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
187-
}()
159+
Expect(testContexts).ToNot(BeEmpty())
160+
testContext := getRandomTestContext()
188161

189162
p, z, _ := testContext.Instance.GetIdentity()
190163
client := testContext.Client

test/remote/instance.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
8888
return fmt.Errorf("Failed to create firewall rule: %v", err)
8989
}
9090

91-
// TODO(#97): Pick a better boot disk image
92-
imageURL := "projects/ml-images/global/images/family/tf-1-9"
91+
imageURL := "projects/ubuntu-os-cloud/global/images/family/ubuntu-minimal-1804-lts"
9392
inst := &compute.Instance{
9493
Name: i.name,
9594
MachineType: machineType(i.zone, ""),

0 commit comments

Comments
 (0)