Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Nov 22, 2023
1 parent e2a4ffa commit b6a36a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
43 changes: 8 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
name: Test

on:
pull_request:
workflow_dispatch:
push:
branches: [master]

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
matrix:
os: ['ubuntu-latest']
os: ['macos-latest']
python: ['3.8', '3.9']
include:
- os: 'macos-latest'
python: '3.8'
n: [1, 2]
fail-fast: false
env:
PYTEST_ADDOPTS: --cov --color=yes
PYTEST_ADDOPTS: --cov --color=yes -rA --disable-warnings
FORCE_COLOR: 2

steps:
- name: Checkout
Expand All @@ -28,7 +25,7 @@ jobs:
if: startsWith(matrix.os, 'macos')
run: |
# install system deps
brew update
# brew update
brew install bash coreutils
# add GNU coreutils to the user PATH
Expand All @@ -49,34 +46,10 @@ jobs:
python-version: ${{ matrix.python }}

- name: install cylc-flow
uses: cylc/release-actions/install-cylc-components@v1
with:
cylc_flow: true
cylc_flow_opts: ''
run: pip install "cylc-flow @ git+https://github.com/cylc/[email protected]"

- name: install cylc-uiserver
run: pip install -e .[all]

- name: Style test
run: flake8

- name: Type checking
run: mypy

- name: Check changelog
if: startsWith(matrix.os, 'ubuntu')
run: towncrier build --draft

- name: Test
run: pytest

- name: Coverage report
run: |
coverage xml --ignore-errors
coverage report
- name: Codecov upload
uses: codecov/codecov-action@v3
with:
name: '${{ matrix.os }} py-${{ matrix.python }}'
fail_ci_if_error: false
run: pytest cylc/uiserver/tests/test_resolvers.py
20 changes: 17 additions & 3 deletions cylc/uiserver/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,14 @@ async def play(cls, workflows, args, workflows_mgr, log):
return response

@staticmethod
async def enqueue(stream, queue):
async def enqueue(stream, queue, log: 'Logger'):
log.error('-- ENQUEUE --')
async for line in stream:
log.warning(f':::::::::::::::::: {line.decode()}')
await queue.put(line.decode())

@classmethod
async def cat_log(cls, id_: Tokens, log, info, file=None):
async def cat_log(cls, id_: Tokens, log: 'Logger', info, file=None):
"""Calls `cat log`.
Used for log subscriptions.
Expand All @@ -392,17 +394,21 @@ async def cat_log(cls, id_: Tokens, log, info, file=None):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
log.error('-- CREATED SUBPROCESS --')
buffer: List[str] = []
queue: asyncio.Queue = asyncio.Queue()
# Farm out reading from stdout stream to a background task
# This is to get around problem where stream is not EOF until
# subprocess ends
enqueue_task = asyncio.create_task(cls.enqueue(proc.stdout, queue))
enqueue_task = asyncio.create_task(
cls.enqueue(proc.stdout, queue, log)
)
op_id = info.root_value
line_count = 0
try:
while info.context['sub_statuses'].get(op_id) != 'stop':
if queue.empty():
log.error(f'-- QUEUE EMPTY; BUFFER LEN: {len(buffer)} --')
if buffer:
yield {'lines': list(buffer)}
buffer.clear()
Expand All @@ -417,6 +423,9 @@ async def cat_log(cls, id_: Tokens, log, info, file=None):
# sleep set at 1, which matches the `tail` default interval
await asyncio.sleep(1)
else:
# log.error(
# f'-- LINE COUNT: {line_count} (max: {MAX_LINES}) --'
# )
if line_count > MAX_LINES:
yield {'lines': buffer}
yield {
Expand All @@ -427,6 +436,7 @@ async def cat_log(cls, id_: Tokens, log, info, file=None):
}
break
elif line_count == 0:
log.error('-- LINE COUNT: 0 --')
line_count += 1
yield {
'connected': True,
Expand All @@ -436,14 +446,18 @@ async def cat_log(cls, id_: Tokens, log, info, file=None):
line = await queue.get()
line_count += 1
buffer.append(line)
# log.warning(f'lInE: {line}')
log.error(f'-- BUFFER LEN: {len(buffer)} --')
if len(buffer) >= 75:
yield {'lines': list(buffer)}
buffer.clear()
await asyncio.sleep(0)
finally:
log.error('-- FINALLY --')
kill_process_tree(proc.pid)
enqueue_task.cancel()
with suppress(asyncio.CancelledError):
log.error('-- AWAITING ENQUEUE TASK --')
await enqueue_task
yield {'connected': False}

Expand Down
2 changes: 2 additions & 0 deletions cylc/uiserver/tests/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async def test_cat_log(workflow_run_dir):
info.context = {'sub_statuses': {2: "start"}}
workflow = Tokens(id_)
log = logging.getLogger(CYLC_LOG)
log.warning('Hello? You do have dinosaurs in this park, yes?')
# note - timeout tests that the cat-log process is being stopped correctly

first_response = None
Expand All @@ -98,6 +99,7 @@ async def test_cat_log(workflow_run_dir):
first_response = response
is_first = False
for line in response.get('lines', []):
log.warning(f"dEbUg: {line}")
actual += line
if "DONE" in line:
info.context['sub_statuses'][2] = 'stop'
Expand Down

0 comments on commit b6a36a6

Please sign in to comment.