-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
2 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
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,60 @@ | ||
import inngest | ||
|
||
from .base import BaseState, Case, wait_for | ||
|
||
_TEST_NAME = "function_args" | ||
|
||
|
||
class _State(BaseState): | ||
attempt: int | None = None | ||
event: inngest.Event | None = None | ||
events: list[inngest.Event] | None = None | ||
run_id: str | None = None | ||
step: inngest.Step | None = None | ||
|
||
def is_done(self) -> bool: | ||
return self.attempt is not None | ||
|
||
|
||
def create(client: inngest.Inngest, framework: str) -> Case: | ||
event_name = f"{framework}/{_TEST_NAME}" | ||
state = _State() | ||
|
||
@inngest.create_function( | ||
inngest.FunctionOpts(id=_TEST_NAME), | ||
inngest.TriggerEvent(event=event_name), | ||
) | ||
def fn( | ||
*, | ||
attempt: int, | ||
event: inngest.Event, | ||
events: list[inngest.Event], | ||
run_id: str, | ||
step: inngest.Step, | ||
) -> None: | ||
state.attempt = attempt | ||
state.event = event | ||
state.events = events | ||
state.run_id = run_id | ||
state.step = step | ||
|
||
def run_test(_self: object) -> None: | ||
client.send(inngest.Event(name=event_name)) | ||
|
||
def assertion() -> None: | ||
assert state.is_done() | ||
assert state.attempt == 0 | ||
assert isinstance(state.event, inngest.Event) | ||
assert isinstance(state.events, list) and len(state.events) == 1 | ||
assert state.run_id != "" | ||
assert isinstance(state.step, inngest.Step) | ||
|
||
wait_for(assertion) | ||
|
||
return Case( | ||
event_name=event_name, | ||
fn=fn, | ||
run_test=run_test, | ||
state=state, | ||
name=_TEST_NAME, | ||
) |
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,55 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import inngest | ||
|
||
from .base import BaseState, Case, wait_for | ||
|
||
_TEST_NAME = "sleep_until" | ||
|
||
|
||
class _State(BaseState): | ||
after_sleep: datetime | None = None | ||
before_sleep: datetime | None = None | ||
|
||
def is_done(self) -> bool: | ||
return self.after_sleep is not None and self.before_sleep is not None | ||
|
||
|
||
def create(client: inngest.Inngest, framework: str) -> Case: | ||
event_name = f"{framework}/{_TEST_NAME}" | ||
state = _State() | ||
|
||
@inngest.create_function( | ||
inngest.FunctionOpts(id=_TEST_NAME), | ||
inngest.TriggerEvent(event=event_name), | ||
) | ||
def fn(*, step: inngest.Step, **_kwargs: object) -> None: | ||
if state.before_sleep is None: | ||
state.before_sleep = datetime.now() | ||
|
||
step.sleep_until("zzz", datetime.now() + timedelta(seconds=2)) | ||
|
||
if state.after_sleep is None: | ||
state.after_sleep = datetime.now() | ||
|
||
def run_test(_self: object) -> None: | ||
client.send(inngest.Event(name=event_name)) | ||
|
||
def assertion() -> None: | ||
assert state.is_done() | ||
assert ( | ||
state.after_sleep is not None and state.before_sleep is not None | ||
) | ||
assert state.after_sleep - state.before_sleep >= timedelta( | ||
seconds=2 | ||
) | ||
|
||
wait_for(assertion) | ||
|
||
return Case( | ||
event_name=event_name, | ||
fn=fn, | ||
run_test=run_test, | ||
state=state, | ||
name=_TEST_NAME, | ||
) |