Skip to content

Commit 4535e58

Browse files
authored
Sleep less, test more (#338)
There are a number of tests that are using calls to sleep to achieve an effect that they could get more precisely from something else (e.g. join). Let's change these call sites so that we don't have to waste a bunch of time sleeping during our tests.
1 parent 4f3df76 commit 4535e58

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

tests/general/test_namespace.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ def test_deletion_no_throttle(db, patch_requests_no_throttle):
188188

189189
to_delete = get_accounts_to_delete(0)
190190
greenlet = gevent.spawn(delete_marked_accounts, 0, to_delete, throttle=True)
191-
gevent.sleep(5)
192-
gevent.kill(greenlet)
191+
greenlet.join()
193192

194193
alive_accounts = db.session.query(Account.id).all()
195194

@@ -214,8 +213,7 @@ def test_deletion_metric_throttle(db, patch_requests_throttle):
214213

215214
to_delete = get_accounts_to_delete(0)
216215
greenlet = gevent.spawn(delete_marked_accounts, 0, to_delete, throttle=True)
217-
gevent.sleep(5)
218-
gevent.kill(greenlet)
216+
greenlet.join()
219217

220218
alive_accounts = [acc.id for acc in db.session.query(Account).all()]
221219

@@ -241,8 +239,7 @@ def test_deletion_time_throttle(db, patch_requests_no_throttle):
241239

242240
to_delete = get_accounts_to_delete(0)
243241
greenlet = gevent.spawn(delete_marked_accounts, 0, to_delete, throttle=True)
244-
gevent.sleep(2)
245-
gevent.kill(greenlet)
242+
greenlet.join()
246243

247244
alive_accounts = [acc.id for acc in db.session.query(Account).all()]
248245

tests/imap/test_delete_handling.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ def test_renamed_label_refresh(db, default_account, thread, message,
242242
semaphore.acquire()
243243
rename_handler.start()
244244

245-
# Wait 10 secs and check that the data hasn't changed.
246-
gevent.sleep(10)
245+
gevent.sleep(0) # yield to the handler
247246

248247
labels = list(imapuid.labels)
249248
assert len(labels) == 1

tests/scheduling/test_syncback_logic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_actions_are_claimed(purge_accounts_and_actions, patched_task):
9999
service._process_log()
100100

101101
while not service.task_queue.empty():
102-
gevent.sleep(0.1)
102+
gevent.sleep(0)
103103

104104
with session_scope_by_shard_id(0) as db_session:
105105
q = db_session.query(ActionLog)

tests/security/test_smtp_ssl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_smtp_ssl_verification_bad_cert(db, bad_cert_smtp_server,
8282
api_client, patched_smtp):
8383

8484
api_client = new_api_client(db, local_smtp_account.namespace)
85-
gevent.sleep(0.2) # let SMTP daemon start up
85+
gevent.sleep(0) # let SMTP daemon start up
8686
r = api_client.post_data('/send', example_draft)
8787
assert r.status_code == 200
8888

0 commit comments

Comments
 (0)