Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocrd_network base integration tests #1164

Merged
merged 96 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
67d4b17
initial configs
MehmedGIT Jan 10, 2024
ed13c4b
fix rabbitmq tests
MehmedGIT Jan 10, 2024
b8bab25
add pytest-docker to req
MehmedGIT Jan 10, 2024
8ed056c
Merge branch 'master' into network-tests
MehmedGIT Jan 11, 2024
c18916e
fix conftest - move to top level
MehmedGIT Jan 11, 2024
f4c653b
fix docker file path
MehmedGIT Jan 11, 2024
9e341ba
experiment with circle ci
MehmedGIT Jan 11, 2024
9f799e1
increase timeout secs
MehmedGIT Jan 11, 2024
70b05d0
extend circle ci config
MehmedGIT Jan 11, 2024
29a6247
try different host resolution
MehmedGIT Jan 11, 2024
d4ce2b8
revert host resolution
MehmedGIT Jan 11, 2024
55ff89a
add docker network
MehmedGIT Jan 11, 2024
d383d2b
update python orb to 2.1.1 and config file to 2.1
kba Jan 12, 2024
abe5d1e
increase timeouts in wait_until_responsive
kba Jan 12, 2024
1df014a
implement make integration-test w/o pytest_docker
kba Jan 14, 2024
fd13145
ci: make integration-test
kba Jan 14, 2024
55c3e3b
network: try 0.0.0.0 over localhost
kba Jan 14, 2024
b73879b
improve local exec of integration tests
MehmedGIT Jan 15, 2024
87e21e4
remove external expectation
MehmedGIT Jan 15, 2024
0c29610
try machine executor for pyt37
MehmedGIT Jan 15, 2024
68a5c6f
revert to remote docker
MehmedGIT Jan 15, 2024
12836a8
proof-of-concept of in-docker integration tests
kba Jan 15, 2024
bea14b7
increase sleep time again X(
kba Jan 15, 2024
d0dffd0
Merge branch 'network-tests-kba' into network-tests
kba Jan 15, 2024
52064a5
change core test envs
MehmedGIT Jan 15, 2024
c96fd2e
remove constants
MehmedGIT Jan 15, 2024
0e5cf7e
add 2 base db tests
MehmedGIT Jan 15, 2024
7806211
refactor name rabbitmq tests
MehmedGIT Jan 15, 2024
18d7c7e
fix DB tests
MehmedGIT Jan 15, 2024
28debcf
do a proper update
MehmedGIT Jan 15, 2024
425c4c2
fix host for circle ci
MehmedGIT Jan 15, 2024
38a0737
fix db update test
MehmedGIT Jan 15, 2024
84656ef
wait longer time
MehmedGIT Jan 15, 2024
9afea11
move init db inside fixture
MehmedGIT Jan 15, 2024
c9a8cd3
put init_db inside the fixture
MehmedGIT Jan 15, 2024
be359f8
comment out init db
MehmedGIT Jan 15, 2024
cdf7c4a
ci: disable layer caching until we fix the outdated core_test image p…
kba Jan 15, 2024
6182a00
add sync version of db_create_workspace
MehmedGIT Jan 16, 2024
a23fe9e
add db workspace tests
MehmedGIT Jan 16, 2024
39c7e05
refactor db processing job tests
MehmedGIT Jan 16, 2024
9ee09f9
refine tests, remove unnecessary
MehmedGIT Jan 16, 2024
720e0cc
add db create for jobs
MehmedGIT Jan 16, 2024
0bf4bc9
simplify fixtures
MehmedGIT Jan 16, 2024
afcbd3f
simplify db tests
MehmedGIT Jan 16, 2024
1115e3d
extend db tests
MehmedGIT Jan 16, 2024
2d4809a
add processing server test
MehmedGIT Jan 18, 2024
c063a67
fix processing server tests
MehmedGIT Jan 19, 2024
f0654bf
fix test typo
MehmedGIT Jan 19, 2024
14a163b
add processing request test - failing
MehmedGIT Jan 19, 2024
cdb71ee
fix ocrd-dummy queue and processor name
MehmedGIT Jan 19, 2024
50c8bbe
merge master v2.61.1
MehmedGIT Jan 24, 2024
e7261f4
rm integ tests from CCI
MehmedGIT Jan 24, 2024
9640edb
add integ test yml workflow
MehmedGIT Jan 24, 2024
6ba0b4c
remove editable install check
MehmedGIT Jan 24, 2024
4bb3a54
refine integration test yml
MehmedGIT Jan 24, 2024
4bbd9dc
run only integration-test
MehmedGIT Jan 24, 2024
dd5bacd
revert unnecessary changes
MehmedGIT Jan 24, 2024
721f0af
shorten the GAct wf name
MehmedGIT Jan 24, 2024
a64b3b5
Merge branch 'master' into network-tests
MehmedGIT Jan 24, 2024
c69b334
add PS run workflow test
MehmedGIT Jan 24, 2024
6b52c21
include assets in ocrd_core_test
MehmedGIT Jan 25, 2024
cc2fca7
revert and add make test again
MehmedGIT Jan 25, 2024
da59c5f
revert previous commit
MehmedGIT Jan 25, 2024
1fe5155
temp disable mac-os
MehmedGIT Jan 25, 2024
a57b8ea
add simple wf status check
MehmedGIT Jan 25, 2024
ff5e41e
fix post -> get
MehmedGIT Jan 25, 2024
2c7bea1
add header to request
MehmedGIT Jan 25, 2024
6ed08e7
fix workflow run test
MehmedGIT Jan 26, 2024
0dcd789
enable the test
MehmedGIT Jan 26, 2024
bc160a6
fix the ocrd_logging.conf
MehmedGIT Jan 26, 2024
00b983b
use internal assets for testing
MehmedGIT Jan 26, 2024
d4a46f6
temp disable macos and u20 wfs
MehmedGIT Jan 26, 2024
ca6e7eb
fix and refactor processing test
MehmedGIT Jan 26, 2024
68dc06b
new job state - unset, refactor
MehmedGIT Jan 26, 2024
a34bf19
randomize ids
MehmedGIT Jan 26, 2024
f6ea344
clean leftovers
MehmedGIT Jan 30, 2024
be43f47
transfer method to src
MehmedGIT Jan 30, 2024
466d2e6
reuse verifiers from network
MehmedGIT Jan 30, 2024
477f37c
use prefix 'src.' for imports
MehmedGIT Jan 30, 2024
8d54093
missed src. refactor
MehmedGIT Jan 30, 2024
b89990c
activate back mac-os and u20
MehmedGIT Jan 30, 2024
0d2682d
ci/integration-test: install docker via brew for macos
kba Jan 30, 2024
5b433e7
ci/integration-test: install docker via brew for macos
kba Jan 30, 2024
0f1992e
make integration-test: DOCKER_COMPOSE overrideable
kba Jan 30, 2024
1fdcf4c
add .env and adapt
MehmedGIT Jan 30, 2024
4a9bb87
resolve conflict
MehmedGIT Jan 30, 2024
27cbb8f
ci/integration: disable macos
kba Jan 30, 2024
dfbbca3
add the .env file
MehmedGIT Jan 30, 2024
00d536a
Merge branch 'network-tests' of github.com:OCR-D/core into network-tests
MehmedGIT Jan 30, 2024
4fb485b
add separate test config
MehmedGIT Jan 30, 2024
9979b28
add suggestion of Jonas
MehmedGIT Jan 30, 2024
bbc2a8c
remove unnecessary sleep
MehmedGIT Jan 30, 2024
4bfdc3a
remove test deps
MehmedGIT Jan 30, 2024
1a6d237
clean socket files before tests
MehmedGIT Jan 30, 2024
453bed3
replace glob call available after P3.10
MehmedGIT Jan 30, 2024
824a9ab
fix socket removal
MehmedGIT Jan 30, 2024
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
version: 2.1

orbs:
python: circleci/python@2.0.3
python: circleci/python@2.1.1

jobs:

Expand Down
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
!LICENSE
!README.md
!.git
!tests
!requirements_test.txt
!.gitmodules
58 changes: 58 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Run ocrd network integration tests

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

jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
os:
- ubuntu-22.04
# - macos-latest

steps:
- uses: actions/checkout@v3
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
if [[ "${{ matrix.os }}" == "ubuntu"* ]];then
sudo apt-get -y update
sudo make deps-ubuntu
else
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 \
HOMEBREW_NO_AUTO_UPDATE=1 \
brew install imagemagick geos bash # opencv
fi
make install deps-test
- name: Install Docker on macOS
if: runner.os == 'macos'
run: |
brew install docker docker-compose
colima start
- name: Test network integration with pytest
run: |
if [[ "${{ matrix.os }}" == "macos"* ]];then
make integration-test DOCKER_COMPOSE=docker-compose
else
make integration-test
fi
22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE
FROM $BASE_IMAGE as ocrd_core_base
ARG FIXUP=echo
MAINTAINER OCR-D
ENV DEBIAN_FRONTEND noninteractive
Expand Down Expand Up @@ -33,13 +33,25 @@ RUN apt-get update && apt-get -y install software-properties-common \
curl \
sudo \
git \
&& make deps-ubuntu \
&& python3 -m venv /usr/local \
&& make deps-ubuntu
RUN python3 -m venv /usr/local \
&& hash -r \
&& make install \
&& eval $FIXUP \
&& rm -rf /build-ocrd
&& eval $FIXUP

WORKDIR /data

CMD ["/usr/local/bin/ocrd", "--help"]

FROM ocrd_core_base as ocrd_core_test
WORKDIR /build-ocrd
COPY Makefile .
RUN make assets
COPY tests ./tests
COPY .gitmodules .
COPY requirements_test.txt .
RUN pip install -r requirements_test.txt
RUN mkdir /ocrd-data && chmod 777 /ocrd-data

CMD ["yes"]
# CMD ["make", "test", "integration-test"]
joschrew marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ TESTDIR = $(CURDIR)/tests
PYTEST_ARGS = --continue-on-collection-errors
VERSION = $(shell cat VERSION)

DOCKER_COMPOSE = docker compose

SPHINX_APIDOC =

BUILD_ORDER = ocrd_utils ocrd_models ocrd_modelfactory ocrd_validators ocrd_network ocrd
Expand Down Expand Up @@ -213,9 +215,16 @@ test: assets
$(PYTHON) \
-m pytest $(PYTEST_ARGS) --durations=10\
--ignore-glob="$(TESTDIR)/**/*bench*.py" \
--ignore-glob="$(TESTDIR)/network/*.py" \
$(TESTDIR)
cd ocrd_utils ; $(PYTHON) -m pytest --continue-on-collection-errors -k TestLogging -k TestDecorators $(TESTDIR)

INTEGRATION_TEST_IN_DOCKER = docker exec core_test
integration-test:
$(DOCKER_COMPOSE) --file tests/network/docker-compose.yml up -d
-$(INTEGRATION_TEST_IN_DOCKER) pytest -k 'test_rmq or test_db or test_processing_server' -v
$(DOCKER_COMPOSE) --file tests/network/docker-compose.yml down --remove-orphans

benchmark:
$(PYTHON) -m pytest $(TESTDIR)/model/test_ocrd_mets_bench.py

Expand Down Expand Up @@ -296,7 +305,7 @@ docker-cuda: DOCKER_FILE = Dockerfile.cuda
docker-cuda: docker

docker docker-cuda:
docker build --progress=plain -f $(DOCKER_FILE) -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) .
docker build --progress=plain -f $(DOCKER_FILE) -t $(DOCKER_TAG) --target ocrd_core_base --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) .

