File: test_e2e.py

package info (click to toggle)
python-aioxmpp 0.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 6,244 kB
  • sloc: python: 97,761; xml: 215; makefile: 155; sh: 63
file content (759 lines) | stat: -rw-r--r-- 22,794 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
########################################################################
# File name: test_e2e.py
# This file is part of: aioxmpp
#
# LICENSE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
########################################################################
import asyncio
import functools
import logging
import unittest

from datetime import timedelta

import aioxmpp.muc
import aioxmpp.im
import aioxmpp.im.p2p
import aioxmpp.im.service

from aioxmpp.utils import namespaces

from aioxmpp.testutils import (
    make_listener,
)

from aioxmpp.e2etest import (
    require_feature,
    blocking,
    blocking_timed,
    TestCase,
    skip_with_quirk,
    Quirk,
)


class TestMuc(TestCase):
    @skip_with_quirk(Quirk.BROKEN_MUC)
    @require_feature(namespaces.xep0045_muc)
    @blocking
    async def setUp(self, muc_provider):
        services = [
            aioxmpp.MUCClient,
            aioxmpp.im.p2p.Service,
            aioxmpp.im.service.ConversationService,
        ]

        self.peer = muc_provider
        self.mucjid = self.peer.replace(localpart="coven")

        self.firstwitch, self.secondwitch, self.thirdwitch = \
            await asyncio.gather(
                self.provisioner.get_connected_client(
                    services=services
                ),
                self.provisioner.get_connected_client(
                    services=services
                ),
                self.provisioner.get_connected_client(
                    services=services
                ),
            )

        logging.debug("firstwitch is %s", self.firstwitch.local_jid)
        logging.debug("secondwitch is %s", self.secondwitch.local_jid)
        logging.debug("thirdwitch is %s", self.thirdwitch.local_jid)

        # make firstwitch and secondwitch join
        firstmuc = self.firstwitch.summon(aioxmpp.MUCClient)
        self.firstroom, fut = firstmuc.join(
            self.mucjid,
            "firstwitch",
        )

        # configure room to be open (this also alleviates any locking)
        try:
            form = aioxmpp.muc.xso.ConfigurationForm.from_xso(
                await firstmuc.get_room_config(self.firstroom.jid)
            )
            form.membersonly.value = False
            await firstmuc.set_room_config(self.firstroom.jid,
                                           form.render_reply())
        except aioxmpp.errors.XMPPError:
            logging.warning(
                "failed to configure room for the tests",
                exc_info=True,
            )

        # we want firstwitch to join first so that we have a deterministic
        # owner of the muc
        await fut

        secondwitch_fut = asyncio.Future()
        def cb(member, **kwargs):
            secondwitch_fut.set_result(member)
            return True

        self.firstroom.on_join.connect(cb)

        self.secondroom, fut = self.secondwitch.summon(
            aioxmpp.MUCClient
        ).join(
            self.mucjid,
            "secondwitch",
        )

        await fut

        # we also want to wait until firstwitch sees secondwitch

        member = await secondwitch_fut
        self.assertIn(member, self.firstroom.members)

    @blocking_timed
    async def test_join(self):
        service = self.thirdwitch.summon(aioxmpp.MUCClient)

        recvd_future = asyncio.Future()

        def onjoin(occupant, **kwargs):
            if occupant.nick != "thirdwitch":
                return
            nonlocal recvd_future
            recvd_future.set_result((occupant, ))
            # we do not want to be called again
            return True

        self.firstroom.on_join.connect(onjoin)

        thirdroom, fut = service.join(self.mucjid, "thirdwitch")
        await fut

        occupant, = await recvd_future
        self.assertEqual(
            occupant.conversation_jid,
            self.mucjid.replace(resource="thirdwitch"),
        )

        self.assertIn(occupant, self.firstroom.members)

    @blocking_timed
    async def test_join_history(self):
        service = self.thirdwitch.summon(aioxmpp.MUCClient)

        recvd_future = asyncio.Future()

        def onjoin(occupant, **kwargs):
            if occupant.nick != "thirdwitch":
                return
            nonlocal recvd_future
            recvd_future.set_result((occupant, ))
            # we do not want to be called again
            return True

        self.firstroom.on_join.connect(onjoin)

        msg = aioxmpp.Message(type_=aioxmpp.MessageType.GROUPCHAT)
        msg.body[None] = "test"
        await self.firstroom.send_message(msg)

        thirdroom, fut = service.join(
            self.mucjid,
            "thirdwitch",
            history=aioxmpp.muc.xso.History(seconds=10)
        )
        await fut

        occupant, = await recvd_future
        self.assertEqual(
            occupant.conversation_jid,
            self.mucjid.replace(resource="thirdwitch"),
        )

        await asyncio.sleep(0.2)

        if thirdroom.muc_state != aioxmpp.muc.RoomState.ACTIVE:
            logging.warning(
                "this seems to be a broken server implementation. MUC is in"
                " history state after join seems to be over. Maybe it doesn’t"
                " send <subject/>? Trying to send a message to bust this..."
            )

            message_fut = asyncio.Future()

            def onmessage(*args, **kwargs):
                nonlocal message_fut
                message_fut.set_result(None)
                return True

            thirdroom.on_message.connect(onmessage)

            self.firstroom.send_message(msg)

            await message_fut

        self.assertEqual(thirdroom.muc_state,
                         aioxmpp.muc.RoomState.ACTIVE)

        self.assertIn(occupant, self.firstroom.members)

    @blocking_timed
    async def test_kick(self):
        exit_fut = asyncio.Future()
        leave_fut = asyncio.Future()

        def onexit(muc_leave_mode, muc_reason=None, **kwargs):
            nonlocal exit_fut
            exit_fut.set_result((muc_leave_mode, muc_reason))
            return True

        def onleave(occupant, muc_leave_mode, muc_reason=None, **kwargs):
            nonlocal leave_fut
            leave_fut.set_result((occupant, muc_leave_mode, muc_reason))
            return True

        self.secondroom.on_exit.connect(onexit)
        self.firstroom.on_leave.connect(onleave)

        for witch in self.firstroom.members:
            if witch.nick == "secondwitch":
                await self.firstroom.kick(witch, "Thou art no real witch")
                break
        else:
            self.assertFalse(True, "secondwitch not found in members")

        mode, reason = await exit_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.KICKED,
        )

        self.assertEqual(
            reason,
            "Thou art no real witch",
        )

        occupant, mode, reason = await leave_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.KICKED,
        )

        self.assertEqual(
            reason,
            "Thou art no real witch",
        )

    @blocking_timed
    async def test_kick_using_set_role(self):
        exit_fut = asyncio.Future()
        leave_fut = asyncio.Future()

        def onexit(muc_leave_mode, **kwargs):
            nonlocal exit_fut
            exit_fut.set_result((muc_leave_mode,))
            return True

        def onleave(occupant, muc_leave_mode, **kwargs):
            nonlocal leave_fut
            leave_fut.set_result((occupant, muc_leave_mode))
            return True

        self.secondroom.on_exit.connect(onexit)
        self.firstroom.on_leave.connect(onleave)

        await self.firstroom.muc_set_role(
            "secondwitch",
            "none",
            reason="Thou art no real witch")

        mode, = await exit_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.KICKED,
        )

        occupant, mode = await leave_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.KICKED,
        )

    @blocking_timed
    async def test_ban(self):
        exit_fut = asyncio.Future()
        leave_fut = asyncio.Future()

        def onexit(muc_leave_mode, muc_reason=None, **kwargs):
            nonlocal exit_fut
            exit_fut.set_result((muc_leave_mode, muc_reason))
            return True

        def onleave(occupant, muc_leave_mode, muc_reason=None, **kwargs):
            nonlocal leave_fut
            leave_fut.set_result((occupant, muc_leave_mode, muc_reason))
            return True

        self.secondroom.on_exit.connect(onexit)
        self.firstroom.on_leave.connect(onleave)

        for witch in self.firstroom.members:
            if witch.nick == "secondwitch":
                await self.firstroom.ban(witch, "Treason!")
                break
        else:
            self.assertFalse(True, "secondwitch not found in members")

        mode, reason = await exit_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.BANNED,
        )

        self.assertEqual(
            reason,
            "Treason!",
        )

        occupant, mode, reason = await leave_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.BANNED,
        )

        self.assertEqual(
            reason,
            "Treason!",
        )

    @blocking_timed
    async def test_ban_using_set_affiliation(self):
        exit_fut = asyncio.Future()
        leave_fut = asyncio.Future()

        def onexit(muc_leave_mode, **kwargs):
            nonlocal exit_fut
            exit_fut.set_result((muc_leave_mode,))
            return True

        def onleave(occupant, muc_leave_mode, **kwargs):
            nonlocal leave_fut
            leave_fut.set_result((occupant, muc_leave_mode))
            return True

        self.secondroom.on_exit.connect(onexit)
        self.firstroom.on_leave.connect(onleave)

        await self.firstroom.muc_set_affiliation(
            self.secondwitch.local_jid.bare(),
            "outcast",
            reason="Thou art no real witch")

        mode, = await exit_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.BANNED,
        )

        occupant, mode = await leave_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.BANNED,
        )

    @blocking_timed
    async def test_leave(self):
        exit_fut = asyncio.Future()
        leave_fut = asyncio.Future()

        def onexit(muc_leave_mode, **kwargs):
            nonlocal exit_fut
            exit_fut.set_result((muc_leave_mode,))
            return True

        def onleave(occupant, muc_leave_mode, **kwargs):
            nonlocal leave_fut
            leave_fut.set_result((occupant, muc_leave_mode))
            return True

        self.firstroom.on_leave.connect(onleave)
        self.secondroom.on_exit.connect(onexit)

        await self.secondroom.leave()

        self.assertFalse(self.secondroom.muc_active)
        self.assertFalse(self.secondroom.muc_joined)

        mode, = await exit_fut
        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.NORMAL,
        )

        occupant, mode = await leave_fut
        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.NORMAL,
        )

    @blocking_timed
    async def test_set_topic(self):
        subject_fut = asyncio.Future()

        def onsubject(member, subject, **kwargs):
            nonlocal subject_fut
            subject_fut.set_result((member, subject))
            return True

        self.secondroom.on_topic_changed.connect(onsubject)

        await self.firstroom.set_topic({None: "Wytches Brew!"})

        member, subject = await subject_fut

        self.assertEqual(
            subject.any(),
            "Wytches Brew!",
            subject,
        )

        self.assertDictEqual(
            self.secondroom.muc_subject,
            subject,
        )

        self.assertEqual(
            self.secondroom.muc_subject_setter,
            "firstwitch",
        )

    @blocking_timed
    async def test_send_tracked_message(self):
        msg_future = asyncio.Future()
        sent_future = asyncio.Future()

        def onmessage(message, member, source, **kwargs):
            nonlocal msg_future
            msg_future.set_result((message,))
            return True

        def onstatechange(state, response=None):
            if state == aioxmpp.tracking.MessageState.DELIVERED_TO_RECIPIENT:
                sent_future.set_result(None)
                return True

        self.secondroom.on_message.connect(onmessage)

        msg = aioxmpp.Message(aioxmpp.MessageType.NORMAL)
        msg.body[None] = "foo"
        token, tracker = self.firstroom.send_message_tracked(msg)
        tracker.on_state_changed.connect(onstatechange)
        await sent_future

        message, = await msg_future
        self.assertEqual(
            message.body.any(),
            "foo",
        )

    @blocking_timed
    async def test_send_message(self):
        msg_future = asyncio.Future()

        def onmessage(message, member, source, **kwargs):
            nonlocal msg_future
            msg_future.set_result((message, member,))
            return True

        self.secondroom.on_message.connect(onmessage)

        msg = aioxmpp.Message(type_=aioxmpp.MessageType.CHAT)
        msg.body.update({None: "foo"})
        await self.firstroom.send_message(msg)

        message, member, = await msg_future
        self.assertEqual(
            message.body.any(),
            "foo",
        )
        self.assertEqual(
            message.type_,
            aioxmpp.MessageType.GROUPCHAT,
        )
        self.assertEqual(
            msg.type_,
            aioxmpp.MessageType.GROUPCHAT,
        )

        self.assertCountEqual(
            [member],
            [member
             for member in self.secondroom.members
             if member.nick == "firstwitch"],
        )

    @blocking_timed
    async def test_muc_pms(self):
        firstwitch_convs = self.firstwitch.summon(
            aioxmpp.im.service.ConversationService
        )

        firstconv_future = asyncio.Future()
        first_msgs = asyncio.Queue()

        def conv_added(conversation):
            firstconv_future.set_result(conversation)

            def message(message, member, source, **kwargs):
                first_msgs.put_nowait((message, member, source))

            conversation.on_message.connect(message)
            return True

        firstwitch_convs.on_conversation_added.connect(conv_added)

        secondwitch_p2p = self.secondwitch.summon(
            aioxmpp.im.p2p.Service,
        )
        secondconv = secondwitch_p2p.get_conversation(
            self.secondroom.members[1].conversation_jid
        )

        msg = aioxmpp.Message(type_=aioxmpp.MessageType.CHAT)
        msg.body[None] = "I'll give thee a wind."

        await secondconv.send_message(msg)
        firstconv = await firstconv_future

        self.assertEqual(firstconv.members[1].conversation_jid,
                         self.firstroom.members[1].conversation_jid)

        message, member, *_ = await first_msgs.get()
        self.assertIsInstance(message, aioxmpp.Message)
        self.assertEqual(
            message.body.any(),
            msg.body.any(),
        )
        self.assertEqual(member, firstconv.members[1])

    @blocking_timed
    async def test_set_nick(self):
        self_future = asyncio.Future()
        foreign_future = asyncio.Future()

        def onnickchange(fut, occupant, old_nick, new_nick, **kwargs):
            fut.set_result((occupant, old_nick, new_nick))
            return True

        self.secondroom.on_nick_changed.connect(
            functools.partial(onnickchange, foreign_future),
        )

        self.firstroom.on_nick_changed.connect(
            functools.partial(onnickchange, self_future),
        )

        await self.firstroom.set_nick("oldhag")

        occupant, old_nick, new_nick = await self_future
        self.assertEqual(occupant, self.firstroom.me)
        self.assertEqual(old_nick, "firstwitch")
        self.assertEqual(occupant.nick, "oldhag")
        self.assertEqual(new_nick, occupant.nick)

        occupant, old_nick, new_nick = await foreign_future
        self.assertEqual(occupant.nick, "oldhag")
        self.assertEqual(old_nick, "firstwitch")
        self.assertEqual(new_nick, occupant.nick)

    @skip_with_quirk(Quirk.MUC_NO_333)
    @blocking_timed
    async def test_kick_due_to_error(self):
        exit_fut = asyncio.Future()
        leave_fut = asyncio.Future()

        def onexit(muc_leave_mode, muc_reason=None, **kwargs):
            nonlocal exit_fut
            exit_fut.set_result((muc_leave_mode, muc_reason))
            return True

        def onleave(occupant, muc_leave_mode, muc_reason=None, **kwargs):
            nonlocal leave_fut
            leave_fut.set_result((occupant, muc_leave_mode, muc_reason))
            return True

        self.secondroom.on_exit.connect(onexit)
        self.firstroom.on_leave.connect(onleave)

        error_presence = aioxmpp.Presence(
            type_=aioxmpp.PresenceType.ERROR,
            to=self.secondroom.me.conversation_jid,
        )
        error_presence.status.update({None: "Client exited"})
        await self.secondwitch.send(
            error_presence,
        )

        mode, reason = await exit_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.ERROR,
        )

        occupant, mode, reason = await leave_fut

        self.assertEqual(
            mode,
            aioxmpp.muc.LeaveMode.ERROR,
        )

    @blocking_timed
    async def test_voice_request_handling(self):
        info = await self.firstwitch.summon(
            aioxmpp.DiscoClient
        ).query_info(
            self.firstroom.jid
        )

        if aioxmpp.muc.xso.VoiceRequestForm.FORM_TYPE not in info.features:
            raise unittest.SkipTest(
                "voice request not supported"
            )

        role_future = asyncio.Future()
        request_future = asyncio.Future()

        def secondwitch_role_changed(presence, member, *,
                                     actor=None, reason=None,
                                     **kwargs):
            print("role changed")
            role_future.set_result((presence, member, actor, reason))

        def firstwitch_role_request(form, submission_future):
            request_future.set_result(form)
            form.request_allow.value = True
            submission_future.set_result(form.render_reply())

        self.secondroom.on_muc_role_changed.connect(secondwitch_role_changed)
        self.firstroom.on_muc_role_request.connect(firstwitch_role_request)

        firstmuc = self.firstwitch.summon(aioxmpp.MUCClient)

        form = aioxmpp.muc.xso.ConfigurationForm.from_xso(
            await firstmuc.get_room_config(self.firstroom.jid)
        )
        form.moderatedroom.value = True
        await firstmuc.set_room_config(self.firstroom.jid, form.render_reply())

        # ensure that secondwitch has no voice
        await self.firstroom.muc_set_role("secondwitch", "visitor")

        # wait until demotion has passed
        _, member, _, _ = await role_future
        self.assertEqual(member.role, "visitor")

        role_future = asyncio.Future()

        await self.secondroom.muc_request_voice()

        await request_future

        _, member, _, _ = await role_future
        self.assertEqual(member.role, "participant")
        self.assertEqual(self.secondroom.me.role, "participant")

    @blocking_timed
    async def test_direct_invitation(self):
        thirdmuc = self.thirdwitch.summon(aioxmpp.MUCClient)

        invite_fut = asyncio.Future()

        def on_invite(message, muc_address, inviter_address, mode, **kwargs):
            invite_fut.set_result(
                (message, muc_address, inviter_address, mode, kwargs)
            )
            return True

        thirdmuc.on_muc_invitation.connect(on_invite)

        token, _ = await self.firstroom.invite(
            self.thirdwitch.local_jid,
            text="some invitation text",
            mode=aioxmpp.im.InviteMode.DIRECT,
        )

        await token

        message, muc_address, inviter_address, mode, kwargs = await invite_fut

        self.assertEqual(kwargs["reason"], "some invitation text")
        self.assertEqual(muc_address, self.firstroom.jid)
        self.assertEqual(mode, aioxmpp.im.InviteMode.DIRECT)

    @blocking_timed
    async def test_mediated_invitation(self):
        thirdmuc = self.thirdwitch.summon(aioxmpp.MUCClient)

        invite_fut = asyncio.Future()

        def on_invite(message, muc_address, inviter_address, mode, **kwargs):
            invite_fut.set_result(
                (message, muc_address, inviter_address, mode, kwargs)
            )
            return True

        thirdmuc.on_muc_invitation.connect(on_invite)

        token, _ = await self.firstroom.invite(
            self.thirdwitch.local_jid,
            text="some invitation text",
            mode=aioxmpp.im.InviteMode.MEDIATED,
        )

        await token

        message, muc_address, inviter_address, mode, kwargs = await invite_fut

        self.assertEqual(kwargs["reason"], "some invitation text")
        self.assertEqual(muc_address, self.firstroom.jid)
        self.assertEqual(mode, aioxmpp.im.InviteMode.MEDIATED)

    @blocking_timed
    async def test_self_ping(self):
        service = self.thirdwitch.summon(aioxmpp.MUCClient)

        thirdroom, fut = service.join(self.mucjid, "thirdwitch")
        listener = make_listener(thirdroom)
        thirdroom.muc_soft_timeout = timedelta(seconds=0.1)
        thirdroom.muc_hard_timeout = timedelta(seconds=0.2)
        thirdroom.muc_ping_interval = timedelta(seconds=0.1)
        thirdroom.muc_ping_timeout = timedelta(seconds=0.2)
        await fut

        await asyncio.sleep(0.5)

        listener.on_muc_stale.assert_not_called()
        listener.on_muc_fresh.assert_not_called()