Skip to content

change XTC/TRR tests for lock file presence#5423

Merged
orbeckst merged 10 commits into
developfrom
fix-filelocktest-5382
Jul 20, 2026
Merged

change XTC/TRR tests for lock file presence#5423
orbeckst merged 10 commits into
developfrom
fix-filelocktest-5382

Conversation

@orbeckst

@orbeckst orbeckst commented Jul 11, 2026

Copy link
Copy Markdown
Member

Fixes #5382

Changes made in this Pull Request:

  • filelock >= 3.29.5 will now never remove the lockfile (avoids a race condition on POSIX): changed the correspond test (xfail for older versions of filelock)
  • filelock also apparently changed behavior on Windows: it used to leave the lock file around but now it seems to be removing it (based on the windows runners): changed the test to account for this new behavior
  • updated doc string XDRBaseReader._load_offsets to indicate that we use filelock
  • added more docs to XDR page (more details on offsets)
  • add filelock docs to intersphinx mapping

LLM / AI generated code disclosure

LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)
  • LLM/AI disclosure was updated.

Developers Certificate of Origin

I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.

- fix #5382
- filelock >= 3.29.5 will now never remove the lockfile (avoids a race condition on POSIX):
  changed the correspond test (xfail for older versions of fielock)
- updated doc string XDRBaseReader._load_offsets to indicate that we use filelock
- added more docs to XDR page (more details on offsets)
- add filelock docs to intersphinx mapping
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.86%. Comparing base (32b7808) to head (e495ba5).
⚠️ Report is 10 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5423   +/-   ##
========================================
  Coverage    93.85%   93.86%           
========================================
  Files          182      182           
  Lines        22509    22510    +1     
  Branches      3202     3202           
========================================
+ Hits         21125    21128    +3     
+ Misses         922      921    -1     
+ Partials       462      461    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@orbeckst
orbeckst force-pushed the fix-filelocktest-5382 branch from 42127e8 to 7c7724e Compare July 11, 2026 06:02
@orbeckst

Copy link
Copy Markdown
Member Author

Not sure what the linter is complaining about. Pre-commit (with black 24.10) was happy.

