defer ctxCancel

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
Tiger Kaovilai
2023-04-16 13:33:43 -04:00
parent 84daa36efe
commit 3f4b258dee
8 changed files with 24 additions and 10 deletions
+2 -1
View File
@@ -91,7 +91,8 @@ func backup_deletion_test(useVolumeSnapshots bool) {
// runUpgradeTests runs upgrade test on the provider by kibishii.
func runBackupDeletionTests(client TestClient, veleroCfg VeleroConfig, backupName, backupLocation string,
useVolumeSnapshots bool, kibishiiDirectory string) error {
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
oneHourTimeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*60)
defer ctxCancel()
veleroCLI := veleroCfg.VeleroCLI
providerName := veleroCfg.CloudProvider
veleroNamespace := veleroCfg.VeleroNamespace
+4 -1
View File
@@ -40,6 +40,7 @@ type SyncBackups struct {
testNS string
backupName string
ctx context.Context
ctxCancel context.CancelFunc
}
func (b *SyncBackups) Init() {
@@ -47,7 +48,7 @@ func (b *SyncBackups) Init() {
UUIDgen, _ = uuid.NewRandom()
b.testNS = "sync-bsl-test-" + UUIDgen.String()
b.backupName = "sync-bsl-test-" + UUIDgen.String()
b.ctx, _ = context.WithTimeout(context.Background(), time.Minute*10)
b.ctx, b.ctxCancel = context.WithTimeout(context.Background(), time.Minute*10)
}
func BackupsSyncTest() {
@@ -79,6 +80,7 @@ func BackupsSyncTest() {
It("Backups in object storage should be synced to a new Velero successfully", func() {
test.Init()
defer test.ctxCancel()
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace %s namespace", test.testNS))
Expect(CreateNamespace(test.ctx, *VeleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", test.testNS))
@@ -119,6 +121,7 @@ func BackupsSyncTest() {
It("Deleted backups in object storage are synced to be deleted in Velero", func() {
test.Init()
defer test.ctxCancel()
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace in %s namespace", test.testNS), func() {
Expect(CreateNamespace(test.ctx, *VeleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", test.testNS))
+3 -1
View File
@@ -43,6 +43,7 @@ type TTL struct {
backupName string
restoreName string
ctx context.Context
ctxCancel context.CancelFunc
ttl time.Duration
}
@@ -52,7 +53,7 @@ func (b *TTL) Init() {
b.testNS = "backup-ttl-test-" + UUIDgen.String()
b.backupName = "backup-ttl-test-" + UUIDgen.String()
b.restoreName = "restore-ttl-test-" + UUIDgen.String()
b.ctx, _ = context.WithTimeout(context.Background(), 2*time.Hour)
b.ctx, b.ctxCancel = context.WithTimeout(context.Background(), 2*time.Hour)
b.ttl = 20 * time.Minute
}
@@ -93,6 +94,7 @@ func TTLTest() {
It("Backups in object storage should be synced to a new Velero successfully", func() {
test.Init()
defer test.ctxCancel()
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace %s namespace", test.testNS), func() {
Expect(CreateNamespace(test.ctx, client, test.testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", test.testNS))