-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds StreamOptions class + integration test
- Loading branch information
Showing
8 changed files
with
126 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .client import Client, QueryOptions | ||
from .client import Client, QueryOptions, StreamOptions | ||
from .endpoints import Endpoints | ||
from .headers import Header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import threading | ||
from datetime import timedelta | ||
|
||
import pytest | ||
|
||
from fauna import fql | ||
from fauna.client import StreamOptions | ||
|
||
|
||
def test_stream(client, a_collection): | ||
|
||
opts = StreamOptions( | ||
idle_timeout=timedelta(seconds=1), retry_on_timeout=False) | ||
|
||
def thread_fn(): | ||
stream = client.stream( | ||
fql("${coll}.all().toStream()", coll=a_collection), opts) | ||
|
||
with stream as iter: | ||
events = [evt["type"] for evt in iter] | ||
|
||
assert events == ["start", "add", "remove", "add"] | ||
|
||
stream_thread = threading.Thread(target=thread_fn) | ||
stream_thread.start() | ||
|
||
id = client.query(fql("${coll}.create({}).id", coll=a_collection)).data | ||
client.query(fql("${coll}.byId(${id})!.delete()", coll=a_collection, id=id)) | ||
client.query(fql("${coll}.create({}).id", coll=a_collection)) | ||
|
||
stream_thread.join() | ||
|
||
|
||
def test_retry_on_timeout(client, a_collection): | ||
|
||
opts = StreamOptions( | ||
idle_timeout=timedelta(seconds=0.1), retry_on_timeout=True) | ||
|
||
def thread_fn(): | ||
stream = client.stream( | ||
fql("${coll}.all().toStream()", coll=a_collection), opts) | ||
|
||
events = [] | ||
with stream as iter: | ||
for evt in iter: | ||
events.append(evt["type"]) | ||
if len(events) == 4: | ||
iter.close() | ||
|
||
assert events == ["start", "start", "start", "start"] | ||
|
||
stream_thread = threading.Thread(target=thread_fn) | ||
stream_thread.start() | ||
stream_thread.join() |