diff --git a/test/config.js b/test/config.js index f8c17d085..ebd8e5ddf 100644 --- a/test/config.js +++ b/test/config.js @@ -18,3 +18,4 @@ config.sts = { }; config.metaSyncTime = env.ONCI ? '30s' : '1000ms'; +config.timeout = '120s'; diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index c53e98442..a23f50c3b 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -6,7 +6,7 @@ const utils = require('./utils'); const oss = require('../..'); const config = require('../config').oss; const ms = require('humanize-ms'); -const { metaSyncTime } = require('../config'); +const { metaSyncTime, timeout } = require('../config'); // only run on travis ci @@ -27,13 +27,14 @@ describe('test/bucket.test.js', () => { bucket = bucket.substring(0, bucket.length - 1); bucketRegion = defaultRegion; - const result = await store.putBucket(bucket, { timeout: process.env.ONCI ? 60000 : 10000 }); + const result = await store.putBucket(bucket, { timeout }); assert.equal(result.bucket, bucket); assert.equal(result.res.status, 200); }); - after(async () => { - await utils.cleanBucket(store, bucket); - }); + // restore object will have cache + // after(async () => { + // await utils.cleanBucket(store, bucket); + // }); describe('setBucket()', () => { it('should check bucket name', async () => { @@ -65,11 +66,11 @@ describe('test/bucket.test.js', () => { // just for archive bucket test archvieBucket = `ali-oss-archive-bucket-${prefix.replace(/[/.]/g, '-')}`; archvieBucket = archvieBucket.substring(0, archvieBucket.length - 1); - await store.putBucket(archvieBucket, { StorageClass: 'Archive', timeout: 120000 }); + await store.putBucket(archvieBucket, { StorageClass: 'Archive', timeout }); }); it('should create a new bucket', async () => { - const result1 = await store.putBucket(name, { timeout: 120000 }); + const result1 = await store.putBucket(name, { timeout }); assert.equal(result1.bucket, name); assert.equal(result1.res.status, 200); }); @@ -79,7 +80,7 @@ describe('test/bucket.test.js', () => { const result2 = await store.listBuckets( {}, { - timeout: 120000 + timeout } ); const { buckets } = result2; @@ -223,7 +224,7 @@ describe('test/bucket.test.js', () => { 'max-keys': 20 }, { - timeout: 120000 + timeout } ); @@ -419,12 +420,12 @@ describe('test/bucket.test.js', () => { describe('putBucketReferer(), getBucketReferer(), deleteBucketReferer()', () => { it('should create, get and delete the referer', async () => { - const putresult = await store.putBucketReferer(bucket, true, ['http://npm.taobao.org'], { timeout: 120000 }); + const putresult = await store.putBucketReferer(bucket, true, ['http://npm.taobao.org'], { timeout }); assert.equal(putresult.res.status, 200); // put again will be fine const referers = ['http://npm.taobao.org', 'https://npm.taobao.org', 'http://cnpmjs.org']; - const putReferer = await store.putBucketReferer(bucket, false, referers, { timeout: 120000 }); + const putReferer = await store.putBucketReferer(bucket, false, referers, { timeout }); assert.equal(putReferer.res.status, 200); await utils.sleep(ms(metaSyncTime)); @@ -444,7 +445,7 @@ describe('test/bucket.test.js', () => { describe('putBucketCORS(), getBucketCORS(), deleteBucketCORS()', () => { afterEach(async () => { // delete it - const result = await store.deleteBucketCORS(bucket, { timeout: 120000 }); + const result = await store.deleteBucketCORS(bucket, { timeout }); assert.equal(result.res.status, 204); }); @@ -461,7 +462,7 @@ describe('test/bucket.test.js', () => { const putResult = await store.putBucketCORS(bucket, rules); assert.equal(putResult.res.status, 200); - const getResult = await store.getBucketCORS(bucket, { timeout: 120000 }); + const getResult = await store.getBucketCORS(bucket, { timeout }); assert.equal(getResult.res.status, 200); assert.deepEqual(getResult.rules, [ { @@ -479,7 +480,7 @@ describe('test/bucket.test.js', () => { { allowedOrigin: '*', allowedMethod: 'GET', - timeout: 120000 + timeout } ]; const putCorsResult1 = await store.putBucketCORS(bucket, rules1); @@ -487,7 +488,7 @@ describe('test/bucket.test.js', () => { await utils.sleep(ms(metaSyncTime)); - const getCorsResult1 = await store.getBucketCORS(bucket, { timeout: 120000 }); + const getCorsResult1 = await store.getBucketCORS(bucket, { timeout }); assert.equal(getCorsResult1.res.status, 200); assert.deepEqual(getCorsResult1.rules, [ { @@ -507,7 +508,7 @@ describe('test/bucket.test.js', () => { await utils.sleep(ms(metaSyncTime)); - const getCorsResult2 = await store.getBucketCORS(bucket, { timeout: 120000 }); + const getCorsResult2 = await store.getBucketCORS(bucket, { timeout }); assert.equal(getCorsResult2.res.status, 200); assert.deepEqual(getCorsResult2.rules, [ { diff --git a/test/node/bucket_worm.test.js b/test/node/bucket_worm.test.js index 75d0a6b58..91346be32 100644 --- a/test/node/bucket_worm.test.js +++ b/test/node/bucket_worm.test.js @@ -1,8 +1,8 @@ - const assert = require('assert'); const utils = require('./utils'); const oss = require('../..'); const config = require('../config').oss; +const timeout = require('../config').timeout; describe('test/bucket_worm.test.js', () => { const { prefix } = utils; @@ -16,15 +16,15 @@ describe('test/bucket_worm.test.js', () => { bucket = `ali-oss-test-worm-bucket-worm-${prefix.replace(/[/.]/g, '-')}`; bucket = bucket.substring(0, bucket.length - 1); - const result = await store.putBucket(bucket, { - timeout: process.env.ONCI ? 60000 : 10000 }); + const result = await store.putBucket(bucket, { timeout }); assert.equal(result.bucket, bucket); assert.equal(result.res.status, 200); }); - - after(async () => { - await utils.cleanAllBucket(store); - }); + // github CI will remove buckets + // restore object will have cache + // after(async () => { + // await utils.cleanBucket(store, bucket); + // }); describe('worm()', () => { describe('initiateBucketWorm()', () => { it('should init bucket worm', async () => { @@ -68,11 +68,7 @@ describe('test/bucket_worm.test.js', () => { it('should extend bucket worm', async () => { try { const { wormId, days } = await store.getBucketWorm(bucket); - await store.extendBucketWorm( - bucket, - wormId, - (days * 1 + 1).toString() - ); + await store.extendBucketWorm(bucket, wormId, (days * 1 + 1).toString()); const result = await store.getBucketWorm(bucket); assert(result.days - days === 1); } catch (error) { @@ -81,5 +77,4 @@ describe('test/bucket_worm.test.js', () => { }); }); }); - }); diff --git a/test/node/bukcet_worm.test.js b/test/node/bukcet_worm.test.js index 32ebfe6a0..5363a7306 100644 --- a/test/node/bukcet_worm.test.js +++ b/test/node/bukcet_worm.test.js @@ -1,8 +1,8 @@ - const assert = require('assert'); const utils = require('./utils'); const oss = require('../..'); const config = require('../config').oss; +const { timeout } = require('../config'); describe('test/bucket.test.js', () => { const { prefix } = utils; @@ -16,14 +16,17 @@ describe('test/bucket.test.js', () => { bucket = `ali-oss-test-worm2-bucket-${prefix.replace(/[/.]/g, '-')}`; bucket = bucket.substring(0, bucket.length - 1); - const result = await store.putBucket(bucket, { timeout: process.env.ONCI ? 60000 : 10000 }); + const result = await store.putBucket(bucket, { timeout }); assert.equal(result.bucket, bucket); assert.equal(result.res.status, 200); }); - after(async () => { - await utils.cleanAllBucket(store); - }); + // github CI will remove buckets + // restore object will have cache + // after(async () => { + // await utils.cleanBucket(store, bucket); + // }); + describe('worm()', () => { describe('initiateBucketWorm()', () => { it('should init bucket worm', async () => { diff --git a/test/node/cleanAllBucket.js b/test/node/cleanAllBucket.js index e43301a28..a520e2fdc 100644 --- a/test/node/cleanAllBucket.js +++ b/test/node/cleanAllBucket.js @@ -1,6 +1,29 @@ const utils = require('./utils'); const config = require('../config').oss; -const oss = require('../..'); +const OSS = require('../..'); -const store = oss(config); -utils.cleanAllBucket(store); +const store = OSS(config); + +store.listBuckets().then(r => { + const bucketList = []; + r.buckets.forEach(i => { + if (i.name.indexOf('ali-oss') === 0) { + bucketList.push({ + bucket: i.name, + region: i.region + }); + } + }); + + for (const bucketListItem of bucketList) { + const client = new OSS({ + ...store.options, + bucket: bucketListItem.bucket, + region: bucketListItem.region + }); + utils.cleanBucket(client, bucketListItem.bucket).catch(e => { + console.log('bucket name =======>', bucketListItem.bucket); + console.log('error:====>', e); + }); + } +}); diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index ad740e58c..272d7e485 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -208,6 +208,7 @@ describe('test/multiversion.test.js', () => { it('should copy latest object with versionId `null` when the bucket is suspended', async () => { const target = `${name.replace('file.js', 'file-target-suspended.js')}`; const suspendedRes = await store.putBucketVersioning(bucket, suspended); + await utils.sleep(ms(metaSyncTime)); assert.strictEqual(suspendedRes.res.status, 200); try { const result = await store.copy(target, name, { diff --git a/test/node/rtmp.test.js b/test/node/rtmp.test.js index ee3892304..b45dc290f 100644 --- a/test/node/rtmp.test.js +++ b/test/node/rtmp.test.js @@ -25,7 +25,7 @@ describe('test/rtmp.test.js', () => { let conf; before(async () => { store = oss(config); - bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}`; + bucket = `ali-oss-test-bucket-rtmp-${prefix.replace(/[/.]/g, '-')}`; bucket = bucket.substring(0, bucket.length - 1); store.useBucket(bucket); @@ -46,6 +46,7 @@ describe('test/rtmp.test.js', () => { }; }); + // github CI will remove buckets after(async () => { await utils.cleanBucket(store, bucket); });