From: Chris Fulljames Date: Sat, 24 May 2025 01:31:24 +0000 (-0400) Subject: Fix activity tests X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=818b29c467472ae312463462fcf3e2178f545e39;p=littlesongplace.git Fix activity tests --- diff --git a/src/littlesongplace/push_notifications.py b/src/littlesongplace/push_notifications.py index dde8900..c9b17c1 100644 --- a/src/littlesongplace/push_notifications.py +++ b/src/littlesongplace/push_notifications.py @@ -9,6 +9,8 @@ from . import auth, datadir, db bp = Blueprint("push-notifications", __name__, url_prefix="/push-notifications") +push_threads = [] + class SubscriptionSetting(enum.IntEnum): COMMENTS = 0x0001 SONGS = 0x0002 @@ -96,8 +98,14 @@ def notify(userids, title, body): thread = threading.Thread( target=_do_push, args=(current_app._get_current_object(), userids, title, body)) + push_threads.append(thread) thread.start() +def wait_all(): + push_copy = push_threads[:] + for thread in push_copy: + thread.join() + def _do_push(app, userids, title, body): data = {"title": title, "body": body} data_str = json.dumps(data) @@ -132,3 +140,5 @@ def _do_push(app, userids, title, body): if sent_notifications > 0: app.logger.info(f"Pushed {sent_notifications} notifications") + push_threads.remove(threading.current_thread()) + diff --git a/test/conftest.py b/test/conftest.py index 476a023..480ce51 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -41,6 +41,8 @@ def app(): yield lsp.app + lsp.push_notifications.wait_all() + @pytest.fixture def client(app): # Mock bcrypt to speed up tests