# Build wheels and source dist and twine upload them
pypi: build
Expand Down
41 changes: 37 additions & 4 deletions src/ocrd_network/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
from .utils import call_sync


async def initiate_database(db_url: str):
async def initiate_database(db_url: str, db_name: str = 'ocrd'):
client = AsyncIOMotorClient(db_url)
await init_beanie(
database=client.get_default_database(default='ocrd'),
database=client.get_default_database(default=db_name),
document_models=[DBProcessorJob, DBWorkflowJob, DBWorkspace, DBWorkflowScript]
)


@call_sync
async def sync_initiate_database(db_url: str):
await initiate_database(db_url)
async def sync_initiate_database(db_url: str, db_name: str = 'ocrd'):
await initiate_database(db_url, db_name)


async def db_create_workspace(mets_path: str) -> DBWorkspace:
Expand All @@ -60,6 +60,11 @@ async def db_create_workspace(mets_path: str) -> DBWorkspace:
return workspace_db


@call_sync
async def sync_db_create_workspace(mets_path: str) -> DBWorkspace:
return await db_create_workspace(mets_path=mets_path)


async def db_get_workspace(workspace_id: str = None, workspace_mets_path: str = None) -> DBWorkspace:
workspace = None
if not workspace_id and not workspace_mets_path:
Expand Down Expand Up @@ -134,6 +139,15 @@ async def sync_db_update_workspace(workspace_id: str = None, workspace_mets_path
return await db_update_workspace(workspace_id=workspace_id, workspace_mets_path=workspace_mets_path, **kwargs)


async def db_create_processing_job(db_processing_job: DBProcessorJob) -> DBProcessorJob:
return await db_processing_job.insert()


@call_sync
async def sync_db_create_processing_job(db_processing_job: DBProcessorJob) -> DBProcessorJob:
return await db_create_processing_job(db_processing_job=db_processing_job)


async def db_get_processing_job(job_id: str) -> DBProcessorJob:
job = await DBProcessorJob.find_one(
DBProcessorJob.job_id == job_id)
Expand Down Expand Up @@ -180,6 +194,15 @@ async def sync_db_update_processing_job(job_id: str, **kwargs) -> DBProcessorJob
return await db_update_processing_job(job_id=job_id, **kwargs)


async def db_create_workflow_job(db_workflow_job: DBWorkflowJob) -> DBWorkflowJob:
return await db_workflow_job.insert()


@call_sync
async def sync_db_create_workflow_job(db_workflow_job: DBWorkflowJob) -> DBWorkflowJob:
return await db_create_workflow_job(db_workflow_job=db_workflow_job)


async def db_get_workflow_job(job_id: str) -> DBWorkflowJob:
job = await DBWorkflowJob.find_one(DBWorkflowJob.job_id == job_id)
if not job:
Expand All @@ -202,6 +225,15 @@ async def sync_db_get_processing_jobs(job_ids: List[str]) -> [DBProcessorJob]:
return await db_get_processing_jobs(job_ids)


async def db_create_workflow_script(db_workflow_script: DBWorkflowScript) -> DBWorkflowScript:
return await db_workflow_script.insert()


@call_sync
async def sync_db_create_workflow_script(db_workflow_script: DBWorkflowScript) -> DBWorkflowScript:
return await db_create_workflow_script(db_workflow_script=db_workflow_script)


async def db_get_workflow_script(workflow_id: str) -> DBWorkflowScript:
workflow = await DBWorkflowScript.find_one(DBWorkflowScript.workflow_id == workflow_id)
if not workflow:
Expand All @@ -221,6 +253,7 @@ async def db_find_first_workflow_script_by_content(content_hash: str) -> DBWorkf
return workflow


# TODO: Resolve the inconsistency between the async and sync versions of the same method
@call_sync
async def sync_db_find_first_workflow_script_by_content(workflow_id: str) -> DBWorkflowScript:
return await db_get_workflow_script(workflow_id)
2 changes: 2 additions & 0 deletions src/ocrd_network/models/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class StateEnum(str, Enum):
success = 'SUCCESS'
# Processing job failed
failed = 'FAILED'
# Processing job has not been assigned yet
unset = 'UNSET'


class PYJobInput(BaseModel):
Expand Down
Loading
Loading