Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fixture order for consumer tests #898

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

jjaakola-aiven
Copy link
Contributor

@jjaakola-aiven jjaakola-aiven commented Jun 10, 2024

About this change - What it does

Consumer close can get stuck if the referenced topic is deleted from broker before.

References: #xxxxx

Why this way

Use worker ids to determine when Kafka servers can be closed.
This helps finding out which worker is stuck.
Consumer may get stuck on close if topic is deleted from broker
before close. This change should make the stuck consumers on
tests to be more rare.
@jjaakola-aiven jjaakola-aiven force-pushed the jjaakola-aiven-fix-fixture-order-for-consumer-tests branch from 204f13a to a477c0e Compare June 10, 2024 19:12
@jjaakola-aiven jjaakola-aiven changed the title Jjaakola aiven fix fixture order for consumer tests Fix fixture order for consumer tests Jun 11, 2024
@jjaakola-aiven jjaakola-aiven marked this pull request as ready for review June 11, 2024 10:07
@jjaakola-aiven jjaakola-aiven requested review from a team as code owners June 11, 2024 10:07
Comment on lines +28 to +32
def test_partitions_for(
self,
new_topic: NewTopic,
consumer: KafkaConsumer,
) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

its actually the order of the fixture that causes the problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is reaaaaally bad, I would expect this to be uninfluent. The order of parameters in a function shouldn't change the semantics of a program.
I wasn't quite liking the idea of fixture but this is much more dangerous.
Shouldn't we create a higher order fixture that gives the parameters and enforces the right order?

IMO if we need a topological sort of the fixture generation we should enforce it by definition

Copy link
Contributor

@eliax1996 eliax1996 left a comment

Choose a reason for hiding this comment

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

Its a clear improvement even if I don't really like the idea of the test being relying on the order of the input parameters.
Pragmatically this is a big improvement though

@eliax1996 eliax1996 merged commit de5d51f into main Jun 11, 2024
8 checks passed
@eliax1996 eliax1996 deleted the jjaakola-aiven-fix-fixture-order-for-consumer-tests branch June 11, 2024 10:30
Comment on lines +230 to +233
try:
yield consumer
finally:
consumer.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that this shouldn't have any impact, fixtures do not work like a context manager, and the pytest framework will resume the generator on clean-up. So the finally: here doesn't make any difference (but also doesn't hurt).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants