-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Improve REST API testing system #4403
Conversation
cvat_db_container('psql -U root -q -d test_db -f /cvat_db/cvat_db.sql') | ||
_run(f"docker container cp {osp.join(CVAT_DB_DIR, 'restore.sh')} cvat_db:restore.sh") | ||
_run(f"docker container cp {osp.join(CVAT_DB_DIR, 'data.json')} cvat:data.json") | ||
_run('docker exec cvat python manage.py loaddata /data.json') |
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.
psql
command supports -v
option which allows you to set a variable. Thus you can write cvat_db.sql script with :src_db
and :dst_db
and set them in cvat_db.sql script. Thus you don't need restore.sh
script. More details here: https://stackoverflow.com/questions/36959/how-do-you-use-script-variables-in-psql
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.
Fixed
@@ -0,0 +1,5 @@ | |||
restore="SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'cvat' AND pid <> pg_backend_pid();\ |
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.
It should be replaced by restore_db.sql with variables (see psql -v)
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.
Fixed
If I run tests on a non-empty CVAT instance, it will fail. What do you recommend?
|
@kirill-sizov , I have a couple of questions:
|
|
I don't exactly know the cause of this problem, but in my case this problem only occurs if my current database was built not with
|
I believe it is because I already have cvat db and it isn't empty. Probably we need to run tests on a clear CVAT instance. There are two ways: say about that in documentation, drop cvat db before start. Need to choose the best solution. |
|
@kirill-sizov , I have merged the PR from Andrey. Could you please resolve conflicts? |
Done |
tests/rest_api/README.md
Outdated
cat assets/cvat_db/cvat_db.sql | docker exec -i cvat_db psql -U root -d cvat | ||
cat assets/cvat_data.tar.bz2 | docker run --rm -i --volumes-from cvat ubuntu tar -xj --strip 3 -C /home/django/data | ||
docker container cp assets/cvat_db/data.json cvat:data.json | ||
docker exec cvat python manage.py loaddata /data.json |
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.
Why don't read from stdin? https://docs.djangoproject.com/en/4.0/ref/django-admin/#loading-fixtures-from-stdin
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.
Fixed
tests/rest_api/README.md
Outdated
- `cvat_data.tar.bz2` --- archieve with data volumes; | ||
- `data.json` --- file required for DB restoring. | ||
Contains all information about test db; | ||
- `restore.sh` --- simple bash script for creating copy of database and |
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.
Do we still have restore.sh?
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.
Fixed
tests/rest_api/README.md
Outdated
In this case you should terminate all existent connections for cvat database, | ||
you can perform it with command: | ||
``` | ||
docker exec cvat_db sh restore.sh cvat test_db |
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.
Do we have restore.sh?
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.
Fixed
@kirill-sizov , I see cvat_data.tar.bz2 twice in the PR. |
@kirill-sizov , could you please double check your PR next time? |
I see only one
|
Motivation and context
The current test database initialization strategy for REST API tests uses the
cvat_db.sql
file, this approach makes it difficult to develop tests in parallel because it is not clear how to perform *.sql file merging. So this PR solve this problem with Django functionality.This PR suggest to initialize test db in this way:
Increase time with new recovery strategy: ~4 sec.
How has this been tested?
Checklist
develop
branchcvat-core, cvat-data and cvat-ui)
License
Feel free to contact the maintainers if that's a concern.