1
|
|
|
import pdb |
2
|
|
|
import pytest |
3
|
|
|
import logging |
4
|
|
|
import itertools |
5
|
|
|
import threading |
6
|
|
|
from time import sleep |
7
|
|
|
from multiprocessing import Process |
8
|
|
|
from milvus import IndexType, MetricType |
9
|
|
|
from utils import * |
10
|
|
|
|
11
|
|
|
collection_id = "has_collection" |
12
|
|
|
default_fields = gen_default_fields() |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class TestHasCollection: |
16
|
|
|
|
17
|
|
|
""" |
18
|
|
|
****************************************************************** |
19
|
|
|
The following cases are used to test `has_collection` function |
20
|
|
|
****************************************************************** |
21
|
|
|
""" |
22
|
|
|
def test_has_collection(self, connect, collection): |
23
|
|
|
''' |
24
|
|
|
target: test if the created collection existed |
25
|
|
|
method: create collection, assert the value returned by has_collection method |
26
|
|
|
expected: True |
27
|
|
|
''' |
28
|
|
|
assert connect.has_collection(collection) |
29
|
|
|
|
30
|
|
|
@pytest.mark.level(2) |
31
|
|
|
def test_has_collection_without_connection(self, collection, dis_connect): |
32
|
|
|
''' |
33
|
|
|
target: test has collection, without connection |
34
|
|
|
method: calling has collection with correct params, with a disconnected instance |
35
|
|
|
expected: has collection raise exception |
36
|
|
|
''' |
37
|
|
|
with pytest.raises(Exception) as e: |
38
|
|
|
assert connect.has_collection(collection) |
|
|
|
|
39
|
|
|
|
40
|
|
|
def test_has_collection_not_existed(self, connect): |
41
|
|
|
''' |
42
|
|
|
target: test if collection not created |
43
|
|
|
method: random a collection name, which not existed in db, |
44
|
|
|
assert the value returned by has_collection method |
45
|
|
|
expected: False |
46
|
|
|
''' |
47
|
|
|
collection_name = gen_unique_str("test_collection") |
48
|
|
|
assert not connect.has_collection(collection_name) |
49
|
|
|
|
50
|
|
|
@pytest.mark.level(2) |
51
|
|
|
def test_has_collection_multithread(self, connect): |
52
|
|
|
''' |
53
|
|
|
target: test create collection with multithread |
54
|
|
|
method: create collection using multithread, |
55
|
|
|
expected: collections are created |
56
|
|
|
''' |
57
|
|
|
threads_num = 4 |
58
|
|
|
threads = [] |
59
|
|
|
collection_name = gen_unique_str(collection_id) |
60
|
|
|
connect.create_collection(collection_name, default_fields) |
61
|
|
|
|
62
|
|
|
def has(): |
63
|
|
|
assert not assert_collection(connect, collection_name) |
|
|
|
|
64
|
|
|
for i in range(threads_num): |
65
|
|
|
t = threading.Thread(target=has, args=()) |
66
|
|
|
threads.append(t) |
67
|
|
|
t.start() |
68
|
|
|
time.sleep(0.2) |
69
|
|
|
for t in threads: |
70
|
|
|
t.join() |
71
|
|
|
|
72
|
|
|
|
73
|
|
View Code Duplication |
class TestHasCollectionInvalid(object): |
|
|
|
|
74
|
|
|
""" |
75
|
|
|
Test has collection with invalid params |
76
|
|
|
""" |
77
|
|
|
@pytest.fixture( |
78
|
|
|
scope="function", |
79
|
|
|
params=gen_invalid_strs() |
80
|
|
|
) |
81
|
|
|
def get_collection_name(self, request): |
82
|
|
|
yield request.param |
83
|
|
|
|
84
|
|
|
@pytest.mark.level(2) |
85
|
|
|
def test_has_collection_with_invalid_collectionname(self, connect, get_collection_name): |
86
|
|
|
collection_name = get_collection_name |
87
|
|
|
with pytest.raises(Exception) as e: |
88
|
|
|
connect.has_collection(collection_name) |
89
|
|
|
|
90
|
|
|
@pytest.mark.level(2) |
91
|
|
|
def test_has_collection_with_empty_collectionname(self, connect): |
92
|
|
|
collection_name = '' |
93
|
|
|
with pytest.raises(Exception) as e: |
94
|
|
|
connect.has_collection(collection_name) |
95
|
|
|
|
96
|
|
|
@pytest.mark.level(2) |
97
|
|
|
def test_has_collection_with_none_collectionname(self, connect): |
98
|
|
|
collection_name = None |
99
|
|
|
with pytest.raises(Exception) as e: |
100
|
|
|
connect.has_collection(collection_name) |
101
|
|
|
|