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
|
|
|
|
12
|
|
|
drop_interval_time = 3 |
13
|
|
|
collection_id = "list_collections" |
14
|
|
|
default_fields = gen_default_fields() |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class TestListCollections: |
18
|
|
|
|
19
|
|
|
""" |
20
|
|
|
****************************************************************** |
21
|
|
|
The following cases are used to test `list_collections` function |
22
|
|
|
****************************************************************** |
23
|
|
|
""" |
24
|
|
|
def test_list_collections(self, connect, collection): |
25
|
|
|
''' |
26
|
|
|
target: test list collections |
27
|
|
|
method: create collection, assert the value returned by list_collections method |
28
|
|
|
expected: True |
29
|
|
|
''' |
30
|
|
|
assert collection in connect.list_collections() |
31
|
|
|
|
32
|
|
|
def test_list_collections_multi_collections(self, connect): |
33
|
|
|
''' |
34
|
|
|
target: test list collections |
35
|
|
|
method: create collection, assert the value returned by list_collections method |
36
|
|
|
expected: True |
37
|
|
|
''' |
38
|
|
|
collection_num = 100 |
39
|
|
|
for i in range(collection_num): |
40
|
|
|
collection_name = gen_unique_str(collection_id) |
41
|
|
|
connect.create_collection(collection_name, default_fields) |
42
|
|
|
assert collection_name in connect.list_collections() |
43
|
|
|
|
44
|
|
|
@pytest.mark.level(2) |
45
|
|
|
def test_list_collections_without_connection(self, dis_connect): |
46
|
|
|
''' |
47
|
|
|
target: test list collections, without connection |
48
|
|
|
method: calling list collections with correct params, with a disconnected instance |
49
|
|
|
expected: list collections raise exception |
50
|
|
|
''' |
51
|
|
|
with pytest.raises(Exception) as e: |
52
|
|
|
dis_connect.list_collections() |
53
|
|
|
|
54
|
|
|
def test_list_collections_not_existed(self, connect): |
55
|
|
|
''' |
56
|
|
|
target: test if collection not created |
57
|
|
|
method: random a collection name, which not existed in db, |
58
|
|
|
assert the value returned by list_collections method |
59
|
|
|
expected: False |
60
|
|
|
''' |
61
|
|
|
collection_name = gen_unique_str(collection_id) |
62
|
|
|
assert collection_name not in connect.list_collections() |
63
|
|
|
|
64
|
|
|
def test_list_collections_no_collection(self, connect): |
65
|
|
|
''' |
66
|
|
|
target: test show collections is correct or not, if no collection in db |
67
|
|
|
method: delete all collections, |
68
|
|
|
assert the value returned by list_collections method is equal to [] |
69
|
|
|
expected: the status is ok, and the result is equal to [] |
70
|
|
|
''' |
71
|
|
|
result = connect.list_collections() |
72
|
|
|
if result: |
73
|
|
|
for collection_name in result: |
74
|
|
|
connect.drop_collection(collection_name) |
75
|
|
|
time.sleep(drop_interval_time) |
76
|
|
|
result = connect.list_collections() |
77
|
|
|
assert len(result) == 0 |
78
|
|
|
|
79
|
|
|
@pytest.mark.level(2) |
80
|
|
|
def test_list_collections_multithread(self, connect): |
81
|
|
|
''' |
82
|
|
|
target: test create collection with multithread |
83
|
|
|
method: create collection using multithread, |
84
|
|
|
expected: collections are created |
85
|
|
|
''' |
86
|
|
|
threads_num = 4 |
87
|
|
|
threads = [] |
88
|
|
|
collection_name = gen_unique_str(collection_id) |
89
|
|
|
connect.create_collection(collection_name, default_fields) |
90
|
|
|
|
91
|
|
|
def _list(): |
92
|
|
|
assert collection_name in connect.list_collections() |
93
|
|
|
for i in range(threads_num): |
94
|
|
|
t = threading.Thread(target=_list, args=()) |
95
|
|
|
threads.append(t) |
96
|
|
|
t.start() |
97
|
|
|
time.sleep(0.2) |
98
|
|
|
for t in threads: |
99
|
|
|
t.join() |
100
|
|
|
|