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

E2E Integration test environment setup #746

Merged
merged 37 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f11f10f
Add playwright to dev requirements
pavish Oct 21, 2021
226c4a6
Set base docker image to a temp custom prebuilt image with ubuntu+pyt…
pavish Oct 22, 2021
668e67c
Set container names in docker compose
pavish Oct 22, 2021
88488a0
Remove playwright from requirements file
pavish Oct 22, 2021
71817c0
Fix container name in documents and tests
pavish Oct 22, 2021
07cd5b8
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Oct 22, 2021
007f883
Github action to run e2e tests
pavish Oct 22, 2021
608e452
Sleep for 60 seconds to wait for server to be up, handle migrations
pavish Oct 22, 2021
bb6b7f0
Merge branch 'master' into integ_test_playwright_python
pavish Oct 25, 2021
3382926
Skip confirmation during db creation in github actions
pavish Oct 25, 2021
11bf8fa
Log page content to debug failing of test cases in GH workflow
pavish Oct 25, 2021
deb7f46
Record video artifacts to help debug failing tests
pavish Oct 25, 2021
5efcfe0
Merge branch 'master' into integ_test_playwright_python
pavish Oct 26, 2021
edd7854
Print DB name in installation message.
kgodey Oct 26, 2021
94e7827
Remove copy of env file.
kgodey Oct 26, 2021
2cb167b
Change cache key.
kgodey Oct 26, 2021
063cb7a
Revert "Remove copy of env file."
kgodey Oct 26, 2021
12ef48d
Update status: waiting issues automatically
kgodey Oct 30, 2021
e772b0a
Merge branch 'fix_install_script' of https://github.com/centerofci/ma…
pavish Nov 1, 2021
4c67223
Merge branch 'master' into integ_test_playwright_python
kgodey Nov 1, 2021
954901c
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 5, 2021
49eb096
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 8, 2021
a710cfc
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 8, 2021
2a07f16
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 9, 2021
64352b8
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 12, 2021
649e904
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 15, 2021
f26ca02
Reverting dockerfile changes
pavish Nov 16, 2021
6395b19
Run pytest on mathesar and db modules
pavish Nov 16, 2021
ff3e5cf
Dockerfile for integration tests
pavish Nov 16, 2021
62439b2
Use integ test dockerfile for running e2e tests
pavish Nov 16, 2021
b7657c3
Merge branch 'master' of https://github.com/centerofci/mathesar into …
pavish Nov 16, 2021
ba894a2
Specify different path for artifacts for each workflow
pavish Nov 16, 2021
04b970b
Documentation for running E2E tests
pavish Nov 16, 2021
609dd49
chore(docs): update TOC
pavish Nov 16, 2021
1db88d1
Add license of python3.9 dockerfile used as reference
pavish Nov 16, 2021
cfa53d9
Merge branch 'integ_test_playwright_python' of https://github.com/cen…
pavish Nov 16, 2021
e5bfc70
Removing conflicting step to set waiting status on issues
pavish Nov 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/run-e2e-integ-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Run E2E integration tests
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
# We only want to run on external PRs, since internal PRs are covered by "push"
# This prevents this from running twice on internal PRs
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v2

# In this step, this action saves a list of existing images,
# the cache is created without them in the post run.
# It also restores the cache if it exists.
- uses: satackey/action-docker-layer-caching@v0.0.11
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
with:
key: mathesar-docker-cache-integ-tests-{hash}
restore-keys: |
mathesar-docker-cache-e2e-tests-

- name: Copy env file
run: cp .env.example .env

- name: Use integ test dockerfile
run: rm Dockerfile && mv Dockerfile.integ-tests Dockerfile

# The code is checked out under uid 1001 - reset this to 1000 for the
# container to run tests successfully
- name: Fix permissions
run: sudo chown -R 1000:1000 .

- name: Build the stack
run: docker-compose up --build -d

- name: Sleep for 60 seconds
run: sleep 60s
shell: bash

# TODO: This needs to be handled inside the tests
- name: Run migrations
run: docker exec mathesar_service python manage.py migrate

- name: Run type installation
run: docker exec mathesar_service python install.py --skip-confirm

- name: Run integ tests with pytest
run: docker exec mathesar_service pytest --browser chromium --browser webkit --browser firefox integration_tests/

- uses: actions/upload-artifact@v2
if: ${{ failure() || success() }}
with:
name: Recordings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the timestamp in the name of the artifact.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to upload an artifact in a job and download in another job, time stamping the name would make it hard for us to do that.

I do understand the concern where multiple workflows could overwrite the artifact. So, I've modified the action to use different paths for each workflow in ba894a2. Let me know if this looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

path: ${{ github.workspace }}/videos/
2 changes: 1 addition & 1 deletion .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: docker-compose up --build -d

- name: Run tests with pytest
run: docker exec mathesar_service pytest
run: docker exec mathesar_service pytest mathesar/ db/
8 changes: 8 additions & 0 deletions .github/workflows/update-project-on-issue-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ jobs:
cd .github/actions/project_update/
python project_update.py ${{ github.event.issue.node_id }} --status Blocked

- name: Update Waiting issues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavish This change seems like a bad merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgodey This was added in 12ef48d, which was mentioned here as harmless: #746 (comment)

There wasn't another step with the same name. Should I go ahead and remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavish it was superseded by 24e615a. I thought I had removed the older one. Please make sure that there's only one and it's the latest one (it should be setting the status to Waiting in the last line, not Blocked).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got confused and forgot that I added it in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Updated in e5bfc70

if: "${{ contains(github.event.issue.labels.*.name, 'status: waiting') }}"
env:
MATHESAR_ORG_GITHUB_TOKEN: ${{secrets.MATHESAR_ORG_GITHUB_TOKEN}}
run: |
cd .github/actions/project_update/
python project_update.py ${{ github.event.issue.node_id }} --status Blocked

- name: Update Ready issues
if: "${{ contains(github.event.issue.labels.*.name, 'status: ready') }}"
env:
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM python:3.9-buster

# Add mathesar user
ENV PYTHONUNBUFFERED=1
ENV DOCKERIZE_VERSION v0.6.1

Expand Down
131 changes: 131 additions & 0 deletions Dockerfile.integ-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
FROM buildpack-deps:focal

ARG DEBIAN_FRONTEND=noninteractive

# Install python
# Some of this is ported from docker file for python-3.9:
# https://github.com/docker-library/python/blob/33751272d8171cece37c59180c049ab77cf9c837/3.9/buster/Dockerfile

# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH

# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8

# Download node14 source
RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -

