-
Notifications
You must be signed in to change notification settings - Fork 71
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
Fix fixture order for consumer tests #898
Conversation
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.
204f13a
to
a477c0e
Compare
def test_partitions_for( | ||
self, | ||
new_topic: NewTopic, | ||
consumer: KafkaConsumer, | ||
) -> None: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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
try: | ||
yield consumer | ||
finally: | ||
consumer.close() |
There was a problem hiding this comment.
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).
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