Skip to content

Commit

Permalink
Integration tests: close DB on scheduler() fixture teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed May 21, 2021
1 parent fd3885b commit 072acd3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
21 changes: 15 additions & 6 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import asyncio
from functools import partial
from pathlib import Path
import pytest
import re
from shutil import rmtree
from typing import List, TYPE_CHECKING

import pytest

from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.pathutil import get_workflow_run_dir
from cylc.flow.wallclock import get_current_time_string
Expand Down Expand Up @@ -139,14 +138,24 @@ def flow(run_dir, test_dir):

@pytest.fixture(scope='module')
def mod_scheduler():
"""Return a scheduler object for a flow."""
return _make_scheduler
"""Return a Scheduler object for a flow.
Usage: see scheduler() below
"""
with _make_scheduler() as _scheduler:
yield _scheduler


@pytest.fixture
def scheduler():
"""Return a scheduler object for a flow."""
return _make_scheduler
"""Return a Scheduler object for a flow.
Args:
reg (str): Workflow name.
**opts (Any): Options to be passed to the Scheduler.
"""
with _make_scheduler() as _scheduler:
yield _scheduler


@pytest.fixture(scope='module')
Expand Down
27 changes: 19 additions & 8 deletions tests/integration/utils/flow_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

import asyncio
from async_timeout import timeout
from async_generator import asynccontextmanager
from contextlib import asynccontextmanager, contextmanager
import logging
from pathlib import Path
import pytest
from typing import Optional
from typing import Any, Optional
from uuid import uuid1

from cylc.flow import CYLC_LOG
Expand All @@ -54,13 +54,24 @@ def _make_flow(run_dir, test_dir, conf, name=None):
return reg


def _make_scheduler(reg, **opts):
@contextmanager
def _make_scheduler():
"""Return a scheduler object for a flow registration."""
# This allows paused_start to be overriden:
opts = {'paused_start': True, **opts}
options = RunOptions(**opts)
# create workflow
return Scheduler(reg, options)
schd: Scheduler = None # type: ignore

def __make_scheduler(reg: str, **opts: Any) -> Scheduler:
# This allows paused_start to be overriden:
opts = {'paused_start': True, **opts}
options = RunOptions(**opts)
# create workflow
nonlocal schd
schd = Scheduler(reg, options)
return schd

yield __make_scheduler
# Teardown
if hasattr(schd, 'workflow_db_mgr'):
schd.workflow_db_mgr.on_workflow_shutdown()


@asynccontextmanager
Expand Down

0 comments on commit 072acd3

Please sign in to comment.