|
2 | 2 | import gc |
3 | 3 | import random |
4 | 4 | import re |
| 5 | +from unittest.mock import patch |
5 | 6 | from weakref import finalize |
6 | 7 | from weakref import ref as weakref |
7 | 8 |
|
8 | 9 | import pytest |
9 | 10 |
|
10 | 11 | import reactpy |
11 | 12 | from reactpy import html |
12 | | -from reactpy.config import REACTPY_DEBUG_MODE |
| 13 | +from reactpy.config import REACTPY_DEBUG_MODE, REACTPY_FEATURE_CONCURRENT_RENDERING |
13 | 14 | from reactpy.core.component import component |
14 | 15 | from reactpy.core.hooks import use_effect, use_state |
15 | 16 | from reactpy.core.layout import Layout |
|
20 | 21 | assert_reactpy_did_log, |
21 | 22 | capture_reactpy_logs, |
22 | 23 | ) |
| 24 | +from reactpy.testing.common import poll |
23 | 25 | from reactpy.utils import Ref |
24 | 26 | from tests.tooling import select |
25 | 27 | from tests.tooling.aio import Event |
|
29 | 31 | from tests.tooling.select import element_exists, find_element |
30 | 32 |
|
31 | 33 |
|
| 34 | +@pytest.fixture(autouse=True, params=[True, False]) |
| 35 | +def concurrent_rendering(request): |
| 36 | + with patch.object(REACTPY_FEATURE_CONCURRENT_RENDERING, "current", request.param): |
| 37 | + yield request.param |
| 38 | + |
| 39 | + |
32 | 40 | @pytest.fixture(autouse=True) |
33 | 41 | def no_logged_errors(): |
34 | 42 | with capture_reactpy_logs() as logs: |
@@ -832,17 +840,19 @@ def some_effect(): |
832 | 840 | async with reactpy.Layout(Root()) as layout: |
833 | 841 | await layout.render() |
834 | 842 |
|
835 | | - assert effects == ["mount x"] |
| 843 | + await poll(lambda: effects).until_equals(["mount x"]) |
836 | 844 |
|
837 | 845 | set_toggle.current() |
838 | 846 | await layout.render() |
839 | 847 |
|
840 | | - assert effects == ["mount x", "unmount x", "mount y"] |
| 848 | + await poll(lambda: effects).until_equals(["mount x", "unmount x", "mount y"]) |
841 | 849 |
|
842 | 850 | set_toggle.current() |
843 | 851 | await layout.render() |
844 | 852 |
|
845 | | - assert effects == ["mount x", "unmount x", "mount y", "unmount y", "mount x"] |
| 853 | + await poll(lambda: effects).until_equals( |
| 854 | + ["mount x", "unmount x", "mount y", "unmount y", "mount x"] |
| 855 | + ) |
846 | 856 |
|
847 | 857 |
|
848 | 858 | async def test_layout_does_not_copy_element_children_by_key(): |
@@ -1253,7 +1263,10 @@ def App(): |
1253 | 1263 | assert c["attributes"]["color"] == "blue" |
1254 | 1264 |
|
1255 | 1265 |
|
1256 | | -async def test_concurrent_renders(): |
| 1266 | +async def test_concurrent_renders(concurrent_rendering): |
| 1267 | + if not concurrent_rendering: |
| 1268 | + raise pytest.skip("Concurrent rendering not enabled") |
| 1269 | + |
1257 | 1270 | child_1_hook = HookCatcher() |
1258 | 1271 | child_2_hook = HookCatcher() |
1259 | 1272 | child_1_rendered = Event() |
|
0 commit comments