Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

jobs:
quest_test:
history_test:
runs-on: ubuntu-latest

permissions:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
env:
PYTHONPATH: ${{ github.workspace }}/src
run: |
pytest quest_test -o log_cli=true
pytest history_test -o log_cli=true

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
Expand All @@ -62,4 +62,4 @@ jobs:
env:
PYTHONPATH: ${{ github.workspace }}/src
run: |
pytest quest_test -m "integration" -o log_cli=true
pytest history_test -m "integration" -o log_cli=true
8 changes: 4 additions & 4 deletions demos/guessing_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from pathlib import Path

from quest import step, create_filesystem_manager, ainput
from history import step, create_filesystem_historian, ainput

@step
async def pick_number(lower, upper):
Expand Down Expand Up @@ -38,13 +38,13 @@ async def guessing_game():
async def main():
state = Path('state')
# state.rmdir()
async with create_filesystem_manager(
async with create_filesystem_historian(
state,
'guess_game_demo',
lambda wid: guessing_game
) as manager:
if not manager.has_workflow('demo'):
manager.start_workflow(
if not manager.has('demo'):
manager.start_soon(
'',
f'demo'
)
Expand Down
2 changes: 1 addition & 1 deletion demos/multi_guess_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from quest import client, step
from history import client, step


# TODO - write a websocket client
Expand Down
10 changes: 5 additions & 5 deletions demos/multi_guess_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import random
from pathlib import Path

from quest import (step, queue, state, identity_queue,
create_filesystem_manager, these)
from quest.server import Server
from history import (step, queue, state, identity_queue,
create_filesystem_historian, these)
from history.server import Server


@step
Expand Down Expand Up @@ -100,7 +100,7 @@ async def multi_guess():

async def main():
async with (
create_filesystem_manager(
create_filesystem_historian(
Path('state'),
'multi_guess',
lambda wid: multi_guess
Expand All @@ -113,7 +113,7 @@ async def main():
):
# TODO: Add ability to start workflows to server.py
# Start the game
manager.start_workflow('', 'demo')
manager.start_soon('', 'demo')

# Wait for it to finish
await manager.get_workflow('demo')
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 23 additions & 23 deletions quest_test/test_alias.py → history_test/test_alias.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
import pytest

from quest.manager import DuplicateAliasException
from quest import queue, alias
from .utils import timeout, create_in_memory_workflow_manager
from history.historian import DuplicateAliasException
from history import queue, alias
from .utils import timeout, create_in_memory_historian


@pytest.mark.asyncio
Expand All @@ -27,22 +27,22 @@ async def workflow():
'workflow': workflow
}

async with create_in_memory_workflow_manager(workflows) as manager:
manager.start_workflow('workflow', 'wid')
async with create_in_memory_historian(workflows) as historian:
historian.start_soon('workflow', 'wid')
await asyncio.sleep(0.1)

await manager.send_event('wid', 'data', None, 'put', '1')
await historian.send_event('wid', 'data', None, 'put', '1')
await asyncio.sleep(0.1)

assert '1' in data

await manager.send_event('the_foo', 'data', None, 'put', 'foo')
await historian.send_event('the_foo', 'data', None, 'put', 'foo')
first_pause.set()
await asyncio.sleep(0.1)

assert 'foo' in data

await manager.send_event('wid', 'data', None, 'put', '2')
await historian.send_event('wid', 'data', None, 'put', '2')
second_pause.set()
await asyncio.sleep(0.1)

Expand Down Expand Up @@ -83,21 +83,21 @@ async def workflow_b():
'workflow_b': workflow_b,
}

async with create_in_memory_workflow_manager(workflows) as manager:
async with create_in_memory_historian(workflows) as historian:
# Gather resources
manager.start_workflow('workflow_a', 'wid_a')
historian.start_soon('workflow_a', 'wid_a')
await asyncio.sleep(0.1)
manager.start_workflow('workflow_b', 'wid_b')
historian.start_soon('workflow_b', 'wid_b')
await asyncio.sleep(0.1)

first_pause.set()
await manager.send_event('wid_a', 'data', None, 'put', 'data a 1')
await manager.send_event('wid_b', 'data', None, 'put', 'data b 1')
await manager.send_event('the_foo', 'data', None, 'put', 'data foo 1')
await historian.send_event('wid_a', 'data', None, 'put', 'data a 1')
await historian.send_event('wid_b', 'data', None, 'put', 'data b 1')
await historian.send_event('the_foo', 'data', None, 'put', 'data foo 1')
await asyncio.sleep(0.1) # yield to the workflows

# now both should be waiting on second gate and no one should be the foo
assert not manager.has_workflow('the_foo')
assert not historian.has('the_foo')
assert 'data a 1' in data_a
assert 'data foo 1' in data_a
assert 'data b 1' in data_b
Expand All @@ -106,9 +106,9 @@ async def workflow_b():
await asyncio.sleep(0.1) # yield

# now workflow b should be the foo
await manager.send_event('wid_a', 'data', None, 'put', 'data a 2')
await manager.send_event('wid_b', 'data', None, 'put', 'data b 2')
await manager.send_event('the_foo', 'data', None, 'put', 'data foo 2')
await historian.send_event('wid_a', 'data', None, 'put', 'data a 2')
await historian.send_event('wid_b', 'data', None, 'put', 'data b 2')
await historian.send_event('the_foo', 'data', None, 'put', 'data foo 2')

third_pause.set()
await asyncio.sleep(0.1) # yield to the workflows
Expand Down Expand Up @@ -138,13 +138,13 @@ async def workflow_b():
'workflow_a': workflow_a,
'workflow_b': workflow_b,
}
async with create_in_memory_workflow_manager(workflows) as manager:
manager.start_workflow('workflow_a', 'wid1', delete_on_finish=False)
manager.start_workflow('workflow_b', 'wid2', delete_on_finish=False)
async with create_in_memory_historian(workflows) as historian:
historian.start_soon('workflow_a', 'wid1', delete_on_finish=False)
historian.start_soon('workflow_b', 'wid2', delete_on_finish=False)

await asyncio.sleep(0.1)
pause.set()
await asyncio.sleep(0.1) # Allow workflows to finish

result_wid1 = await manager.get_workflow_result('wid1', delete=True)
result_wid2 = await manager.get_workflow_result('wid2', delete=True)
result_wid1 = await historian.get_result('wid1', delete=True)
result_wid2 = await historian.get_result('wid2', delete=True)
48 changes: 24 additions & 24 deletions quest_test/test_basic.py → history_test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pytest

from .utils import timeout
from quest import step
from quest.historian import Historian
from quest.serializer import NoopSerializer
from history import step
from history.history import History
from history.serializer import NoopSerializer


#
Expand All @@ -26,15 +26,15 @@ async def workflow(name):
@pytest.mark.asyncio
@timeout(3)
async def test_basic_workflow():
history = []
historian = Historian(
in_memory_list = []
history = History(
'test',
workflow,
history,
in_memory_list,
serializer=NoopSerializer()
)

result = await historian.run('world')
result = await history.run('world')

assert result == 'Hello world'

Expand Down Expand Up @@ -75,25 +75,25 @@ async def longer_workflow(text):
@pytest.mark.asyncio
@timeout(3)
async def test_resume():
history = []
historian = Historian(
book = []
history = History(
'test',
longer_workflow,
history,
book,
serializer=NoopSerializer()
)

workflow = historian.run('abc')
workflow = history.run('abc')
await asyncio.sleep(0.01)
await historian.suspend()
await history.suspend()

assert history # should not be empty
assert book # should not be empty

# Allow workflow to proceed
block_workflow.set()

# Start the workflow again
result = await historian.run('abc')
result = await history.run('abc')

assert result == 'abcabcfooabcabcfoo'
assert double_calls == 2
Expand Down Expand Up @@ -134,20 +134,20 @@ async def nested_workflow(text1, text2):
@pytest.mark.asyncio
@timeout(3)
async def test_nested_steps_resume():
history = []
historian = Historian(
book = []
history = History(
'test',
nested_workflow,
history,
book,
serializer=NoopSerializer()
)

workflow = historian.run('abc', 'xyz')
workflow = history.run('abc', 'xyz')
await asyncio.sleep(0.1)
await historian.suspend()
await history.suspend()

pause.set()
result = await historian.run()
result = await history.run()

assert result == 'foofooabcbarfooxyzbar'

Expand All @@ -170,19 +170,19 @@ async def dance(start):
@pytest.mark.asyncio
@timeout(3)
async def test_resume_mid_step():
historian = Historian(
history = History(
'test',
dance,
[],
serializer=NoopSerializer()
)

wtask = historian.run(1)
wtask = history.run(1)
await asyncio.sleep(0.1)
await historian.suspend()
await history.suspend()
stop.set()

wtask = historian.run(1)
wtask = history.run(1)
await asyncio.sleep(0.1)

assert await wtask == 3
28 changes: 14 additions & 14 deletions quest_test/test_basic_tasks.py → history_test/test_basic_tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import pytest

from quest import step
from quest.historian import Historian
from quest.wrappers import task
from quest.serializer import NoopSerializer
from history import step
from history.history import History
from history.wrappers import task
from history.serializer import NoopSerializer
from .utils import timeout

counters = {}
Expand Down Expand Up @@ -43,18 +43,18 @@ async def test_basic_tasks():
counters['basic_tasks'] = 0
pauses['basic_tasks'] = asyncio.Event()

history = []
historian = Historian(
book = []
history = History(
'test',
sub_task_workflow,
history,
book,
serializer=NoopSerializer()
)

# Don't pause
pauses['basic_tasks'].set()

result = await historian.run('abc', 'xyz', 'basic_tasks')
result = await history.run('abc', 'xyz', 'basic_tasks')

assert counters['basic_tasks'] == 4
assert result == 'foofooabcbarbarfoofooxyzbarbar'
Expand All @@ -67,25 +67,25 @@ async def test_basic_tasks_resume():
counters['tasks_resume'] = 0
pauses['tasks_resume'] = asyncio.Event()

history = []
historian = Historian(
book = []
history = History(
'test',
sub_task_workflow,
history,
book,
serializer=NoopSerializer()
)

# Will run and block on the event
workflow = historian.run('abc', 'xyz', 'tasks_resume')
workflow = history.run('abc', 'xyz', 'tasks_resume')
await asyncio.sleep(0.1)
await historian.suspend()
await history.suspend()

# Both subtasks should have run the first foobar
assert counters['tasks_resume'] == 2

# Don't pause this time
pauses['tasks_resume'].set()
result = await historian.run()
result = await history.run()

assert counters['tasks_resume'] == 4
assert result == 'foofooabcbarbarfoofooxyzbarbar'
Loading