]> littlesong.place Git - littlesongplace.git/commitdiff
Fix activity tests
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 24 May 2025 01:31:24 +0000 (21:31 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 24 May 2025 01:31:24 +0000 (21:31 -0400)
src/littlesongplace/push_notifications.py
test/conftest.py

index dde8900d120eeb6e0824b61dd7b6445fba6719db..c9b17c1e94438de0ba8ea6fa42a9943295a022e6 100644 (file)
@@ -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())
+
index 476a0233d6f4dd4590e9937637becc08bd753bf9..480ce51e07e01708233e9552b2b4f7582003bdc6 100644 (file)
@@ -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