11/*
22Copyright 2018 Pressinfra SRL
3-
43Licensed under the Apache License, Version 2.0 (the "License");
54you may not use this file except in compliance with the License.
65You may obtain a copy of the License at
7-
86 http://www.apache.org/licenses/LICENSE-2.0
9-
107Unless required by applicable law or agreed to in writing, software
118distributed under the License is distributed on an "AS IS" BASIS,
129WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -56,6 +53,8 @@ var _ = Describe("Test cluster reconciliation queue", func() {
5653 controller = newController (stop , client , myClient , rec )
5754 backupPollingTime = 10 * time .Millisecond
5855 backupWatchTimeout = time .Second
56+ two := 2
57+ cluster .Spec .BackupScheduleJobsHistoryLimit = & two
5958
6059 })
6160
@@ -67,6 +66,7 @@ var _ = Describe("Test cluster reconciliation queue", func() {
6766 Context ("cluster with schedule backups" , func () {
6867 It ("try to register multiple times" , func () {
6968 cluster .Spec .BackupSchedule = "0 * * * *"
69+
7070 _ , err := myClient .MysqlV1alpha1 ().MysqlClusters (tutil .Namespace ).Create (cluster )
7171 Expect (err ).To (Succeed ())
7272
@@ -113,15 +113,16 @@ var _ = Describe("Test cluster reconciliation queue", func() {
113113 myClient : myClient ,
114114 BackupRunning : new (bool ),
115115 lock : new (sync.Mutex ),
116+ BackupScheduleJobsHistoryLimit : cluster .Spec .BackupScheduleJobsHistoryLimit ,
116117 }
117118
118119 go j .Run ()
119-
120120 Eventually (func () bool {
121121 j .lock .Lock () // avoid a data race
122122 defer j .lock .Unlock ()
123123 return * j .BackupRunning
124124 }).Should (Equal (true ))
125+
125126 Eventually (func () []api.MysqlBackup {
126127 bs , _ := myClient .Mysql ().MysqlBackups (j .Namespace ).List (metav1.ListOptions {})
127128 return bs .Items
@@ -139,6 +140,28 @@ var _ = Describe("Test cluster reconciliation queue", func() {
139140 return * j .BackupRunning
140141 }).Should (Equal (false ))
141142 })
143+
144+ It ("start jobs to schedule backups" , func () {
145+
146+ j := job {
147+ Name : cluster .Name ,
148+ Namespace : cluster .Namespace ,
149+ myClient : myClient ,
150+ BackupRunning : new (bool ),
151+ lock : new (sync.Mutex ),
152+ BackupScheduleJobsHistoryLimit : cluster .Spec .BackupScheduleJobsHistoryLimit ,
153+ }
154+
155+ for i := 0 ; i < * (j .BackupScheduleJobsHistoryLimit )+ 1 ; i ++ {
156+ j .Run ()
157+ }
158+
159+ Eventually (func () []api.MysqlBackup {
160+ bs , _ := myClient .Mysql ().MysqlBackups (j .Namespace ).List (metav1.ListOptions {})
161+ return bs .Items
162+ }).Should (HaveLen (* j .BackupScheduleJobsHistoryLimit ))
163+
164+ })
142165 })
143166 })
144167})
0 commit comments