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(test): avoid racy reader vs writer contender in test_rw_lock #747

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

StephenSorriaux
Copy link
Member

@StephenSorriaux StephenSorriaux commented Mar 3, 2024

See test failure https://github.com/python-zk/kazoo/actions/runs/8116444130/job/22206401448?pr=744

        for contender in ("reader", "writer"):
            thread, event = contender_bits[contender]
    
            with self.condition:
                while not self.active_thread:
                    self.condition.wait()
>               assert self.active_thread == contender
E               AssertionError: assert 'writer' == 'reader'
E                 - reader
E                 + writer

kazoo/tests/test_lock.py:515: AssertionError

Why is this needed?

test_rw_lock is creating 2 threads (reader and writer) and, after being started, it is expected that reader is a contender before writer. In some busy systems (like the CI... it's always the CI!) this may not be true and lead to the test failure because writer can be a contender before reader. This commit makes sure that reader is always a contender before writer.

Proposed Changes

  • wait for reader being a contender before starting writer
  • rewrote some minimal part of the test, just because I was there

Does this PR introduce any breaking change?

No!

@StephenSorriaux StephenSorriaux marked this pull request as ready for review March 3, 2024 17:31
Copy link
Member

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Nice cleanup.

Copy link
Contributor

@ceache ceache left a comment

Choose a reason for hiding this comment

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

Looks good to me!

`test_rw_lock` is creating 2 threads (`reader` and `writer`) and, after being started, it is expected that `reader` is a contender before `writer`. In some busy systems (like the CI... it's always the CI!) this may not be true and lead to the test failure because `writer` can be a contender before `reader`. This commit makes sure that `reader` is always a contender before `writer`.
@StephenSorriaux StephenSorriaux merged commit 6540c93 into master Mar 8, 2024
28 checks passed
@StephenSorriaux StephenSorriaux deleted the fix/test_rw_lock branch March 8, 2024 19:04
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.

3 participants