diff --git a/listenbrainz/db/lb_radio_artist.py b/listenbrainz/db/lb_radio_artist.py index a3fd67a39e..4ec05d1a1e 100644 --- a/listenbrainz/db/lb_radio_artist.py +++ b/listenbrainz/db/lb_radio_artist.py @@ -108,7 +108,7 @@ def lb_radio_artist(mode: str, seed_artist: str, max_similar_artists: int, num_r FROM randomize JOIN mapping.mb_artist_metadata_cache ON artist_mbid = similar_artist_mbid - WHERE rownum < {num_recordings_per_artist} + WHERE rownum <= {num_recordings_per_artist} """).format( seed_artist_mbid=Literal(uuid.UUID(seed_artist)), similar_artist_limit=Literal(100), diff --git a/listenbrainz/tests/integration/test_settings_views.py b/listenbrainz/tests/integration/test_settings_views.py index 362ebf51bd..40c688ae1f 100644 --- a/listenbrainz/tests/integration/test_settings_views.py +++ b/listenbrainz/tests/integration/test_settings_views.py @@ -111,13 +111,21 @@ def test_delete_listens(self): self.assertEquals(task.user_id, self.user["id"]) self.assertEquals(task.task, "delete_listens") - # 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'])) - self.assert200(resp) - self.assertEqual(json.loads(resp.data)['payload']['count'], 0) + # wait for background tasks to be processed -- max 30s allowed for the test to pass + ok = False + for i in range(30): + time.sleep(1) + + # 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'])) + self.assert200(resp) + if json.loads(resp.data)['payload']['count'] == 0: + continue + else: + ok = True + + if not ok: + self.assertEqual(json.loads(resp.data)['payload']['count'], 0) # check that the latest_import timestamp has been reset too resp = self.client.get(self.custom_url_for('api_v1.latest_import', user_name=self.user['musicbrainz_id']))