|
1 | 1 | import threading |
2 | 2 | import time |
| 3 | +from datetime import timedelta |
| 4 | + |
3 | 5 | import pytest |
4 | 6 | import httpx |
5 | 7 | import fauna |
| 8 | + |
6 | 9 | from fauna import fql |
7 | 10 | from fauna.client import Client, StreamOptions |
8 | 11 | from fauna.http.httpx_client import HTTPXClient |
@@ -74,6 +77,8 @@ def thread_fn(): |
74 | 77 | def test_error_on_stream(scoped_client): |
75 | 78 | scoped_client.query(fql("Collection.create({name: 'Product'})")) |
76 | 79 |
|
| 80 | + events = [] |
| 81 | + |
77 | 82 | def thread_fn(): |
78 | 83 | stream = scoped_client.stream(fql("Product.all().map(.foo / 0).toStream()")) |
79 | 84 |
|
@@ -166,41 +171,6 @@ def thread_fn(): |
166 | 171 | assert events == ["add", "add", "add"] |
167 | 172 |
|
168 | 173 |
|
169 | | -def test_providing_start_ts(scoped_client): |
170 | | - scoped_client.query(fql("Collection.create({name: 'Product'})")) |
171 | | - |
172 | | - stream_token = scoped_client.query(fql("Product.all().toStream()")).data |
173 | | - |
174 | | - createOne = scoped_client.query(fql("Product.create({})")) |
175 | | - createTwo = scoped_client.query(fql("Product.create({})")) |
176 | | - createThree = scoped_client.query(fql("Product.create({})")) |
177 | | - |
178 | | - events = [] |
179 | | - |
180 | | - def thread_fn(): |
181 | | - # replay excludes the ts that was passed in, it provides events for all ts after the one provided |
182 | | - stream = scoped_client.stream(stream_token, |
183 | | - StreamOptions(start_ts=createOne.txn_ts)) |
184 | | - with stream as iter: |
185 | | - for event in iter: |
186 | | - events.append(event) |
187 | | - if (len(events) == 3): |
188 | | - iter.close() |
189 | | - |
190 | | - stream_thread = threading.Thread(target=thread_fn) |
191 | | - stream_thread.start() |
192 | | - |
193 | | - # adds a delay so the thread can open the stream, |
194 | | - # otherwise we could miss some events |
195 | | - time.sleep(0.5) |
196 | | - |
197 | | - createFour = scoped_client.query(fql("Product.create({})")) |
198 | | - stream_thread.join() |
199 | | - assert events[0]["txn_ts"] == createTwo.txn_ts |
200 | | - assert events[1]["txn_ts"] == createThree.txn_ts |
201 | | - assert events[2]["txn_ts"] == createFour.txn_ts |
202 | | - |
203 | | - |
204 | 174 | @pytest.mark.xfail(reason="not currently supported by core") |
205 | 175 | def test_handle_status_events(scoped_client): |
206 | 176 | scoped_client.query(fql("Collection.create({name: 'Product'})")) |
|
0 commit comments