Files
qdrant/openapi/tests/openapi_integration/test_snapshot.py
Alex Huang de93c75bf3 feat: add wait param for all snapshot API (#1571)
* feat: add wait parm for all snapshot API

* update openAPI

* avoid unwrap

* remove all unwarp

* return HTTP 202 when no waiting on snapshot creation

* return 202 when non wait

* update open API

* update param on python test

* update and test api

* optimize the test

* return 202 when non-wait delete

* recover fixes

---------

Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>
Co-authored-by: Andrey Vasnetsov <andrey@vasnetsov.com>
2023-04-11 13:42:11 +02:00

206 lines
5.8 KiB
Python

from time import sleep
import pytest
from .helpers.helpers import request_with_validation
from .helpers.collection_setup import basic_collection_setup, drop_collection
collection_name = 'test_collection_snapshot'
@pytest.fixture(autouse=True)
def setup():
basic_collection_setup(collection_name=collection_name)
yield
drop_collection(collection_name=collection_name)
def test_snapshot_operations():
# no snapshot on collection
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert len(response.json()['result']) == 0
# create snapshot on collection
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="POST",
path_params={'collection_name': collection_name},
query_params={'wait': 'true'},
)
assert response.ok
snapshot_name = response.json()['result']['name']
# validate it exists
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert len(response.json()['result']) == 1
assert response.json()['result'][0]['name'] == snapshot_name
# delete it
response = request_with_validation(
api='/collections/{collection_name}/snapshots/{snapshot_name}',
method="DELETE",
path_params={'collection_name': collection_name,
'snapshot_name': snapshot_name},
query_params={'wait': 'true'},
)
assert response.ok
# validate it is gone
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert len(response.json()['result']) == 0
# no full snapshot
response = request_with_validation(
api='/snapshots',
method="GET",
)
assert response.ok
assert len(response.json()['result']) == 0
# create full snapshot
response = request_with_validation(
api='/snapshots',
method="POST",
)
assert response.ok
snapshot_name = response.json()['result']['name']
# validate it exists
response = request_with_validation(
api='/snapshots',
method="GET",
)
assert response.ok
assert len(response.json()['result']) == 1
assert response.json()['result'][0]['name'] == snapshot_name
# delete it
response = request_with_validation(
api='/snapshots/{snapshot_name}',
path_params={'snapshot_name': snapshot_name},
method="DELETE",
query_params={'wait': 'true'},
)
assert response.ok
response = request_with_validation(
api='/snapshots',
method="GET",
)
assert response.ok
assert len(response.json()['result']) == 0
def test_test_snapshot_operations_non_wait():
# there no snapshot on collection
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert len(response.json()['result']) == 0
# create snapshot on collection
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="POST",
path_params={'collection_name': collection_name},
query_params={'wait': 'false'},
)
assert response.status_code == 202
# wait for snapshot to be created
sleep(1)
# validate it exists
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert len(response.json()['result']) == 1
snapshot_name = response.json()['result'][0]['name']
# delete it
response = request_with_validation(
api='/collections/{collection_name}/snapshots/{snapshot_name}',
method="DELETE",
path_params={'collection_name': collection_name,
'snapshot_name': snapshot_name},
query_params={'wait': 'false'},
)
assert response.status_code == 202
# wait for snapshot to be deleted
sleep(2)
# validate it is gone
response = request_with_validation(
api='/collections/{collection_name}/snapshots',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert len(response.json()['result']) == 0
# no full snapshot
response = request_with_validation(
api='/snapshots',
method="GET",
)
assert response.ok
assert len(response.json()['result']) == 0
# create full snapshot
response = request_with_validation(
api='/snapshots',
method="POST",
query_params={'wait': 'false'},
)
assert response.status_code == 202
# wait for snapshot to be created
sleep(2)
# validate it exists
response = request_with_validation(
api='/snapshots',
method="GET",
)
assert response.ok
assert len(response.json()['result']) == 1
snapshot_name = response.json()['result'][0]['name']
# delete it
response = request_with_validation(
api='/snapshots/{snapshot_name}',
path_params={'snapshot_name': snapshot_name},
method="DELETE",
query_params={'wait': 'false'},
)
assert response.status_code == 202
# wait for snapshot to be deleted
sleep(1)
response = request_with_validation(
api='/snapshots',
method="GET",
)
assert response.ok
assert len(response.json()['result']) == 0