Skip to content

Commit

Permalink
fix #297: Ablog is NOT safe for parallel read
Browse files Browse the repository at this point in the history
  • Loading branch information
liborjelinek committed Nov 1, 2024
1 parent c17d644 commit d194653
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions roots/test-parallel/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions = ["ablog"]
7 changes: 7 additions & 0 deletions roots/test-parallel/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test-postlist
===============

.. toctree::
:maxdepth: 1

postlist
4 changes: 4 additions & 0 deletions roots/test-parallel/post1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. post:: 2020-12-01

post 1
=======
4 changes: 4 additions & 0 deletions roots/test-parallel/post2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. post:: 2020-12-01

post 2
=======
4 changes: 4 additions & 0 deletions roots/test-parallel/post3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. post:: 2020-12-01

post 3
=======
4 changes: 4 additions & 0 deletions roots/test-parallel/post4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. post:: 2020-12-01

post 4
=======
4 changes: 4 additions & 0 deletions roots/test-parallel/postlist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
postlist
==========

.. postlist::
2 changes: 1 addition & 1 deletion src/ablog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ def setup(app):
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
return {
"version": __version__,
"parallel_read_safe": True,
"parallel_read_safe": False,
"parallel_write_safe": True,
}
31 changes: 31 additions & 0 deletions src/ablog/tests/test_parallel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pathlib import Path
from subprocess import run


def test_not_safe_for_parallel_read(rootdir: Path):
"""Ablog is NOT safe for parallel read. In such case, it doesn't collect any posts."""
# https://github.com/sunpy/ablog/issues/297
# Very ugly hack to change the parallel_read_safe value to True
good_read_safe = '"parallel_read_safe": False'
bad_read_safe = '"parallel_read_safe": True'
init_py_path = Path(__file__).parent.parent / "__init__.py"
assert good_read_safe in init_py_path.read_text()
bad_init_py = init_py_path.read_text().replace(good_read_safe, bad_read_safe)
init_py_path.write_text(bad_init_py)

# liborjelinek: I wasn't able to demonstrate the issue with the `parallel` argument to the `sphinx` fixture
# @pytest.mark.sphinx("html", testroot="parallel", parallel=2)
# therefore running sphinx-build externally
indir = rootdir / "test-parallel"
run(["sphinx-build", "-M", "html", indir.as_posix(), "_build", "-j", "auto"], check=True)

path = indir / "_build" / "html" / "postlists.html"

run(f"sudo ls -l {path.as_posix()}", shell=True)

# And posts are not collected by Ablog...
html = path.read_text()
assert "post 1" not in html
assert "post 2" not in html
assert "post 3" not in html
assert "post 4" not in html

0 comments on commit d194653

Please sign in to comment.