Skip to content

Commit

Permalink
LB-620: Fix a test case that fails due to asynchronous action and ins…
Browse files Browse the repository at this point in the history
…ufficient time for processing.
  • Loading branch information
ykchong45 committed Mar 22, 2024
1 parent 3b41b66 commit c42f092
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions listenbrainz/tests/integration/test_settings_views.py
@@ -1,6 +1,8 @@
import json
import time

import pytest

from brainzutils import cache

import listenbrainz.db.user as db_user
Expand Down Expand Up @@ -63,6 +65,7 @@ def test_user_page_latest_listen(self):
json_response = r.json
self.assertEqual(json_response['latestListenTs'], 1618500200)

@pytest.mark.timeout(30)
def test_delete_listens(self):
"""
Test delete listens for a user
Expand Down Expand Up @@ -108,11 +111,13 @@ def test_delete_listens(self):
with self.app.app_context():
task = get_task()
self.assertIsNotNone(task)
self.assertEquals(task.user_id, self.user["id"])
self.assertEquals(task.task, "delete_listens")
self.assertEqual(task.user_id, self.user["id"])
self.assertEqual(task.task, "delete_listens")

# wait for background tasks to be processed, with timeout function decorator
while get_task():
time.sleep(1)

# wait for background tasks to be processed
time.sleep(5)

# check that listens have been successfully deleted
resp = self.client.get(self.custom_url_for('api_v1.get_listen_count', user_name=self.user['musicbrainz_id']))
Expand Down
1 change: 1 addition & 0 deletions requirements_development.txt
Expand Up @@ -2,6 +2,7 @@ coverage==6.3.2
flask-shell-ipython==0.5.1
freezegun==1.2.0
pytest==7.1.0
pytest-timeout==2.3.1
pytest-cov==3.0.0
requests-mock==1.9.3
pytest-subtests==0.8.0

0 comments on commit c42f092

Please sign in to comment.