Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix tests on Twisted trunk. #16528

Merged
merged 11 commits into from
Oct 25, 2023
Merged

Fix tests on Twisted trunk. #16528

merged 11 commits into from
Oct 25, 2023

Conversation

clokep
Copy link
Member

@clokep clokep commented Oct 20, 2023

Part of #16289, before fixing them we need to refactor some code first.

Twisted trunk makes a change to the TLSMemoryBIOFactory where the underlying protocol is changed from TLSMemoryBIOProtocol to BufferingTLSTransport to improve performance of TLS code (see twisted/twisted#11989). In order to properly hook up this code we need to modify some of our test code to pass the test reactor's clock into TLSMemoryBIOFactory such that the global (trial) reactor isn't used by default.

This is all rather annoying, especially when attempting to maintain compatible with older Twisted versions.

See https://github.com/twisted/twisted/pull/11996/files#diff-9d27cdf01b21540c6ef350193a9d44b88a3d2b322f3fbc08b95cdaac8fd50ed6R871-R874 for where Twisted does this in its own tests.

Comment on lines +178 to +186
# Twisted > 23.8.0 has a different API that accepts a clock.
if twisted.version <= Version("Twisted", 23, 8, 0):
return TLSMemoryBIOFactory(
connection_creator, isClient=False, wrappedFactory=factory
)
else:
return TLSMemoryBIOFactory(
connection_creator, isClient=False, wrappedFactory=factory, clock=clock # type: ignore[call-arg]
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did Twisted make a breaking change to TLSMemoryBIOFactory here, or are we just taking advantage of a newer API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@clokep clokep Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a breaking change, you don't have to provide clock, but you do if you want our tests to pass. (Otherwise it uses the trial reactor instead of the test reactor.)

tests/server.py Outdated Show resolved Hide resolved
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane, but I don't understand what exactly was failing and why on Twisted trunk. Could you spell it out for me?

@DMRobertson
Copy link
Contributor

Looks sane, but I don't understand what exactly was failing and why on Twisted trunk. Could you spell it out for me?

Oh, I think I see: twisted/twisted#11996 made speedups in twisted. But as a consequence of how they did so, their tests now need to pass in a Clock explicitly. We need to do the same.

@clokep
Copy link
Member Author

clokep commented Oct 23, 2023

Looks sane, but I don't understand what exactly was failing and why on Twisted trunk. Could you spell it out for me?

I attempted to add more info to the description, I'm not sure it is enough though.

@DMRobertson
Copy link
Contributor

Thanks! I think I was confused because the version check we added made me think there was a behaviour change in 23.8.0, rather than in twisted trunk.

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@clokep
Copy link
Member Author

clokep commented Oct 23, 2023

Thanks! I think I was confused because the version check we added made me think there was a behaviour change in 23.8.0, rather than in twisted trunk.

There's no released version so I had to do checks against the currently released version (and hope there's no 23.8.x release.... but I find that unlikely).

@clokep
Copy link
Member Author

clokep commented Oct 23, 2023

Looks like the patching is causing issues... maybe a memory leak?

@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

I kicked off a run without the patching: https://github.com/matrix-org/synapse/actions/runs/6626203043

@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

I kicked off a run without the patching: matrix-org/synapse/actions/runs/6626203043

Looks like the tests do fail without this change, I wonder if they pass on the commit before?

@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

matrix-org/synapse/actions/runs/6626962438

This passed, but fails on older Twisteds, I think we should just not patch older ones then? 🤷

# test to patch over it.
#
# Use create=True for backwards compatibilty with Twisted <= 23.8.0.
if twisted.version > Version("Twisted", 23, 8, 0):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels janky that we check > here and <= to above... as if there is at 23.8.x then it'll enable one bit of code and not the other.

It sounds like a Twisted 23.1x.0 will be out soon-ish though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use >= 23.10.0 if we want (in both places), but it'll fail until the release is out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 23.8 is fine, just a note for completeness.

@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

Tests passed here, now let's see if they pass on Twisted Trunk: https://github.com/matrix-org/synapse/actions/runs/6628632702

@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

@clokep clokep marked this pull request as ready for review October 24, 2023 18:03
@clokep clokep requested a review from a team as a code owner October 24, 2023 18:03
@clokep clokep removed the request for review from a team October 24, 2023 18:03
@clokep
Copy link
Member Author

clokep commented Oct 24, 2023

@DMRobertson Can you take another quick look?

Comment on lines -621 to +620
server_ssl_protocol = _wrap_server_factory_for_tls(
_get_test_protocol_factory()
server_ssl_protocol = wrap_server_factory_for_tls(
_get_test_protocol_factory(), self.reactor, sanlist=[b"DNS:test.com"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is passing in an explicit sanlist here a meaningful change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto below in the rest of this test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: _wrap_server_factory_for_tls defaulted to this if no sanlist argument was provided.

@clokep clokep merged commit e182dbb into develop Oct 25, 2023
35 checks passed
@clokep clokep deleted the clokep/fix-twisted-tests branch October 25, 2023 11:39
arkamar added a commit to arkamar/gentoo that referenced this pull request Nov 1, 2023
Some tests are known to fail with >twisted-23.8, see [1]

[1] matrix-org/synapse#16528

Signed-off-by: Petr Vaněk <[email protected]>
arkamar added a commit to arkamar/gentoo that referenced this pull request Nov 1, 2023
Some tests are known to fail with >twisted-23.8, see [1]

[1] matrix-org/synapse#16528

Signed-off-by: Petr Vaněk <[email protected]>
arkamar added a commit to arkamar/gentoo that referenced this pull request Nov 1, 2023
Some tests are known to fail with >twisted-23.8, see [1]

[1] matrix-org/synapse#16528

Signed-off-by: Petr Vaněk <[email protected]>
arkamar added a commit to arkamar/gentoo that referenced this pull request Nov 17, 2023
Some tests are known to fail with >twisted-23.8, see [1]

[1] matrix-org/synapse#16528

Signed-off-by: Petr Vaněk <[email protected]>
gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Nov 17, 2023
Some tests are known to fail with >twisted-23.8, see [1]

[1] matrix-org/synapse#16528

Signed-off-by: Petr Vaněk <[email protected]>
Signed-off-by: Sam James <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants