From 6c04446fdfb736b8db60129a3113c2b458037536 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Wed, 15 Dec 2021 16:47:53 +0800 Subject: [PATCH] Fix appaccount test bug Signed-off-by: zhaoyuan17 --- .../appaccount/actsaccountpressure/Test.json | 2 +- .../src/main/js/default/pages/index/index.js | 2 +- .../entry/src/main/js/test/Pressure.test.js | 63 +++++++++----- account/appaccount/actsaccounttest/Test.json | 2 +- .../entry/src/main/js/test/AppAccess.test.js | 9 +- .../src/main/js/test/AssociatedData.test.js | 9 +- .../entry/src/main/js/test/Credential.test.js | 9 +- .../entry/src/main/js/test/ExtraInfo.test.js | 9 +- .../entry/src/main/js/test/OAuthToken.test.js | 7 ++ .../entry/src/main/js/test/OnOff.js | 86 ++++++++++++++++--- 10 files changed, 157 insertions(+), 41 deletions(-) diff --git a/account/appaccount/actsaccountpressure/Test.json b/account/appaccount/actsaccountpressure/Test.json index d01bfc738..479500b35 100755 --- a/account/appaccount/actsaccountpressure/Test.json +++ b/account/appaccount/actsaccountpressure/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for hjunit demo Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "2000000", + "test-timeout": "3000000", "package": "com.example.actsaccountpressure", "shell-timeout": "60000" }, diff --git a/account/appaccount/actsaccountpressure/entry/src/main/js/default/pages/index/index.js b/account/appaccount/actsaccountpressure/entry/src/main/js/default/pages/index/index.js index 0155375ef..21dce8485 100755 --- a/account/appaccount/actsaccountpressure/entry/src/main/js/default/pages/index/index.js +++ b/account/appaccount/actsaccountpressure/entry/src/main/js/default/pages/index/index.js @@ -35,7 +35,7 @@ export default { core.init() const configService = core.getDefaultService('config') - this.timeout = 150000; + this.timeout = 180000; configService.setConfig(this) require('../../../test/List.test') diff --git a/account/appaccount/actsaccountpressure/entry/src/main/js/test/Pressure.test.js b/account/appaccount/actsaccountpressure/entry/src/main/js/test/Pressure.test.js index 20fe98290..a32f91959 100755 --- a/account/appaccount/actsaccountpressure/entry/src/main/js/test/Pressure.test.js +++ b/account/appaccount/actsaccountpressure/entry/src/main/js/test/Pressure.test.js @@ -113,8 +113,15 @@ describe('ActsAccountPressure', function () { console.debug("====>creat finish===="); let flag = true; let count = 0; - for (let i = 0; i < STRESSLEVEL; i++) { + let STRESSNUM; + if(STRESSLEVEL > ACCOUNTLIMIT){ + STRESSNUM = ACCOUNTLIMIT; + }else{ + STRESSNUM = STRESSLEVEL; + } + for (let i = 0; i < STRESSNUM; i++) { let accountName = "account_pressure_callback" + i; + sleep(TIMEOUT); appAccountManager.addAccount(accountName, (err)=>{ console.debug('====>addAccount name: ' + accountName); expect(err.code).assertEqual(0); @@ -124,6 +131,7 @@ describe('ActsAccountPressure', function () { flag = false; done(); } + sleep(TIMEOUT); appAccountManager.deleteAccount(accountName, (err)=>{ console.debug('====>deleteAccount name: ' + accountName); expect(err.code).assertEqual(0); @@ -141,10 +149,8 @@ describe('ActsAccountPressure', function () { done(); } count++; - sleep(TIMEOUT); }) }); - sleep(TIMEOUT); if (!flag) { done(); break; @@ -191,26 +197,43 @@ describe('ActsAccountPressure', function () { catch(err){ console.debug("====>add Account that exceed the limit err:" + JSON.stringify(err)); expect(err.code != 0).assertEqual(true); - await appAccountManager.deleteAccount("account_name_limit"); - } - } - console.debug("====>deleteAccount start===="); - for (count = 0; count < STRESSNUM; count++) { - let accountName = "account_pressure_limit" + count; - console.debug('====>deleteAccount name: ' + accountName); - try{ - await appAccountManager.deleteAccount(accountName); - sleep(TIMEOUT); - } - catch(err){ - console.error("====>deleteAccount fail err:" + JSON.stringify(err)); - expect().assertFail(); + console.debug("====>deleteAccount start===="); + for (count = 0; count < STRESSNUM; count++) { + let accountName = "account_pressure_limit" + count; + console.debug('====>deleteAccount name: ' + accountName); + try{ + await appAccountManager.deleteAccount(accountName); + sleep(TIMEOUT); + } + catch(err){ + console.error("====>deleteAccount fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + } + console.debug("====>the number of times to complete the stress test is: " + count) + console.debug("====>ActsAccountPressure_0300 end===="); done(); } + }else{ + console.debug("====>deleteAccount start===="); + for (count = 0; count < STRESSNUM; count++) { + let accountName = "account_pressure_limit" + count; + console.debug('====>deleteAccount name: ' + accountName); + try{ + await appAccountManager.deleteAccount(accountName); + sleep(TIMEOUT); + } + catch(err){ + console.error("====>deleteAccount fail err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + } + console.debug("====>the number of times to complete the stress test is: " + count) + console.debug("====>ActsAccountPressure_0300 end===="); + done(); } - console.debug("====>the number of times to complete the stress test is: " + count) - console.debug("====>ActsAccountPressure_0300 end===="); - done(); }); /* diff --git a/account/appaccount/actsaccounttest/Test.json b/account/appaccount/actsaccounttest/Test.json index 0f25d92c1..0ed6b946a 100755 --- a/account/appaccount/actsaccounttest/Test.json +++ b/account/appaccount/actsaccounttest/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for hjunit demo Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "300000", + "test-timeout": "500000", "package": "com.example.actsaccounttest", "shell-timeout": "60000" }, diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js index c2d5b1eb6..dad817699 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/AppAccess.test.js @@ -17,6 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; const STRCOUNT = 1025; +const EACHTIMEOUT = 500; describe('ActsAccountAppAccess', function () { function sleep(delay) { var start = (new Date()).getTime(); @@ -30,7 +31,13 @@ describe('ActsAccountAppAccess', function () { sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); - }); + }) + + beforeEach(async function (done) { + console.debug("====>beforeEach enter===="); + sleep(EACHTIMEOUT); + done(); + }) /* * @tc.number : ActsAccountAppAccess_0100 diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js index 4c155e89e..e876bd5d1 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/AssociatedData.test.js @@ -16,6 +16,7 @@ import account from '@ohos.account.appAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' const TIMEOUT = 5000; +const EACHTIMEOUT = 500; describe('ActsAccountAssociatedData', function () { function sleep(delay) { var start = (new Date()).getTime(); @@ -29,7 +30,13 @@ describe('ActsAccountAssociatedData', function () { sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); - }); + }) + + beforeEach(async function (done) { + console.debug("====>beforeEach enter===="); + sleep(EACHTIMEOUT); + done(); + }) /* * @tc.number : ActsAccountAssociatedData_0100 diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js index 4d76f07dc..babfc997a 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/Credential.test.js @@ -16,6 +16,7 @@ import account from '@ohos.account.appAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' const TIMEOUT = 5000; +const EACHTIMEOUT = 500; describe('ActsAccountCredential', function () { function sleep(delay) { var start = (new Date()).getTime(); @@ -29,7 +30,13 @@ describe('ActsAccountCredential', function () { sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); - }); + }) + + beforeEach(async function (done) { + console.debug("====>beforeEach enter===="); + sleep(EACHTIMEOUT); + done(); + }) /* * @tc.number : ActsAccountCredential_0100 diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js index 8e636ecad..a4a695e11 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/ExtraInfo.test.js @@ -16,6 +16,7 @@ import account from '@ohos.account.appAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' const TIMEOUT = 5000; +const EACHTIMEOUT = 500; describe('ActsAccountSetGetExtraInfo', function () { function sleep(delay) { var start = (new Date()).getTime(); @@ -29,7 +30,13 @@ describe('ActsAccountSetGetExtraInfo', function () { sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); - }); + }) + + beforeEach(async function (done) { + console.debug("====>beforeEach enter===="); + sleep(EACHTIMEOUT); + done(); + }) /* * @tc.number : ActsAccountSetGetExtraInfo_0100 diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js index d140986b2..630dfa042 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js @@ -17,6 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; const LENGTHLIMIT = 1024; +const EACHTIMEOUT = 500; describe('ActsAccountOAuthToken', function () { function sleep(delay) { var start = (new Date()).getTime(); @@ -32,6 +33,12 @@ describe('ActsAccountOAuthToken', function () { done(); }); + beforeEach(async function (done) { + console.debug("====>beforeEach enter===="); + sleep(EACHTIMEOUT); + done(); + }) + /* * @tc.number : ActsAccountOAuthToken_0100 * @tc.name : Test oauth token in callback form diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js index e7e9b044f..563310551 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js @@ -499,6 +499,7 @@ describe('ActsAccountChangeOnOff', async function () { */ it('ActsAccountChangeOnOff_0800', 0, async function (done) { console.debug("====>ActsAccountChangeOnOff_0800 start===="); + let dataMap = new Map(); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat appAccountManager finish"); console.debug("====>add account ActsAccountChangeOnOff_0800 start"); @@ -506,8 +507,16 @@ describe('ActsAccountChangeOnOff', async function () { console.debug("====>on ActsAccountChangeOnOff_0800 start"); function changeOnCallback(data){ console.debug("====>receive change 0800 data:" + JSON.stringify(data)); - expect(data[0].name).assertEqual("onoff_self"); - expect(data[0].owner).assertEqual("com.example.actsaccounttest"); + console.debug("====>data.length:" + data.length); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].name, data[i].owner) + } + expect(dataMap.has("onoff_self")).assertTrue(); + if (dataMap.has("onoff_self")) { + let data = dataMap.get("onoff_self"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } appAccountManager.off('change', function (){ console.debug("====>off ActsAccountChangeOnOff_0800 finish===="); appAccountManager.deleteAccount("onoff_self", (err)=>{ @@ -545,6 +554,7 @@ describe('ActsAccountChangeOnOff', async function () { */ it('ActsAccountChangeOnOff_0900', 0, async function (done) { console.debug("====>ActsAccountChangeOnOff_0900 start===="); + let dataMap = new Map(); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat appAccountManager finish"); console.debug("====>add first account ActsAccountChangeOnOff_0900 start"); @@ -554,10 +564,22 @@ describe('ActsAccountChangeOnOff', async function () { console.debug("====>on ActsAccountChangeOnOff_0900 start"); function changeOnCallback(data){ console.debug("====>receive change 0900 data:" + JSON.stringify(data)); - expect(data[0].name).assertEqual("onoff_self_first"); - expect(data[0].owner).assertEqual("com.example.actsaccounttest"); - expect(data[1].name).assertEqual("onoff_self_second"); - expect(data[1].owner).assertEqual("com.example.actsaccounttest"); + console.debug("====>data.length:" + data.length); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].name, data[i].owner) + } + expect(dataMap.has("onoff_self_first")).assertTrue(); + if (dataMap.has("onoff_self_first")) { + let data = dataMap.get("onoff_self_first"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } + expect(dataMap.has("onoff_self_second")).assertTrue(); + if (dataMap.has("onoff_self_second")) { + let data = dataMap.get("onoff_self_second"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } appAccountManager.off('change', function (){ console.debug("====>off ActsAccountChangeOnOff_0900 finish===="); appAccountManager.deleteAccount("onoff_self_first", (err)=>{ @@ -598,6 +620,8 @@ describe('ActsAccountChangeOnOff', async function () { */ it('ActsAccountChangeOnOff_1000', 0, async function (done) { console.debug("====>ActsAccountChangeOnOff_1000 start===="); + let dataMapFir = new Map(); + let dataMapSec = new Map(); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat appAccountManager finish"); console.debug("====>add account ActsAccountChangeOnOff_1000 start"); @@ -606,14 +630,30 @@ describe('ActsAccountChangeOnOff', async function () { var twiceSign = 0; function changeOnFirstCallback(data){ console.debug("====>first receive change 1000 data:" + JSON.stringify(data)); - expect(data[0].name).assertEqual("onoff_twice"); - expect(data[0].owner).assertEqual("com.example.actsaccounttest"); + console.debug("====>data.length:" + data.length); + for (let i = 0, len = data.length; i < len; i++) { + dataMapFir.set(data[i].name, data[i].owner) + } + expect(dataMapFir.has("onoff_twice")).assertTrue(); + if (dataMapFir.has("onoff_twice")) { + let data = dataMapFir.get("onoff_twice"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } twiceSign = twiceSign + 1; } function changeOnSecondCallback(data){ console.debug("====>second receive change 1000 data:" + JSON.stringify(data)); - expect(data[0].name).assertEqual("onoff_twice"); - expect(data[0].owner).assertEqual("com.example.actsaccounttest"); + console.debug("====>data.length:" + data.length); + for (let i = 0, len = data.length; i < len; i++) { + dataMapSec.set(data[i].name, data[i].owner) + } + expect(dataMapSec.has("onoff_twice")).assertTrue(); + if (dataMapSec.has("onoff_twice")) { + let data = dataMapSec.get("onoff_twice"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } twiceSign = twiceSign + 1; appAccountManager.off('change', function (){ console.debug("====>off ActsAccountChangeOnOff_1000 finish===="); @@ -654,6 +694,7 @@ describe('ActsAccountChangeOnOff', async function () { */ it('ActsAccountChangeOnOff_1100', 0, async function (done) { console.debug("====>ActsAccountChangeOnOff_1100 start===="); + let dataMap = new Map(); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat appAccountManager finish"); console.debug("====>add account ActsAccountChangeOnOff_1100 start"); @@ -663,8 +704,16 @@ describe('ActsAccountChangeOnOff', async function () { function onCallBack(data){ console.debug("====>receive change 1100 data:" + JSON.stringify(data)); sameSign = sameSign + 1; - expect(data[0].name).assertEqual("onoff_same"); - expect(data[0].owner).assertEqual("com.example.actsaccounttest"); + console.debug("====>data.length:" + data.length); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].name, data[i].owner) + } + expect(dataMap.has("onoff_same")).assertTrue(); + if (dataMap.has("onoff_same")) { + let data = dataMap.get("onoff_same"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } } try{ appAccountManager.on('change', ["com.example.actsaccounttest", "com.example.actsaccounttest"], onCallBack); @@ -705,6 +754,7 @@ describe('ActsAccountChangeOnOff', async function () { */ it('ActsAccountChangeOnOff_1200', 0, async function (done) { console.debug("====>ActsAccountChangeOnOff_1200 start===="); + let dataMap = new Map(); var appAccountManager = account.createAppAccountManager(); console.debug("====>creat appAccountManager finish"); console.debug("====>add account ActsAccountChangeOnOff_1200 start"); @@ -712,8 +762,16 @@ describe('ActsAccountChangeOnOff', async function () { console.debug("====>on ActsAccountChangeOnOff_1200 start"); function changeOnCallback(data){ console.debug("====>receive change 1200 data:" + JSON.stringify(data)); - expect(data[0].name).assertEqual("onoff_repeatoff"); - expect(data[0].owner).assertEqual("com.example.actsaccounttest"); + console.debug("====>data.length:" + data.length); + for (let i = 0, len = data.length; i < len; i++) { + dataMap.set(data[i].name, data[i].owner) + } + expect(dataMap.has("onoff_repeatoff")).assertTrue(); + if (dataMap.has("onoff_repeatoff")) { + let data = dataMap.get("onoff_repeatoff"); + console.debug("====>the account owner is: " + data); + expect(data).assertEqual("com.example.actsaccounttest"); + } appAccountManager.off('change', function (){ console.debug("====>first off ActsAccountChangeOnOff_1200 finish===="); appAccountManager.off('change', function (){ -- GitLab