Skip to content

Commit 0dc025e

Browse files
authored
Update nightly org deletion tests to account for bg job (#2118)
Follow-up to #2098 Updates I missed to nightly org deletion tests following the shift to deleting orgs in a background job. I think this should be the last thing to get nightly tests passing consistently again.
1 parent 3ea20e5 commit 0dc025e

File tree

1 file changed

+90
-6
lines changed

1 file changed

+90
-6
lines changed

backend/test_nightly/test_org_deletion.py

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,38 @@ def test_delete_org_crawl_running(
141141
f"{API_PREFIX}/orgs/{non_default_org_id}", headers=admin_auth_headers
142142
)
143143
assert r.status_code == 200
144-
assert r.json()["deleted"]
144+
data = r.json()
145+
assert data["deleted"]
145146

146-
time.sleep(5)
147+
job_id = data["id"]
148+
149+
# Check that background job is launched and eventually succeeds
150+
max_attempts = 18
151+
attempts = 1
152+
while True:
153+
try:
154+
r = requests.get(
155+
f"{API_PREFIX}/orgs/all/jobs/{job_id}", headers=admin_auth_headers
156+
)
157+
assert r.status_code == 200
158+
success = r.json()["success"]
147159

160+
if success:
161+
break
162+
163+
if success is False:
164+
assert False
165+
166+
if attempts >= max_attempts:
167+
assert False
168+
169+
time.sleep(10)
170+
except:
171+
pass
172+
173+
attempts += 1
174+
175+
# Check that org was deleted
148176
r = requests.get(f"{API_PREFIX}/orgs", headers=admin_auth_headers)
149177
data = r.json()
150178
for org in data["items"]:
@@ -159,10 +187,38 @@ def test_delete_org_qa_running(
159187
f"{API_PREFIX}/orgs/{non_default_org_id}", headers=admin_auth_headers
160188
)
161189
assert r.status_code == 200
162-
assert r.json()["deleted"]
190+
data = r.json()
191+
assert data["deleted"]
163192

164-
time.sleep(5)
193+
job_id = data["id"]
194+
195+
# Check that background job is launched and eventually succeeds
196+
max_attempts = 18
197+
attempts = 1
198+
while True:
199+
try:
200+
r = requests.get(
201+
f"{API_PREFIX}/orgs/all/jobs/{job_id}", headers=admin_auth_headers
202+
)
203+
assert r.status_code == 200
204+
success = r.json()["success"]
205+
206+
if success:
207+
break
165208

209+
if success is False:
210+
assert False
211+
212+
if attempts >= max_attempts:
213+
assert False
214+
215+
time.sleep(10)
216+
except:
217+
pass
218+
219+
attempts += 1
220+
221+
# Check that org was deleted
166222
r = requests.get(f"{API_PREFIX}/orgs", headers=admin_auth_headers)
167223
data = r.json()
168224
for org in data["items"]:
@@ -177,10 +233,38 @@ def test_delete_org_profile_running(
177233
f"{API_PREFIX}/orgs/{non_default_org_id}", headers=admin_auth_headers
178234
)
179235
assert r.status_code == 200
180-
assert r.json()["deleted"]
236+
data = r.json()
237+
assert data["deleted"]
181238

182-
time.sleep(5)
239+
job_id = data["id"]
240+
241+
# Check that background job is launched and eventually succeeds
242+
max_attempts = 18
243+
attempts = 1
244+
while True:
245+
try:
246+
r = requests.get(
247+
f"{API_PREFIX}/orgs/all/jobs/{job_id}", headers=admin_auth_headers
248+
)
249+
assert r.status_code == 200
250+
success = r.json()["success"]
251+
252+
if success:
253+
break
254+
255+
if success is False:
256+
assert False
257+
258+
if attempts >= max_attempts:
259+
assert False
260+
261+
time.sleep(10)
262+
except:
263+
pass
264+
265+
attempts += 1
183266

267+
# Check that org was deleted
184268
r = requests.get(f"{API_PREFIX}/orgs", headers=admin_auth_headers)
185269
data = r.json()
186270
for org in data["items"]:

0 commit comments

Comments
 (0)