From 127398342fda001651d5aaa86359f725bf6a7099 Mon Sep 17 00:00:00 2001 From: Mitch Burton Date: Mon, 9 Dec 2024 10:03:27 -0800 Subject: [PATCH] fix: get tests passing on plucky (#290) Twisted changed a little bit - it used to run `cleanFailure` on `Failure` instances in the `defer` code but no longer does in the version available in plucky (python3-twisted 24.10). This change does `cleanFailure` in the `FakeReactor` we use for some tests. This allows tests that rely on catching and flushing `Failure`s to succeed. --- landscape/client/broker/tests/test_transport.py | 10 ++-------- landscape/lib/testing.py | 10 +++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/landscape/client/broker/tests/test_transport.py b/landscape/client/broker/tests/test_transport.py index fece3b0f1..3baf74356 100644 --- a/landscape/client/broker/tests/test_transport.py +++ b/landscape/client/broker/tests/test_transport.py @@ -193,16 +193,10 @@ def test_ssl_verification_negative(self): message_api=b"X.Y", ) - def got_result(ignored): + def got_result(failure): self.assertIs(r.request, None) self.assertIs(r.content, None) - logfile_value = self.logfile.getvalue() - # pycurl error messages vary by version. - # First is for <= noble, second for > noble. - self.assertTrue( - "server certificate verification failed" in logfile_value - or "SSL certificate problem" in logfile_value, - ) + self.assertEqual(failure.value.error_code, 60) result.addErrback(got_result) return result diff --git a/landscape/lib/testing.py b/landscape/lib/testing.py index 1c13b962d..1a8163ba1 100644 --- a/landscape/lib/testing.py +++ b/landscape/lib/testing.py @@ -685,7 +685,15 @@ def fake(): # because the call might cancel it! call._data = self.call_later(seconds, fake)._data try: - f(*args, **kwargs) + deferred = f(*args, **kwargs) + + if ( + hasattr(deferred, "result") + and isinstance(deferred.result, Failure) + ): + # Required for failures to get GC'd and properly flushed. + # Twisted did this for us in versions < 24.10. + deferred.result.cleanFailure() except Exception: if call.active: self.cancel_call(call)