-
Notifications
You must be signed in to change notification settings - Fork 14k
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
[tests] Helper script to run single tests #9547
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
783aa31
[tests] Helper script to run single tests
dpgaspar 663cca1
[tests] add missing license
dpgaspar 9e2d93d
[tests] add missing license
dpgaspar 843be12
[pypi] use postgres defined at the root docker-compose file
dpgaspar 963eb17
[pypi] improve README remove previous container references
dpgaspar 4a11281
[tests] name the containers
dpgaspar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# Utility script to run tests faster | ||
|
||
## Use: | ||
|
||
From the superset repo root directory: | ||
|
||
- Example run a single module, will launch (or clean relaunch) Redis and Postgres: | ||
```$bash | ||
scripts/tests/run.sh tests.charts.api_tests | ||
``` | ||
|
||
- Example run a single test, will launch (or clean relaunch) Redis and Postgres: | ||
```$bash | ||
scripts/tests/run.sh tests.charts.api_tests:ChartApiTests.test_get_charts | ||
``` | ||
|
||
- Example run a single test, without any init procedures. Init procedures include | ||
relaunching containers, db upgrade, superset init, loading example data. If your tests | ||
are idempotent, after the first run, subsequent runs are really fast | ||
```$bash | ||
scripts/tests/run.sh tests.charts.api_tests:ChartApiTests.test_get_charts --no-init | ||
``` | ||
|
||
- Same has above but using MySQL backend | ||
```$bash | ||
scripts/tests/run.sh tests.charts.api_tests:ChartApiTests.test_get_charts --no-init --mysql | ||
``` | ||
|
||
- Example for not using the "provided" containers, you have your own probably | ||
```$bash | ||
scripts/tests/run.sh tests.charts.api_tests:ChartApiTests.test_get_charts --no-docker | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
version: '2' | ||
services: | ||
redis: | ||
image: redis:3.2 | ||
ports: | ||
- 6379:6379 | ||
volumes: | ||
- redis:/data | ||
|
||
postgres: | ||
image: postgres:9 | ||
environment: | ||
POSTGRES_DB: superset | ||
POSTGRES_PASSWORD: pguserpassword | ||
POSTGRES_USER: postgresuser | ||
ports: | ||
- 5432:5432 | ||
mysql: | ||
image: mysql:5.7 | ||
environment: | ||
MYSQL_DATABASE: superset | ||
MYSQL_USER: mysqluser | ||
MYSQL_PASSWORD: mysqluserpassword | ||
MYSQL_ROOT_PASSWORD: root-password | ||
ports: | ||
- 3306:3306 | ||
networks: | ||
- default | ||
volumes: | ||
- ./mysqlconf:/etc/mysql/conf.d | ||
|
||
volumes: | ||
redis: | ||
external: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set -e | ||
|
||
function restart_docker() { | ||
docker-compose -f "${SCRIPT_DIR}"/docker-compose.yml down | ||
docker-compose -f "${SCRIPT_DIR}"/docker-compose.yml up -d --force-recreate | ||
# Bad way to wait for the db's to start | ||
sleep 5 | ||
} | ||
|
||
function test_init() { | ||
echo -------------------- | ||
echo Upgrading | ||
echo -------------------- | ||
superset db upgrade | ||
echo -------------------- | ||
echo Superset init | ||
echo -------------------- | ||
superset init | ||
echo -------------------- | ||
echo Load examples | ||
echo -------------------- | ||
nosetests tests/load_examples_test.py | ||
} | ||
|
||
|
||
SCRIPT_DIR=$(dirname "$0") | ||
|
||
if [[ "$#" -eq "0" ]] | ||
then | ||
echo "No argument suplied" | ||
echo ------------------------ | ||
echo use: | ||
echo "run.sh <test module name> [options]" | ||
echo "[options]:" | ||
echo "--mysql: Use MySQL container on tests" | ||
echo "--no-init: Dont restart docker and no db migrations, superset init and test data" | ||
echo "--no-docker: Dont restart docker" | ||
exit 1 | ||
fi | ||
|
||
export SUPERSET__SQLALCHEMY_DATABASE_URI=${SUPERSET__SQLALCHEMY_DATABASE_URI:-postgresql+psycopg2://postgresuser:pguserpassword@localhost/superset} | ||
export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.superset_test_config} | ||
RUN_INIT=1 | ||
RUN_DOCKER=1 | ||
TEST_MODULE="${1}" | ||
shift 1 | ||
|
||
PARAMS="" | ||
while (( "$#" )); do | ||
case "$1" in | ||
--mysql) | ||
export SUPERSET__SQLALCHEMY_DATABASE_URI="mysql://mysqluser:mysqluserpassword@localhost/superset?charset=utf8" | ||
shift 1 | ||
;; | ||
--no-init) | ||
RUN_INIT=0 | ||
RUN_DOCKER=0 | ||
shift 1 | ||
;; | ||
--no-docker) | ||
RUN_DOCKER=0 | ||
shift 1 | ||
;; | ||
--) # end argument parsing | ||
shift | ||
break | ||
;; | ||
--*) # unsupported flags | ||
echo "Error: Unsupported flag $1" >&2 | ||
exit 1 | ||
;; | ||
*) # preserve positional arguments | ||
PARAMS="$PARAMS $1" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
echo ------------------------------------ | ||
echo DB_URI="${SUPERSET__SQLALCHEMY_DATABASE_URI}" | ||
echo Superset config module="${SUPERSET_CONFIG}" | ||
echo Run init procedures=$RUN_INIT | ||
echo Run Docker=$RUN_DOCKER | ||
echo Test to run:"${TEST_MODULE}" | ||
echo ------------------------------------ | ||
|
||
|
||
if [ $RUN_DOCKER -eq 1 ] | ||
then | ||
restart_docker | ||
fi | ||
|
||
if [ $RUN_INIT -eq 1 ] | ||
then | ||
test_init | ||
fi | ||
|
||
nosetests --exclude=load_examples_test "${TEST_MODULE}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead just use the docker-compose in the root of the repo? Will start to get a bit tricky to manage several files. You can specify which compose to leverage, as well as which containers to build/start on the CMD line, as I see you're doing already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I like about this is that it creates a different database for testing vs. development. That's a great situation to be in. I'm OK reusing the compose file but I'd like to keep the different test vs. dev database setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but if we can just reuse one file, it's likely simpler. Thoughts on this @dpgaspar ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed thoughts, on my local env I use 2 distinct
docker-compose
files it's easier to bring dev down or test down that way. Note that by default the script recycles the test db's so that we start from a clean env (no data), or keep them running, useful for running multiple times (reducing test dev or just dev loop times). So I propose one of the following paths forward:docker-compose
file, then just restart the containers that belong to the test envI would say both have their pro's and con's, personally prefer the first. Thoughts @willbarrett @craig-rueda ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 3: use the root docker-compose port and the same container as dev, but change the database name so the two have logically separate data. I would prefer that option as it's lighter on containers, and test data is not just held in memory. Dropping the test databases would allow for a clean reset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@craig-rueda is that 👍 for the Option 3 I recommended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sounds like a plan