Skip to content

Commit

Permalink
fix: get tests passing on plucky (#290)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Perfect5th authored Dec 9, 2024
1 parent 9c0a6a6 commit 1273983
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 2 additions & 8 deletions landscape/client/broker/tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion landscape/lib/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1273983

Please sign in to comment.