|
6 | 6 |
|
7 | 7 | import idom
|
8 | 8 | from idom.core.layout import Layout, LayoutEvent, LayoutUpdate
|
9 |
| -from idom.core.serve import ( |
10 |
| - VdomJsonPatch, |
11 |
| - _create_shared_view_dispatcher, |
12 |
| - create_shared_view_dispatcher, |
13 |
| - ensure_shared_view_dispatcher_future, |
14 |
| - serve_json_patch, |
15 |
| -) |
| 9 | +from idom.core.serve import VdomJsonPatch, serve_json_patch |
16 | 10 | from idom.testing import StaticEventHandler
|
17 | 11 |
|
18 | 12 |
|
@@ -102,87 +96,6 @@ async def test_dispatch():
|
102 | 96 | assert_changes_produce_expected_model(changes, expected_model)
|
103 | 97 |
|
104 | 98 |
|
105 |
| -async def test_create_shared_state_dispatcher(): |
106 |
| - events, model = make_events_and_expected_model() |
107 |
| - changes_1, send_1, recv_1 = make_send_recv_callbacks(events) |
108 |
| - changes_2, send_2, recv_2 = make_send_recv_callbacks(events) |
109 |
| - |
110 |
| - async with create_shared_view_dispatcher(Layout(Counter())) as dispatcher: |
111 |
| - dispatcher(send_1, recv_1) |
112 |
| - dispatcher(send_2, recv_2) |
113 |
| - |
114 |
| - assert_changes_produce_expected_model(changes_1, model) |
115 |
| - assert_changes_produce_expected_model(changes_2, model) |
116 |
| - |
117 |
| - |
118 |
| -async def test_ensure_shared_view_dispatcher_future(): |
119 |
| - events, model = make_events_and_expected_model() |
120 |
| - changes_1, send_1, recv_1 = make_send_recv_callbacks(events) |
121 |
| - changes_2, send_2, recv_2 = make_send_recv_callbacks(events) |
122 |
| - |
123 |
| - dispatch_future, dispatch = ensure_shared_view_dispatcher_future(Layout(Counter())) |
124 |
| - |
125 |
| - await asyncio.gather( |
126 |
| - dispatch(send_1, recv_1), |
127 |
| - dispatch(send_2, recv_2), |
128 |
| - return_exceptions=True, |
129 |
| - ) |
130 |
| - |
131 |
| - # the dispatch future should run forever, until cancelled |
132 |
| - with pytest.raises(asyncio.TimeoutError): |
133 |
| - await asyncio.wait_for(dispatch_future, timeout=1) |
134 |
| - |
135 |
| - dispatch_future.cancel() |
136 |
| - await asyncio.gather(dispatch_future, return_exceptions=True) |
137 |
| - |
138 |
| - assert_changes_produce_expected_model(changes_1, model) |
139 |
| - assert_changes_produce_expected_model(changes_2, model) |
140 |
| - |
141 |
| - |
142 |
| -async def test_private_create_shared_view_dispatcher_cleans_up_patch_queues(): |
143 |
| - """Report an issue if this test breaks |
144 |
| -
|
145 |
| - Some internals of idom.core.dispatcher may need to be changed in order to make some |
146 |
| - internal state easier to introspect. |
147 |
| -
|
148 |
| - Ideally we would just check if patch queues are getting cleaned up more directly, |
149 |
| - but without having access to that, we use some side effects to try and infer whether |
150 |
| - it happens. |
151 |
| - """ |
152 |
| - |
153 |
| - @idom.component |
154 |
| - def SomeComponent(): |
155 |
| - return idom.html.div() |
156 |
| - |
157 |
| - async def send(patch): |
158 |
| - raise idom.Stop() |
159 |
| - |
160 |
| - async def recv(): |
161 |
| - return LayoutEvent("something", []) |
162 |
| - |
163 |
| - with idom.Layout(SomeComponent()) as layout: |
164 |
| - dispatch_shared_view, push_patch = await _create_shared_view_dispatcher(layout) |
165 |
| - |
166 |
| - # Dispatch a view that should exit. After exiting its patch queue should be |
167 |
| - # cleaned up and removed. Since we only dispatched one view there should be |
168 |
| - # no patch queues. |
169 |
| - await dispatch_shared_view(send, recv) # this should stop immediately |
170 |
| - |
171 |
| - # We create a patch and check its ref count. We will check this after attempting |
172 |
| - # to push out the change. |
173 |
| - patch = VdomJsonPatch("anything", []) |
174 |
| - patch_ref_count = sys.getrefcount(patch) |
175 |
| - |
176 |
| - # We push out this change. |
177 |
| - push_patch(patch) |
178 |
| - |
179 |
| - # Because there should be no patch queues, we expect that the ref count remains |
180 |
| - # the same. If the ref count had increased, then we would know that the patch |
181 |
| - # queue has not been cleaned up and that the patch we just pushed was added to |
182 |
| - # it. |
183 |
| - assert not sys.getrefcount(patch) > patch_ref_count |
184 |
| - |
185 |
| - |
186 | 99 | async def test_dispatcher_handles_more_than_one_event_at_a_time():
|
187 | 100 | block_and_never_set = asyncio.Event()
|
188 | 101 | will_block = asyncio.Event()
|
|
0 commit comments