Skip to content

Commit 0335e11

Browse files
authored
CLOUDP-88816 second deletion test (#331)
1 parent 688a1f3 commit 0335e11

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/int/project_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"net/http"
8+
"sync"
89
"time"
910

1011
. "github.com/onsi/ginkgo"
@@ -151,6 +152,74 @@ var _ = Describe("AtlasProject", func() {
151152
})
152153
})
153154

155+
Describe("Deleting the project twice", func() {
156+
It("Should Succeed", func() {
157+
By(`Creating the project`, func() {
158+
createdProject = mdbv1.DefaultProject(namespace.Name, connectionSecret.Name)
159+
Expect(k8sClient.Create(context.Background(), createdProject)).ToNot(HaveOccurred())
160+
161+
Eventually(testutil.WaitFor(k8sClient, createdProject, status.TrueCondition(status.ReadyType)),
162+
ProjectCreationTimeout, interval).Should(BeTrue())
163+
})
164+
By("Deleting the project", func() {
165+
Expect(k8sClient.Delete(context.Background(), createdProject)).To(Succeed())
166+
Eventually(checkAtlasProjectRemoved(createdProject.Status.ID)).Should(BeTrue())
167+
time.Sleep(1 * time.Minute)
168+
Expect(checkAtlasProjectRemoved(createdProject.Status.ID)()).Should(BeTrue())
169+
createdProject = nil
170+
})
171+
})
172+
})
173+
174+
Describe("Deleting the project several times", func() {
175+
// Should show that deleted project wasn't created again (depends on Atlas)
176+
It("Should Succeed", func() {
177+
const totalProject = 10
178+
var wg sync.WaitGroup
179+
wg.Add(totalProject)
180+
createdProjects := make([]*mdbv1.AtlasProject, totalProject)
181+
projectPrefix := fmt.Sprintf("project-%s", namespace.Name)
182+
183+
By("Creating global key", func() {
184+
globalConnectionSecret := buildConnectionSecret("atlas-operator-api-key")
185+
Expect(k8sClient.Create(context.Background(), &globalConnectionSecret)).To(Succeed())
186+
})
187+
188+
for i := 0; i < totalProject; i++ {
189+
go func(i int) {
190+
defer GinkgoRecover()
191+
defer wg.Done()
192+
projectName := fmt.Sprintf("%s-%v", projectPrefix, i)
193+
194+
By(fmt.Sprintf("Creating several projects: %s", projectName))
195+
createdProjects[i] = mdbv1.DefaultProject(namespace.Name, "").WithAtlasName(projectName).WithName(projectName)
196+
Expect(k8sClient.Create(context.Background(), createdProjects[i])).ShouldNot(HaveOccurred())
197+
fmt.Printf("%+v", createdProjects[i])
198+
199+
Eventually(testutil.WaitFor(k8sClient, createdProjects[i], status.TrueCondition(status.ReadyType)),
200+
"5m", "2s").Should(BeTrue())
201+
202+
By(fmt.Sprintf("Deleting the project: %s", projectName))
203+
204+
Expect(k8sClient.Delete(context.Background(), createdProjects[i])).Should(Succeed())
205+
fmt.Printf("%+v", createdProjects[i])
206+
fmt.Printf("%v=======================NAME: %s\n", i, projectName)
207+
fmt.Printf("%v=========================ID: %s\n", i, createdProjects[i].Status.ID)
208+
Eventually(checkAtlasProjectRemoved(createdProjects[i].Status.ID), 1*time.Minute, 5*time.Second).Should(BeTrue())
209+
210+
By(fmt.Sprintf("Check if project wasn't created again: %s", projectName))
211+
time.Sleep(1 * time.Minute)
212+
fmt.Printf("%+v", createdProjects[i])
213+
fmt.Printf("%v=======================NAME: %s\n", i, projectName)
214+
fmt.Printf("%v=========================ID: %s\n", i, createdProjects[i].Status.ID)
215+
Expect(checkAtlasProjectRemoved(createdProjects[i].Status.ID)()).Should(BeTrue())
216+
}(i)
217+
}
218+
wg.Wait()
219+
createdProject = nil
220+
})
221+
})
222+
154223
Describe("Updating the project", func() {
155224
It("Should Succeed", func() {
156225
By("Creating the project first")

0 commit comments

Comments
 (0)