Advertisement
giuseppe1977

Untitled

Feb 12th, 2025
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # Uses threading to wait for daemon.run. Gentoo bug 934153
  2. # https://github.com/greenbone/ospd-openvas/pull/1026
  3. --- a/tests/messaging/test_mqtt.py
  4. +++ b/tests/messaging/test_mqtt.py
  5. @@ -3,6 +3,8 @@
  6.  #
  7.  # SPDX-License-Identifier: AGPL-3.0-or-later
  8.  
  9. +import threading
  10. +
  11.  from datetime import datetime
  12.  from uuid import UUID
  13.  
  14. @@ -88,10 +90,20 @@ class MQTTDaemonTestCase(TestCase):
  15.  
  16.      def test_run(self):
  17.          client = mock.MagicMock()
  18. +        start_event = threading.Event()
  19. +
  20. +        def side_effect():
  21. +            start_event.set()
  22. +
  23. +        client.connect.side_effect = side_effect
  24.  
  25.          daemon = MQTTDaemon(client)
  26.  
  27. -        daemon.run()
  28. +        run_thread = threading.Thread(target=daemon.run)
  29. +        run_thread.start()
  30. +
  31. +        # Wait for the daemon to start
  32. +        start_event.wait()
  33.  
  34.          client.connect.assert_called_with()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement