Skip to content

Commit 460029a

Browse files
committed
fix #297: Ablog is NOT safe for parallel read
1 parent c17d644 commit 460029a

File tree

9 files changed

+56
-1
lines changed

9 files changed

+56
-1
lines changed

roots/test-parallel/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extensions = ["ablog"]

roots/test-parallel/index.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test-postlist
2+
===============
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
postlist

roots/test-parallel/post1.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. post:: 2020-12-01
2+
3+
post 1
4+
=======

roots/test-parallel/post2.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. post:: 2020-12-01
2+
3+
post 2
4+
=======

roots/test-parallel/post3.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. post:: 2020-12-01
2+
3+
post 3
4+
=======

roots/test-parallel/post4.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. post:: 2020-12-01
2+
3+
post 4
4+
=======

roots/test-parallel/postlist.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
postlist
2+
==========
3+
4+
.. postlist::

src/ablog/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ def setup(app):
167167
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
168168
return {
169169
"version": __version__,
170-
"parallel_read_safe": True,
170+
"parallel_read_safe": False,
171171
"parallel_write_safe": True,
172172
}

src/ablog/tests/test_parallel.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
from subprocess import run
3+
4+
5+
def test_not_safe_for_parallel_read(rootdir: Path, tmp_path: Path):
6+
"""Ablog is NOT safe for parallel read. In such case, it doesn't collect any posts."""
7+
# https://github.com/sunpy/ablog/issues/297
8+
# Very ugly hack to change the parallel_read_safe value to True
9+
good_read_safe = '"parallel_read_safe": False'
10+
bad_read_safe = '"parallel_read_safe": True'
11+
init_py_path = Path(__file__).parent.parent / "__init__.py"
12+
assert good_read_safe in init_py_path.read_text(encoding="utf-8")
13+
bad_init_py = init_py_path.read_text().replace(good_read_safe, bad_read_safe)
14+
init_py_path.write_text(bad_init_py, encoding="utf-8")
15+
16+
# liborjelinek: I wasn't able to demonstrate the issue with the `parallel` argument to the `sphinx` fixture
17+
# @pytest.mark.sphinx("html", testroot="parallel", parallel=2)
18+
# therefore running sphinx-build externally
19+
indir = rootdir / "test-parallel"
20+
run(["sphinx-build", "-b", "html", indir.as_posix(), tmp_path.as_posix(), "-j", "auto"], check=True)
21+
22+
# And posts are not collected by Ablog...
23+
html = (tmp_path / "postlist.html").read_text(encoding="utf-8")
24+
assert "post 1" not in html
25+
assert "post 2" not in html
26+
assert "post 3" not in html
27+
assert "post 4" not in html

0 commit comments

Comments
 (0)