Browse Source

fix test and check connect

Signed-off-by: nameczz <zizhao.chen@zilliz.com>
nameczz 3 years ago
parent
commit
4fd31b27f6

+ 2 - 5
server/generate-csv.ts

@@ -3,10 +3,7 @@ import { createObjectCsvWriter as createCsvWriter } from 'csv-writer';
 // use to test vector insert
 const csvWriter = createCsvWriter({
   path: './vectors.csv',
-  header: [
-    { id: 'vector', title: 'vector' },
-    { id: 'age', title: 'age' },
-  ],
+  header: [{ id: 'vector', title: 'vector' }],
 });
 
 const records = [];
@@ -23,7 +20,7 @@ const generateVector = (dimension: number) => {
 
 while (records.length < 50000) {
   const value = generateVector(4);
-  records.push({ vector: value, age: records.length });
+  records.push({ vector: value });
 }
 
 csvWriter

+ 4 - 1
server/src/__tests__/collections/collections.service.test.ts

@@ -34,7 +34,10 @@ describe('Test collections service', () => {
     MilvusService.activeAddress = mockAddress;
     MilvusService.activeMilvusClient = new MilvusClient(mockAddress);
 
-    await milvusService.connectMilvus(mockAddress, insightCacheForTest);
+    await milvusService.connectMilvus(
+      { address: mockAddress },
+      insightCacheForTest
+    );
     service = new CollectionsService(milvusService);
   });
 

+ 4 - 1
server/src/__tests__/crons/crons.service.test.ts

@@ -45,7 +45,10 @@ describe('test crons service', () => {
     MilvusService.activeAddress = mockAddress;
     MilvusService.activeMilvusClient = new MilvusClient(mockAddress);
 
-    await milvusService.connectMilvus(mockAddress, insightCacheForTest);
+    await milvusService.connectMilvus(
+      { address: mockAddress },
+      insightCacheForTest
+    );
 
     collectionService = new CollectionsService(milvusService);
 

+ 9 - 6
server/src/__tests__/milvus/milvus.service.test.ts

@@ -25,13 +25,16 @@ describe('Test Milvus service', () => {
   });
 
   test('test connectMilvus method', async () => {
-    const res = await service.connectMilvus(mockAddress, insightCacheForTest);
+    const res = await service.connectMilvus(
+      { address: mockAddress },
+      insightCacheForTest
+    );
     expect(res.address).toBe(mockAddress);
   });
 
   test('test connectMilvus method error', async () => {
     try {
-      await service.connectMilvus('', insightCacheForTest);
+      await service.connectMilvus({ address: '' }, insightCacheForTest);
     } catch (err) {
       expect(err.message).toBe(
         'Connect milvus failed, check your milvus address.'
@@ -49,7 +52,7 @@ describe('Test Milvus service', () => {
 
   test('test checkConnect method', async () => {
     // mock connect first
-    await service.connectMilvus(mockAddress, insightCacheForTest);
+    await service.connectMilvus({ address: mockAddress }, insightCacheForTest);
     // different address
     const errorRes = await service.checkConnect('123', insightCacheForTest);
     expect(errorRes.connected).toBeFalsy();
@@ -58,7 +61,7 @@ describe('Test Milvus service', () => {
   });
 
   test('test managers after connected', async () => {
-    await service.connectMilvus(mockAddress, insightCacheForTest);
+    await service.connectMilvus({ address: mockAddress }, insightCacheForTest);
     expect(service.collectionManager).toBeDefined();
     expect(service.partitionManager).toBeDefined();
     expect(service.indexManager).toBeDefined();
@@ -66,14 +69,14 @@ describe('Test Milvus service', () => {
   });
 
   test('test flush method', async () => {
-    await service.connectMilvus(mockAddress, insightCacheForTest);
+    await service.connectMilvus({ address: mockAddress }, insightCacheForTest);
     const res = await service.flush({ collection_names: ['c1', 'c2'] });
     const data = res.data.collection_names;
     expect(data.length).toBe(2);
   });
 
   test('test getMetrics method', async () => {
-    await service.connectMilvus(mockAddress, insightCacheForTest);
+    await service.connectMilvus({ address: mockAddress }, insightCacheForTest);
     const res = await service.getMetrics();
     expect(res.type).toBe('system_info');
   });

+ 4 - 1
server/src/__tests__/partitions/partitions.service.test.ts

@@ -27,7 +27,10 @@ describe('Test partitions service', () => {
     MilvusService.activeAddress = mockAddress;
     MilvusService.activeMilvusClient = new MilvusClient(mockAddress);
 
-    await milvusService.connectMilvus(mockAddress, insightCacheForTest);
+    await milvusService.connectMilvus(
+      { address: mockAddress },
+      insightCacheForTest
+    );
     service = new PartitionsService(milvusService);
   });
 

+ 4 - 1
server/src/__tests__/schema/schema.service.test.ts

@@ -22,7 +22,10 @@ describe('Test schema service', () => {
     MilvusService.activeAddress = mockAddress;
     MilvusService.activeMilvusClient = new MilvusClient(mockAddress);
 
-    await milvusService.connectMilvus(mockAddress, insightCacheForTest);
+    await milvusService.connectMilvus(
+      { address: mockAddress },
+      insightCacheForTest
+    );
     service = new SchemaService(milvusService);
   });
 

+ 5 - 12
server/src/milvus/milvus.service.ts

@@ -41,11 +41,10 @@ export class MilvusService {
 
   checkMilvus() {
     if (!MilvusService.activeMilvusClient) {
-      // todo, need test when activeMilvusClient is empty.
-      throw HttpErrors(HTTP_STATUS_CODE.BAD_REQUEST, {
-        status: 401,
-        message: 'please connect milvus first',
-      });
+      throw HttpErrors(
+        HTTP_STATUS_CODE.FORBIDDEN,
+        'Can not find your connection, please connect Milvus again'
+      );
       // throw new Error('Please connect milvus first');
     }
   }
@@ -85,13 +84,7 @@ export class MilvusService {
 
   async checkConnect(address: string, cache: LruCache<any, any>) {
     const milvusAddress = MilvusService.formatAddress(address);
-    if (!cache.has(milvusAddress)) {
-      return { connected: false };
-    }
-    // const res = await this.connectMilvus(address, cache);
-    // return {
-    //   connected: res.address ? true : false,
-    // };
+    return { connected: cache.has(milvusAddress) };
   }
 
   async flush(data: FlushReq) {