From 22bfee1cd978326f1a6142a51195461f11a60d0e Mon Sep 17 00:00:00 2001 From: jidong Date: Tue, 7 Jun 2022 10:55:17 +0800 Subject: [PATCH] modify sleep logic in app account xts Signed-off-by: jidong --- .../entry/src/main/js/test/AppAccess.test.js | 15 +++++++++------ .../entry/src/main/js/test/AssociatedData.test.js | 15 +++++++++------ .../entry/src/main/js/test/CreatManager.test.js | 13 ++++++++----- .../entry/src/main/js/test/Credential.test.js | 15 +++++++++------ .../entry/src/main/js/test/DeleteAccount.test.js | 13 ++++++++----- .../entry/src/main/js/test/ExtraInfo.test.js | 15 +++++++++------ .../entry/src/main/js/test/NoPermission.test.js | 14 ++++++++------ .../entry/src/main/js/test/OAuthToken.test.js | 15 +++++++++------ .../entry/src/main/js/test/OnOff.js | 12 +++++++++++- 9 files changed, 80 insertions(+), 47 deletions(-) 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 dad817699..ea1ff0b2a 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 @@ -20,22 +20,25 @@ const STRCOUNT = 1025; const EACHTIMEOUT = 500; describe('ActsAccountAppAccess', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }) beforeEach(async function (done) { console.debug("====>beforeEach enter===="); - sleep(EACHTIMEOUT); + await sleep(EACHTIMEOUT); done(); }) 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 e876bd5d1..d647af7b0 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 @@ -19,22 +19,25 @@ const TIMEOUT = 5000; const EACHTIMEOUT = 500; describe('ActsAccountAssociatedData', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }) beforeEach(async function (done) { console.debug("====>beforeEach enter===="); - sleep(EACHTIMEOUT); + await sleep(EACHTIMEOUT); done(); }) diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js index 9dd6182c6..9ced61338 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/CreatManager.test.js @@ -18,15 +18,18 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; describe('ActsCreatAppAccountManager', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }); 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 babfc997a..cf5714246 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 @@ -19,22 +19,25 @@ const TIMEOUT = 5000; const EACHTIMEOUT = 500; describe('ActsAccountCredential', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }) beforeEach(async function (done) { console.debug("====>beforeEach enter===="); - sleep(EACHTIMEOUT); + await sleep(EACHTIMEOUT); done(); }) diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js index f463d95ba..254a3daa3 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/DeleteAccount.test.js @@ -19,15 +19,18 @@ const NAMELIMIT = 512; const TIMEOUT = 5000; describe('ActsAccountDeleteAccount', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }); 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 a4a695e11..ea6f39de2 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 @@ -19,22 +19,25 @@ const TIMEOUT = 5000; const EACHTIMEOUT = 500; describe('ActsAccountSetGetExtraInfo', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }) beforeEach(async function (done) { console.debug("====>beforeEach enter===="); - sleep(EACHTIMEOUT); + await sleep(EACHTIMEOUT); done(); }) diff --git a/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js b/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js index 7080d8a60..9af1c3191 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/NoPermission.test.js @@ -19,15 +19,17 @@ const TIMEOUT = 5000; const ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED = 4521993; describe('ActsAccountNoPermission', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } - beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }); 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 5027b8a18..82685f048 100644 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OAuthToken.test.js @@ -30,22 +30,25 @@ const OWNERSELF = "com.example.actsaccounttest"; describe('ActsAccountOAuthToken', function () { function sleep(delay) { - var start = (new Date()).getTime(); - while((new Date()).getTime() - start < delay) { - continue; - } + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) } beforeAll(async function (done) { console.debug("====>beforeAll start===="); - sleep(TIMEOUT); + await sleep(TIMEOUT); console.debug("====>beforeAll end===="); done(); }); beforeEach(async function (done) { console.debug("====>beforeAll enter===="); - sleep(EACHTIMEOUT); + await sleep(EACHTIMEOUT); done(); }); 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 c2c32ab9d..8fbf7b6d0 100755 --- a/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js +++ b/account/appaccount/actsaccounttest/entry/src/main/js/test/OnOff.js @@ -20,6 +20,15 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' const TIMEOUT = 5000; describe('ActsAccountChangeOnOff', async function () { + function sleep(delay) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, delay) + }).then(() => { + console.info(`sleep #{time} over ...`) + }) + } beforeAll(async function (done) { console.debug("====>startAbility start===="); await featureAbility.startAbility( @@ -35,7 +44,8 @@ describe('ActsAccountChangeOnOff', async function () { }, }, ); - setTimeout(done(), TIMEOUT); + await sleep(TIMEOUT); + done(); }); /* -- GitLab