From 7d8926e45908af240747db6716acd4bcd30c7fc6 Mon Sep 17 00:00:00 2001
From: Tom Hubrecht <tom.hubrecht@ens.fr>
Date: Thu, 30 Jun 2022 09:39:05 +0200
Subject: [PATCH] Try to flush old messages in tests

---
 kfet/open/tests.py       | 4 +++-
 kfet/tests/test_views.py | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/kfet/open/tests.py b/kfet/open/tests.py
index 9eb07697..a30ecb99 100644
--- a/kfet/open/tests.py
+++ b/kfet/open/tests.py
@@ -283,8 +283,10 @@ class OpenKfetScenarioTest(TestCase):
             cls.r_c.login(username="team", password="team")
 
     def setUp(self):
-        # Create a channel to listen to KPsul's messages
+        # Create channels to listen to messages
         channel_layer = get_channel_layer()
+        async_to_sync(channel_layer.flush)()
+
         self.channel = async_to_sync(channel_layer.new_channel)()
         self.team_channel = async_to_sync(channel_layer.new_channel)()
 
diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py
index 39ec0aa7..153bb1b5 100644
--- a/kfet/tests/test_views.py
+++ b/kfet/tests/test_views.py
@@ -1812,6 +1812,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
 
         # Create a channel to listen to KPsul's messages
         channel_layer = get_channel_layer()
+        async_to_sync(channel_layer.flush)()
         self.channel = async_to_sync(channel_layer.new_channel)()
 
         async_to_sync(channel_layer.group_add)("kfet.kpsul", self.channel)
@@ -3240,6 +3241,9 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
 
         # Create a channel to listen to KPsul's messages
         channel_layer = get_channel_layer()
+
+        # Flush old messages
+        async_to_sync(channel_layer.flush)()
         self.channel = async_to_sync(channel_layer.new_channel)()
 
         async_to_sync(channel_layer.group_add)("kfet.kpsul", self.channel)