Skip to content

Issue 6258 - Mitigate race condition in paged_results_test.py #6433

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

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

abeisemb
Copy link
Collaborator

@abeisemb abeisemb commented Dec 4, 2024

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

@abeisemb abeisemb marked this pull request as draft December 4, 2024 18:02
@abeisemb abeisemb force-pushed the sort-logs-multi-suffix-test branch from dadec79 to f7c7fa8 Compare December 4, 2024 18:16
@abeisemb
Copy link
Collaborator Author

abeisemb commented Dec 4, 2024

Amended commit to move a helper function inside the test function for readability.

@abeisemb abeisemb marked this pull request as ready for review December 4, 2024 18:16
Copy link
Contributor

@progier389 progier389 left a comment

Choose a reason for hiding this comment

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

LGTM
FYI: rather than using indexes to extract the string you can also use directly the regular expression module. Here is an use example:

import re

str="xxxx op=123 conn=567 RESULT xxx"
result = re.search(r'(op=\d+ conn=\d+)', str)
print(result.group(1))

@vashirov
Copy link
Member

vashirov commented Dec 5, 2024

I agree with @progier389, this should be a regex.
Minor nit: in the commit message instead of "Helps fix" please use "Fixes:", see https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests

@abeisemb abeisemb force-pushed the sort-logs-multi-suffix-test branch from f7c7fa8 to e901e1b Compare December 5, 2024 12:58
@abeisemb
Copy link
Collaborator Author

abeisemb commented Dec 5, 2024

Amended commit to correct the error in the message and replace the string index function with the simpler regex solution. Full test runtime for paged_results_test.py comes in at 6 minutes 46 seconds.

@progier389
Copy link
Contributor

Looks good.

@abeisemb abeisemb force-pushed the sort-logs-multi-suffix-test branch from e901e1b to a5cc7f2 Compare December 5, 2024 16:22
@abeisemb
Copy link
Collaborator Author

abeisemb commented Dec 5, 2024

Added missing re import.

Copy link
Member

@droideck droideck left a comment

Choose a reason for hiding this comment

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

Besides that, LGTM!

@@ -1126,6 +1127,8 @@ def test_multi_suffix_search(topology_st, create_user, new_suffixes):
topology_st.standalone.restart(timeout=10)

access_log_lines = topology_st.standalone.ds_access_log.match('.*pr_cookie=.*')
# Sort access_log_lines by op number to mitigate race condition effects.
access_log_lines.sort(key=lambda x: int(re.search(r"op=(.*?) RESULT", x).group(1)))
Copy link
Member

Choose a reason for hiding this comment

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

Minor nitpick, but I think we should be as specific as possible to avoid any weird issues:

Suggested change
access_log_lines.sort(key=lambda x: int(re.search(r"op=(.*?) RESULT", x).group(1)))
access_log_lines.sort(key=lambda x: int(re.search(r"op=(\d+) RESULT", x).group(1)))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! The commit is amended now with that change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Full test runtime comes in at 7 minutes 2 seconds.

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value.
This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Fixes: 389ds#6258
@abeisemb abeisemb force-pushed the sort-logs-multi-suffix-test branch from a5cc7f2 to 2848e3e Compare December 6, 2024 20:11
@progier389 progier389 merged commit c1c46c1 into 389ds:main Dec 9, 2024
197 of 199 checks passed
mmatsuya pushed a commit to mmatsuya/389-ds-base that referenced this pull request Feb 4, 2025
…6433)

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: 389ds#6258

Reviewed by: @droideck , @progier389 (Thanks!)
mmatsuya pushed a commit to mmatsuya/389-ds-base that referenced this pull request Feb 4, 2025
…6433)

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: 389ds#6258

Reviewed by: @droideck , @progier389 (Thanks!)
mmatsuya pushed a commit to mmatsuya/389-ds-base that referenced this pull request Feb 4, 2025
…6433)

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: 389ds#6258

Reviewed by: @droideck , @progier389 (Thanks!)
mmatsuya pushed a commit to mmatsuya/389-ds-base that referenced this pull request Feb 4, 2025
…6433)

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: 389ds#6258

Reviewed by: @droideck , @progier389 (Thanks!)
mmatsuya pushed a commit to mmatsuya/389-ds-base that referenced this pull request Feb 4, 2025
…6433)

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: 389ds#6258

Reviewed by: @droideck , @progier389 (Thanks!)
mmatsuya pushed a commit to mmatsuya/389-ds-base that referenced this pull request Feb 4, 2025
…6433)

The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: 389ds#6258

Reviewed by: @droideck , @progier389 (Thanks!)
droideck pushed a commit that referenced this pull request Feb 5, 2025
The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

Co-authored-by: Anuar Beisembayev <111912342+abeisemb@users.noreply.github.com>
droideck pushed a commit that referenced this pull request Feb 5, 2025
The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

Co-authored-by: Anuar Beisembayev <111912342+abeisemb@users.noreply.github.com>
droideck pushed a commit that referenced this pull request Feb 5, 2025
The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

Co-authored-by: Anuar Beisembayev <111912342+abeisemb@users.noreply.github.com>
droideck pushed a commit that referenced this pull request Feb 5, 2025
The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

Co-authored-by: Anuar Beisembayev <111912342+abeisemb@users.noreply.github.com>
droideck pushed a commit that referenced this pull request Feb 5, 2025
The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

Co-authored-by: Anuar Beisembayev <111912342+abeisemb@users.noreply.github.com>
droideck pushed a commit that referenced this pull request Feb 5, 2025
The regression test dirsrvtests/tests/suites/paged_results/paged_results_test.py::test_multi_suffix_search has a race condition causing it to fail due to multiple queries potentially writing their logs out of chronological order.

This failure is mitigated by sorting the retrieved access_log_lines by their "op" value. This ensures the log lines are in chronological order, as expected by the assertions at the end of test_multi_suffix_search().

Helps fix: #6258

Reviewed by: @droideck , @progier389 (Thanks!)

Co-authored-by: Anuar Beisembayev <111912342+abeisemb@users.noreply.github.com>
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.

Random failure in test_healthcheck_notes_unindexed_search and test_multi_suffix_search
4 participants