# extra dependencies (over what buildpack-deps already includes)
RUN apt-get update && apt-get install -y --no-install-recommends \
libbluetooth-dev \
tk-dev \
uuid-dev \
sudo \
nodejs \
&& rm -rf /var/lib/apt/lists/*

ENV GPG_KEY E3FF2839C048B25C084DEBE9B26995E310250568
ENV PYTHON_VERSION 3.9.8

RUN set -ex \
\
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY" \
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
&& mkdir -p /usr/src/python \
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
&& rm python.tar.xz \
\
&& cd /usr/src/python \
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
&& ./configure \
--build="$gnuArch" \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-option-checking=fatal \
--enable-shared \
--with-system-expat \
--with-system-ffi \
--without-ensurepip \
&& make -j "$(nproc)" \
&& make install \
&& rm -rf /usr/src/python \
\
&& find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \
\) -exec rm -rf '{}' + \
\
&& ldconfig \
\
&& python3 --version

# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
&& ln -s idle3 idle \
&& ln -s pydoc3 pydoc \
&& ln -s python3 python \
&& ln -s python3-config python-config

# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 21.2.4
# https://github.com/docker-library/python/issues/365
ENV PYTHON_SETUPTOOLS_VERSION 57.5.0
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/d781367b97acf0ece7e9e304bf281e99b618bf10/public/get-pip.py
ENV PYTHON_GET_PIP_SHA256 01249aa3e58ffb3e1686b7141b4e9aac4d398ef4ac3012ed9dff8dd9f685ffe0

RUN set -ex; \
\
wget -O get-pip.py "$PYTHON_GET_PIP_URL"; \
echo "$PYTHON_GET_PIP_SHA256 *get-pip.py" | sha256sum --check --strict -; \
\
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
"pip==$PYTHON_PIP_VERSION" \
"setuptools==$PYTHON_SETUPTOOLS_VERSION" \
; \
pip --version; \
\
find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' +; \
rm -f get-pip.py

ENV PYTHONUNBUFFERED=1
ENV DOCKERIZE_VERSION v0.6.1

# Install dockerize
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

RUN pip install playwright==1.16.1
RUN pip install pytest-playwright==0.2.2
RUN playwright install
RUN playwright install-deps

# Change work directory
WORKDIR /code/

COPY requirements.txt .
COPY requirements-dev.txt .

RUN pip install -r requirements.txt --force-reinstall sqlalchemy-filters
RUN pip install -r requirements-dev.txt
COPY . .

RUN sudo npm install -g npm-force-resolutions
RUN cd mathesar_ui && npm install --unsafe-perm && npm run build

EXPOSE 8000 3000 6006
37 changes: 37 additions & 0 deletions LICENSES/python-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Component: python3.9 docker image source file
Copyright: 2014 Docker, Inc
License: MIT
License Text: https://github.com/docker-library/python/blob/33751272d8171cece37c59180c049ab77cf9c837/LICENSE
Derivative files:
/Dockerfile.integ-tests

=================================
BEGIN of license
=================================

The MIT License (MIT)

Copyright (c) 2014 Docker, Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

=================================
END of license
=================================
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ We are currently in early development and hope to release an alpha version by la
- [Frontend](#frontend)
- [Linting](#linting)
- [Running tests](#running-tests)
- [E2E integration tests](#e2e-integration-tests)
- [Setting up the environment for E2E tests](#setting-up-the-environment-for-e2e-tests)
- [Running E2E tests](#running-e2e-tests)
- [Opening a shell in the container](#opening-a-shell-in-the-container)
- [Troubleshooting](#troubleshooting)
- [License](#license)
Expand Down Expand Up @@ -85,14 +88,39 @@ If you'd like to run tests before pushing, here's how you do it:

Backend tests:
```
docker exec mathesar_service pytest
docker exec mathesar_service pytest mathesar/ db/
```

Frontend tests:
```
docker exec mathesar_service bash -c "cd mathesar_ui && npm test"
```

### E2E integration tests

#### Setting up the environment for E2E tests

Running E2E integration tests requires a separate docker setup. The dockerfile for it can be found [here](Dockerfile.integ-tests).

Inorder to make use of it, you can change line 18 in docker-compose.yml:

```
# change this
dockerfile: Dockerfile

# to this
dockerfile: Dockerfile.integ-tests
```

If you are working on the frontend and would like to run integration tests regularly, you could make use of this for your default development environment setup.

#### Running E2E tests

The E2E tests require the server to be up and running. You can run the tests by executing the following command:
```
docker exec mathesar_service pytest integration_tests/
```

### Opening a shell in the container

If you need to do some work on the container that's running the code, here's how you access it:
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ services:
volumes:
- ./.volumes:/var/lib/postgresql/data
service:
build: .
build:
context: .
# Change this to Dockerfile.integ-tests to be able to run e2e integ tests
dockerfile: Dockerfile
container_name: mathesar_service
environment:
- MODE=${MODE-PRODUCTION}
Expand Down
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def install_on_db_with_key(database_key, skip_confirm):
host = DATABASES[database_key]["HOST"]
db_name = DATABASES[database_key]["NAME"]
port = DATABASES[database_key]["PORT"]
print("Installing Mathesar DB on preexisting PostgreSQL instance...")
print(f"Installing Mathesar DB {db_name} on preexisting PostgreSQL instance at host {host}...")
if skip_confirm is False:
confirmation = input(
f"Mathesar will be installed on DB {db_name} at host {host}."
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/test_base_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def test_base_page(browser):
context = browser.new_context(record_video_dir='videos/')
page = context.new_page()
page.goto('http://localhost:8000')
assert page.inner_text('h1') == 'Welcome to Mathesar!'
context.close()
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env =
D:DEBUG=False
D:SECRET_KEY=hdC7qKjaFXNBjJ4heMMlOMrP-6j1-OvZpPf87DAXyaw
D:DJANGO_DATABASE_KEY=default
D:DJANGO_DATABASE_URL=postgres://mathesar:mathesar@db:5432/mathesar_django
D:MATHESAR_DATABASES=(mathesar_db_test|postgres://mathesar:mathesar@db:5432/mathesar_db_test)
D:DJANGO_DATABASE_URL=postgres://mathesar:mathesar@mathesar_db:5432/mathesar_django
D:MATHESAR_DATABASES=(mathesar_db_test|postgres://mathesar:mathesar@mathesar_db:5432/mathesar_db_test)
TEST=True
MODE=PRODUCTION