The feedback from linters/black is close to useless to me as it just says "2 files would be reformatted, 218 files would be left unchanged." without telling me which one. (And please don't make me read the list of 200 files that it touched to find the one that does not say "already well formatted, good job."...).

@orbeckst orbeckst changed the title change XTC/TRR tests for now persistent lock file change XTC/TRR tests for lock file presence Jul 11, 2026
@orbeckst

Copy link
Copy Markdown
Member Author

It looks as if on Win, the lock file is being removed (?!). https://dev.azure.com/mdanalysis/mdanalysis/_build/results?buildId=9343&view=logs&j=dc60759d-7bf7-580f-541c-8b624e38610f&t=c864e5cd-d904-5b0e-978b-27ea9778a5fc&l=843

_______________ TestXTCReader_offsets.test_offset_lock_created ________________
[gw1] win32 -- Python 3.11.9 C:\hostedtoolcache\windows\Python\3.11.9\x64\python.exe

self = <MDAnalysisTests.coordinates.test_xdr.TestXTCReader_offsets object at 0x00000214C33F2550>

    @pytest.mark.xfail(
        Version(filelock.__version__) < Version("3.29.5"),
        reason="unsecure version of filelock",
    )
    def test_offset_lock_created(self):
        lock_file_path = XDR.offsets_filename(self.filename, ending="lock")
    
        with filelock.FileLock(lock_file_path) as lock:
            # Lock acquired in context manager, so lock file should exist
            assert lock.is_locked
            assert os.path.exists(lock_file_path)
    
        # released lock
        assert not lock.is_locked
    
        # for filelock>=3.21.0,<3.29.5, the lockfile was deleted on POSIX, but
        # this can lead to race conditions. Secure versions of filelock keep the
        # lockfile:
>       assert os.path.exists(lock_file_path)
E       AssertionError: assert False
E        +  where False = <function exists at 0x00000214A835C220>('D:/a/1/s/testsuite/MDAnalysisTests/data\\.adk_oplsaa.xtc_offsets.lock')
E        +    where <function exists at 0x00000214A835C220> = <module 'ntpath' (frozen)>.exists
E        +      where <module 'ntpath' (frozen)> = os.path

D:\a\1\s\testsuite\MDAnalysisTests\coordinates\test_xdr.py:1070: AssertionError

@orbeckst
orbeckst requested review from IAlibay and yuxuanzhuang July 11, 2026 22:09
@read-the-docs-community

read-the-docs-community Bot commented Jul 12, 2026

Copy link
Copy Markdown

@orbeckst

Copy link
Copy Markdown
Member Author

We might want to consider switching from FileLock to SoftFileLock because the latter works on NFS, which is typical in HPC environments. See eg https://py-filelock.readthedocs.io/en/latest/concepts.html#what-filelock-doesn-t-protect-against

I am happy to postpone this decision, though, and just get this PR merged so that our CI passes reliably again.

@RMeli

RMeli commented Jul 14, 2026

Copy link
Copy Markdown
Member

The feedback from linters/black is close to useless to me as it just says "2 files would be reformatted, 218 files would be left unchanged." without telling me which one. (And please don't make me read the list of 200 files that it touched to find the one that does not say "already well formatted, good job."...).

Good point, I'll see if this can be improved.

@RMeli

RMeli commented Jul 16, 2026

Copy link
Copy Markdown
Member

Are the timeouts expected?

@RMeli

RMeli commented Jul 16, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@IAlibay

IAlibay commented Jul 17, 2026

Copy link
Copy Markdown
Member

Are the timeouts expected?

Seems like a consistent failure with the IMD tests, which is odd given that it's meant to all be accessing localhost only.

bitflicker64 added a commit to bitflicker64/mdanalysis that referenced this pull request Jul 19, 2026
Upstream jobs only run when github.repository == MDAnalysis/mdanalysis.
Allow bitflicker64/mdanalysis so this fork can exercise the MDAnalysis#5423 port.

- Open linter + GH Actions CI job gates to this fork
- Add focused fork-verify-filelock workflow for offset lock tests
- Skip IMD tests on the fork only (imdclient 0.2.4 hangs; unrelated)
@bitflicker64

bitflicker64 commented Jul 19, 2026

Copy link
Copy Markdown

hey, took a look at this and ported the diff onto a fork to re-run the lock tests under current filelock

fork PR with the same XDR/test changes: bitflicker64#1

focused run on test_xdr offsets/lock tests with filelock 3.31.0 - both TestXTCReader_offsets::test_offset_lock_created and the TRR twin passed (29 related tests green):
https://github.com/bitflicker64/mdanalysis/actions/runs/29683554932

the POSIX keep-lockfile + Windows delete-on-release split matches what filelock does now (tox-dev/filelock#577 / >=3.29.5), and the xfail for older versions makes sense. docs / intersphinx / CHANGELOG look fine from here

on the remaining red CI here: the timeouts @RMeli / @IAlibay flagged look like IMD + imdclient 0.2.4 (default timeout went 5→600), not this FileLock change. suite doesn’t use pytest-flaky either - only pytest-timeout + xdist - and these read more like hard hangs that burn the full --timeout=200 than intermittent flakes. happy to dig on that separately if useful

softfilelock/NFS as a follow-up also seems right rather than blocking this

cc @orbeckst @IAlibay @yuxuanzhuang

@orbeckst

Copy link
Copy Markdown
Member Author

@IAlibay the latest 0.2.4 release of imdclient ships with an increased timeout (issue Becksteinlab/imdclient#111 , PR Becksteinlab/imdclient#120 ). I am going to quickly raise an issue.

@orbeckst

Copy link
Copy Markdown
Member Author

@yuxuanzhuang @IAlibay @RMeli could you please review this PR? The imdclient issue is being addressed in PR #5443 . Thank you.

@IAlibay IAlibay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before I even review this PR - @orbeckst this PR is in direct contradiction to our own AI policy. It's unclear to me how we should proceed.

At the very minimum, please provide details on what parts of the code being pushed is AI generated (and how).

@orbeckst

Copy link
Copy Markdown
Member Author

The yes is a mistake. It should be no — I just made a mistake when I put up the PR. I thought I had edited it but apparently hadn't. Will do now.

@IAlibay IAlibay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just the one thing, otherwise lgtm

register_plugin("pybtex.style.labels", "keylabel", KeyLabelStyle)
register_plugin("pybtex.style.formatting", "MDA", KeyStyle)

mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think splitting a URL up is beneficial to understanding. Please revert the black changeand add a fmt: skip?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, can do; the linter was unhappy with the original long line. I hadn’t considered locally exempting format checks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed — and now the CI is all 💚

@yuxuanzhuang yuxuanzhuang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@orbeckst
orbeckst force-pushed the fix-filelocktest-5382 branch from 4e089e6 to dd0636a Compare July 20, 2026 16:56
- exempt from black
- exempt from flake8
- shortened other offending lines
@orbeckst
orbeckst force-pushed the fix-filelocktest-5382 branch from dd0636a to e495ba5 Compare July 20, 2026 16:57
@orbeckst orbeckst self-assigned this Jul 20, 2026
@orbeckst
orbeckst merged commit 0803d88 into develop Jul 20, 2026
30 checks passed
@orbeckst
orbeckst deleted the fix-filelocktest-5382 branch July 20, 2026 17:55
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.

TestXTCReader_offsets.test_offset_lock_created and TestTRRReader_offsets.test_offset_lock_created always fail

5 participants