diff --git a/test/app/extend/agent.test.js b/test/app/extend/agent.test.ts similarity index 65% rename from test/app/extend/agent.test.js rename to test/app/extend/agent.test.ts index e15682f8a7..e8868bc337 100644 --- a/test/app/extend/agent.test.js +++ b/test/app/extend/agent.test.ts @@ -1,17 +1,13 @@ -'use strict'; +import { strict as assert } from 'node:assert'; +import { restore, createApp, MockApplication } from '../../utils.js'; -const assert = require('assert'); - -const mm = require('egg-mock'); -const utils = require('../../utils'); - -describe('test/app/extend/agent.test.js', () => { - afterEach(mm.restore); +describe('test/app/extend/agent.test.ts', () => { + afterEach(restore); describe('agent.addSingleton()', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/singleton-demo'); + app = createApp('apps/singleton-demo'); return app.ready(); }); after(() => app.close()); @@ -21,28 +17,28 @@ describe('test/app/extend/agent.test.js', () => { assert(config.foo === 'bar'); assert(config.foo2 === 'bar2'); - const ds = app.agent.dataService.createInstance({ foo: 'barrr' }); + const ds = app.agent.dataService.createInstance({ foo: 'bar2' }); config = await ds.getConfig(); - assert(config.foo === 'barrr'); + assert(config.foo === 'bar2'); - const ds2 = await app.agent.dataService.createInstanceAsync({ foo: 'barrr' }); + const ds2 = await app.agent.dataService.createInstanceAsync({ foo: 'bar2' }); config = await ds2.getConfig(); - assert(config.foo === 'barrr'); + assert(config.foo === 'bar2'); config = await app.agent.dataServiceAsync.get('second').getConfig(); assert(config.foo === 'bar'); assert(config.foo2 === 'bar2'); try { - app.agent.dataServiceAsync.createInstance({ foo: 'barrr' }); + app.agent.dataServiceAsync.createInstance({ foo: 'bar2' }); throw new Error('should not execute'); - } catch (err) { + } catch (err: any) { assert(err.message === 'egg:singleton dataServiceAsync only support create asynchronous, please use createInstanceAsync'); } - const ds4 = await app.agent.dataServiceAsync.createInstanceAsync({ foo: 'barrr' }); + const ds4 = await app.agent.dataServiceAsync.createInstanceAsync({ foo: 'bar2' }); config = await ds4.getConfig(); - assert(config.foo === 'barrr'); + assert(config.foo === 'bar2'); }); }); }); diff --git a/test/app/extend/application.test.js b/test/app/extend/application.test.ts similarity index 75% rename from test/app/extend/application.test.js rename to test/app/extend/application.test.ts index 4b93626fa7..7b454c1f94 100644 --- a/test/app/extend/application.test.js +++ b/test/app/extend/application.test.ts @@ -1,14 +1,15 @@ -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const utils = require('../../utils'); +import { strict as assert } from 'node:assert'; +import fs from 'node:fs'; +import path from 'node:path'; +import { scheduler } from 'node:timers/promises'; +import { createApp, MockApplication, cluster } from '../../utils.js'; -describe('test/app/extend/application.test.js', () => { +describe('test/app/extend/application.test.ts', () => { describe('app.logger', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/demo'); + app = createApp('apps/demo'); return app.ready(); }); after(() => app.close()); @@ -17,23 +18,23 @@ describe('test/app/extend/application.test.js', () => { assert(app.logger === app.loggers.logger); }); - it('should alias app.coreLooger => app.loggers.coreLooger', () => { + it('should alias app.coreLogger => app.loggers.coreLogger', () => { assert(app.coreLogger === app.loggers.coreLogger); }); - it('should alias app.getLogger(\'coreLogger\') => app.loggers.coreLooger', () => { + it('should alias app.getLogger(\'coreLogger\') => app.loggers.coreLogger', () => { assert(app.getLogger('coreLogger') === app.loggers.coreLogger); }); - it('should alias app.getLogger(\'noexist\') => null', () => { - assert(app.getLogger('noexist') === null); + it('should alias app.getLogger(\'noExist\') => null', () => { + assert(app.getLogger('noExist') === null); }); }); describe('app.inspect()', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/demo'); + app = createApp('apps/demo'); return app.ready(); }); after(() => app.close()); @@ -50,22 +51,22 @@ describe('test/app/extend/application.test.js', () => { }); describe('app.readyCallback()', () => { - let app; + let app: MockApplication; after(() => app.close()); it('should log info when plugin is not ready', async () => { - app = utils.cluster('apps/notready'); + app = cluster('apps/notready'); // it won't be ready, so wait for the timeout - await utils.sleep(11000); + await scheduler.wait(11000); app.expect('stderr', /\[egg:core:ready_timeout] 10 seconds later a was still unable to finish./); }); }); describe('app.locals', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/locals'); + app = createApp('apps/locals'); return app.ready(); }); after(() => app.close()); @@ -84,15 +85,15 @@ describe('test/app/extend/application.test.js', () => { }); describe('app.locals.foo = bar', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/app-locals-getter'); + app = createApp('apps/app-locals-getter'); return app.ready(); }); after(() => app.close()); - it('should work', () => { - return app.httpRequest() + it('should work', async () => { + return await app.httpRequest() .get('/test') .expect({ locals: { @@ -104,9 +105,9 @@ describe('test/app/extend/application.test.js', () => { }); describe('app.createAnonymousContext()', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/demo'); + app = createApp('apps/demo'); return app.ready(); }); after(() => app.close()); @@ -120,7 +121,7 @@ describe('test/app/extend/application.test.js', () => { 'x-forwarded-for': '10.0.0.1', }, url: '/foobar?ok=1', - }); + } as any); assert(ctx.ip === '10.0.0.1'); assert(ctx.url === '/foobar?ok=1'); assert(ctx.socket.remoteAddress === '10.0.0.1'); @@ -129,9 +130,9 @@ describe('test/app/extend/application.test.js', () => { }); describe('app.addSingleton()', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/singleton-demo'); + app = createApp('apps/singleton-demo'); return app.ready(); }); after(() => app.close()); @@ -156,7 +157,7 @@ describe('test/app/extend/application.test.js', () => { try { app.dataServiceAsync.createInstance({ foo: 'barrr' }); throw new Error('should not execute'); - } catch (err) { + } catch (err: any) { assert(err.message === 'egg:singleton dataServiceAsync only support create asynchronous, please use createInstanceAsync'); } @@ -167,9 +168,9 @@ describe('test/app/extend/application.test.js', () => { }); describe('app.runInBackground(scope)', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/ctx-background'); + app = createApp('apps/ctx-background'); return app.ready(); }); after(() => app.close()); @@ -179,62 +180,62 @@ describe('test/app/extend/application.test.js', () => { .get('/app_background') .expect(200) .expect('hello app'); - await utils.sleep(2100); + await scheduler.wait(2100); const logdir = app.config.logger.dir; const log = fs.readFileSync(path.join(logdir, 'ctx-background-web.log'), 'utf8'); assert(/mock background run at app result file size: \d+/.test(log)); assert(/mock background run at app anonymous result file size: \d+/.test(log)); assert( - /\[egg:background] task:.*?app[\/\\]controller[\/\\]app\.js:\d+:\d+ success \([\d\.]+ms\)/.test(fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8')) + /\[egg:background] task:.*?app[\/\\]controller[\/\\]app\.js:\d+:\d+ success \([\d\.]+ms\)/.test(fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8')), ); }); }); describe('app.runInAnonymousContextScope(scope)', () => { it('should run task in anonymous context scope success', async () => { - const app = utils.app('apps/app-runInAnonymousContextScope'); + const app = createApp('apps/app-runInAnonymousContextScope'); await app.ready(); await app.close(); - await utils.sleep(2100); + await scheduler.wait(2100); const logdir = app.config.logger.dir; const logs = fs.readFileSync(path.join(logdir, 'app-runInAnonymousContextScope-web.log'), 'utf8').split('\n'); // console.log(logs); // 2022-12-15 23:00:08,551 INFO 86728 [-/127.0.0.1/-/1ms GET /] before close on ctx logger // 2022-12-15 23:00:08,551 INFO 86728 [-/127.0.0.1/-/1ms GET /] before close on app logger // 2022-12-15 23:03:16,086 INFO 89216 outside before close on app logger - assert.match(logs[0], / INFO \d+ \[-\/127.0.0.1\/-\/\d+ms GET \/] inside before close on ctx logger/); - assert.match(logs[1], / INFO \d+ \[-\/127.0.0.1\/-\/\d+ms GET \/] inside before close on app logger/); + assert.match(logs[0], / INFO \d+ \[-\/127.0.0.1\/-\/[\d\.]+ms GET \/] inside before close on ctx logger/); + assert.match(logs[1], / INFO \d+ \[-\/127.0.0.1\/-\/[\d\.]+ms GET \/] inside before close on app logger/); assert.match(logs[2], / INFO \d+ outside before close on app logger/); }); }); describe('app.runInAnonymousContextScope(scope,request)', () => { it('should run task in anonymous context scope with req success', async () => { - const app = utils.app('apps/app-runInAnonymousContextScope-withRequest'); + const app = createApp('apps/app-runInAnonymousContextScope-withRequest'); await app.ready(); await app.close(); - await utils.sleep(2100); + await scheduler.wait(2100); const logdir = app.config.logger.dir; const logs = fs.readFileSync(path.join(logdir, 'app-runInAnonymousContextScope-withRequest-web.log'), { encoding: 'utf8' }).split('\n'); - assert.match(logs[0], / INFO \d+ \[-\/127.0.0.2\/-\/\d+ms GET \/] inside before close on ctx logger/); - assert.match(logs[1], / INFO \d+ \[-\/127.0.0.2\/-\/\d+ms GET \/] inside before close on app logger/); + assert.match(logs[0], / INFO \d+ \[-\/127.0.0.2\/-\/[\d\.]+ms GET \/] inside before close on ctx logger/); + assert.match(logs[1], / INFO \d+ \[-\/127.0.0.2\/-\/[\d\.]+ms GET \/] inside before close on app logger/); assert.match(logs[2], / INFO \d+ outside before close on app logger/); }); }); describe('app.handleRequest(ctx, fnMiddleware)', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/demo'); + app = createApp('apps/demo'); return app.ready(); }); after(() => app.close()); it('should wait for middleware resolution', async () => { const ctx = app.createAnonymousContext(); - await app.handleRequest(ctx, async ctx => { - await utils.sleep(100); + await app.handleRequest(ctx, async (ctx: any) => { + await scheduler.wait(100); ctx.body = 'middleware resolution'; }); assert(ctx.body === 'middleware resolution'); @@ -242,9 +243,9 @@ describe('test/app/extend/application.test.js', () => { }); describe('app.keys', () => { - let app; + let app: MockApplication; before(() => { - app = utils.app('apps/demo'); + app = createApp('apps/demo'); return app.ready(); }); after(() => app.close()); diff --git a/test/lib/application.test.js b/test/lib/application.test.js index e6ff7118bf..3474fc2128 100644 --- a/test/lib/application.test.js +++ b/test/lib/application.test.js @@ -124,7 +124,7 @@ describe('test/lib/application.test.js', () => { .expect('foo') .expect(200); - await utils.sleep(1100); + await scheduler.wait(1100); const logfile = path.join(utils.getFilepath('apps/app-throw'), 'logs/app-throw/common-error.log'); const body = fs.readFileSync(logfile, 'utf8'); assert(body.includes('ReferenceError: a is not defined (uncaughtException throw')); @@ -145,7 +145,7 @@ describe('test/lib/application.test.js', () => { .expect('foo') .expect(200); - await utils.sleep(1100); + await scheduler.wait(1100); const logfile = path.join(utils.getFilepath('apps/app-throw'), 'logs/app-throw/common-error.log'); const body = fs.readFileSync(logfile, 'utf8'); assert(body.includes('abc (uncaughtException throw 1 times on pid')); @@ -156,7 +156,7 @@ describe('test/lib/application.test.js', () => { it('should warn if confused configurations exist', async () => { const app = utils.app('apps/confused-configuration'); await app.ready(); - await utils.sleep(1000); + await scheduler.wait(1000); const logs = fs.readFileSync(utils.getFilepath('apps/confused-configuration/logs/confused-configuration/confused-configuration-web.log'), 'utf8'); assert(logs.match(/Unexpected config key `bodyparser` exists, Please use `bodyParser` instead\./)); assert(logs.match(/Unexpected config key `notFound` exists, Please use `notfound` instead\./)); diff --git a/test/lib/cluster/app_worker.test.js b/test/lib/cluster/app_worker.test.js index 9e75d8817e..4e7fca4939 100644 --- a/test/lib/cluster/app_worker.test.js +++ b/test/lib/cluster/app_worker.test.js @@ -120,7 +120,7 @@ describe('test/lib/cluster/app_worker.test.js', () => { it('should not log when there is no rawPacket', async () => { await connect(app.port); - await utils.sleep(1000); + await scheduler.wait(1000); app.expect('stderr', /HPE_INVALID_EOF_STATE/); app.notExpect('stderr', /A client/); }); diff --git a/test/lib/cluster/cluster-client-error.test.js b/test/lib/cluster/cluster-client-error.test.js index fc68029cca..6770fec434 100644 --- a/test/lib/cluster/cluster-client-error.test.js +++ b/test/lib/cluster/cluster-client-error.test.js @@ -22,7 +22,7 @@ describe('test/lib/cluster/cluster-client-error.test.js', () => { }); it('should follower not throw error', async () => { - await utils.sleep(1000); + await scheduler.wait(1000); const cnt = await readFile(path.join(__dirname, '../../fixtures/apps/cluster-client-error/logs/cluster-client-error/common-error.log'), 'utf8'); assert(!cnt.includes('ECONNRESET')); }); diff --git a/test/lib/cluster/master.test.js b/test/lib/cluster/master.test.js index ef5f465979..679215e2ff 100644 --- a/test/lib/cluster/master.test.js +++ b/test/lib/cluster/master.test.js @@ -24,7 +24,7 @@ describe('test/lib/cluster/master.test.js', () => { } // wait for app worker restart - await utils.sleep(5000); + await scheduler.wait(5000); // error pipe to console app.expect('stdout', /app_worker#1:\d+ disconnect/); @@ -42,7 +42,7 @@ describe('test/lib/cluster/master.test.js', () => { } // wait for app worker restart - await utils.sleep(5000); + await scheduler.wait(5000); app.expect('stderr', /\[graceful:worker:\d+:uncaughtException] throw error 1 times/); app.expect('stdout', /app_worker#\d:\d+ started/); @@ -68,7 +68,7 @@ describe('test/lib/cluster/master.test.js', () => { } // wait for app worker restart - await utils.sleep(5000); + await scheduler.wait(5000); // error pipe to console app.notExpect('stdout', /app_worker#1:\d+ disconnect/); @@ -83,7 +83,7 @@ describe('test/lib/cluster/master.test.js', () => { } // wait for app worker restart - await utils.sleep(5000); + await scheduler.wait(5000); app.expect('stderr', /\[graceful:worker:\d+:uncaughtException] throw error 1 times/); app.expect('stderr', /matches ignore list/); diff --git a/test/lib/core/dnscache_httpclient.test.js b/test/lib/core/dnscache_httpclient.test.js index 4b80ff0058..48b27991c1 100644 --- a/test/lib/core/dnscache_httpclient.test.js +++ b/test/lib/core/dnscache_httpclient.test.js @@ -163,7 +163,7 @@ describe('test/lib/core/dnscache_httpclient.test.js', () => { record = app.httpclient.dnsCache.get('localhost'); assert(timestamp === record.timestamp); - await utils.sleep(5500); + await scheduler.wait(5500); obj = urlparse(url + '/get_headers'); result = await app.curl(obj, { dataType: 'json' }); assert(result.status === 200); @@ -193,7 +193,7 @@ describe('test/lib/core/dnscache_httpclient.test.js', () => { record = agent.httpclient.dnsCache.get('localhost'); assert(timestamp === record.timestamp); - await utils.sleep(5500); + await scheduler.wait(5500); obj = urlparse(url + '/get_headers'); result = await agent.curl(obj, { dataType: 'json' }); assert(result.status === 200); diff --git a/test/lib/core/httpclient_tracer_demo.test.js b/test/lib/core/httpclient_tracer_demo.test.js index 1ba8876363..c3e6c08863 100644 --- a/test/lib/core/httpclient_tracer_demo.test.js +++ b/test/lib/core/httpclient_tracer_demo.test.js @@ -45,7 +45,7 @@ describe('test/lib/core/httpclient_tracer_demo.test.js', () => { assert(res.body.data['x-request-id'].startsWith('anonymous-')); }) .expect(200); - await utils.sleep(2000); - app.expectLog(/ INFO \d+ \[-\/127.0.0.1\/mock-traceId-123123\/\d+ms GET \/foo\?url=http%3A%2F%2F127.0.0.1%3A\d+%2Fget_headers] app logger support traceId/); + await scheduler.wait(2000); + app.expectLog(/ INFO \d+ \[-\/127.0.0.1\/mock-traceId-123123\/[\d\.]+ms GET \/foo\?url=http%3A%2F%2F127.0.0.1%3A\d+%2Fget_headers] app logger support traceId/); }); }); diff --git a/test/lib/core/logger.test.js b/test/lib/core/logger.test.js index 81415ca31b..7383734336 100644 --- a/test/lib/core/logger.test.js +++ b/test/lib/core/logger.test.js @@ -9,7 +9,7 @@ describe('test/lib/core/logger.test.js', () => { let app; afterEach(async () => { if (app) { - await utils.sleep(5000); + await scheduler.wait(5000); await app.close(); app = null; } @@ -106,7 +106,7 @@ describe('test/lib/core/logger.test.js', () => { const logfile = path.join(app.config.logger.dir, 'common-error.log'); // app.config.logger.buffer.should.equal(false); ctx.logger.error(new Error('mock nobuffer error')); - await utils.sleep(1000); + await scheduler.wait(1000); if (process.platform !== 'darwin') { // skip check on macOS assert( @@ -128,7 +128,7 @@ describe('test/lib/core/logger.test.js', () => { // app.config.logger.buffer.should.equal(true); ctx.logger.error(new Error('mock enable buffer error')); - await utils.sleep(1000); + await scheduler.wait(1000); assert(fs.readFileSync(logfile, 'utf8').includes('')); }); @@ -143,7 +143,7 @@ describe('test/lib/core/logger.test.js', () => { const logfile = path.join(app.config.logger.dir, 'logger-output-json-web.json.log'); ctx.logger.info('json format'); - await utils.sleep(2000); + await scheduler.wait(2000); assert(fs.existsSync(logfile)); assert(fs.readFileSync(logfile, 'utf8').includes('"message":"json format"')); @@ -187,7 +187,7 @@ describe('test/lib/core/logger.test.js', () => { // .debug() .coverage(false) .end(async err => { - await utils.sleep(1000); + await scheduler.wait(1000); assert(!err); const content = fs.readFileSync(path.join(baseDir, 'logs/logger/common-error.log'), 'utf8'); assert(content.includes('nodejs.Error: agent error')); @@ -205,7 +205,7 @@ describe('test/lib/core/logger.test.js', () => { app.loggers.errorLogger.error(new Error('errorLogger error')); app.loggers.customLogger.error(new Error('customLogger error')); - await utils.sleep(1000); + await scheduler.wait(1000); const content = fs.readFileSync(path.join(app.baseDir, 'logs/logger/common-error.log'), 'utf8'); assert(content.includes('nodejs.Error: logger error')); @@ -235,7 +235,7 @@ describe('test/lib/core/logger.test.js', () => { .expect({ enableFastContextLogger: true, }); - await utils.sleep(1000); + await scheduler.wait(1000); app.expectLog(/ INFO \d+ \[-\/127\.0\.0\.1\/mock-trace-id-123\/[\d\.]+ms GET \/] enableFastContextLogger: true/); }); @@ -276,7 +276,7 @@ describe('test/lib/core/logger.test.js', () => { ok: true, }) .expect(200); - await utils.sleep(1000); + await scheduler.wait(1000); app.expectLog('[custom-logger-label] hello myLogger', 'myLogger'); app.expectLog('hello logger'); }); diff --git a/test/lib/core/messenger/ipc.test.js b/test/lib/core/messenger/ipc.test.js index ab34031128..e34812b8de 100644 --- a/test/lib/core/messenger/ipc.test.js +++ b/test/lib/core/messenger/ipc.test.js @@ -59,7 +59,7 @@ describe('test/lib/core/messenger/ipc.test.js', () => { app = utils.cluster('apps/messenger'); app.coverage(true); await app.ready(); - await utils.sleep(1000); + await scheduler.wait(1000); }); it('app should accept agent message', () => { @@ -120,7 +120,7 @@ describe('test/lib/core/messenger/ipc.test.js', () => { after(() => app.close()); it('app should accept agent message', async () => { - await utils.sleep(10000); + await scheduler.wait(10000); const m = app.stdout.match(/\d+=\d+/g); const map = new Map(); diff --git a/test/lib/egg.test.js b/test/lib/egg.test.js index 66ab0ed35f..0c7949cb5f 100644 --- a/test/lib/egg.test.js +++ b/test/lib/egg.test.js @@ -17,7 +17,7 @@ describe('test/lib/egg.test.js', () => { app = utils.app('apps/demo'); await app.ready(); // CI 环境 Windows 写入磁盘需要时间 - await utils.sleep(1100); + await scheduler.wait(1100); }); after(() => app.close()); @@ -173,7 +173,7 @@ describe('test/lib/egg.test.js', () => { await Promise.all([ utils.rimraf(path.join(baseDir, 'run')), utils.rimraf(path.join(baseDir, 'logs')) ]); const app = utils.app(baseDir); await app.ready(); - await utils.sleep(100); + await scheduler.wait(100); assertFile(path.join(baseDir, `run/application_timing_${process.pid}.json`)); assertFile(path.join(baseDir, 'logs/dumptiming-timeout/common-error.log'), /unfinished timing item: {"name":"Did Load in app.js:didLoad"/); }); @@ -183,7 +183,7 @@ describe('test/lib/egg.test.js', () => { await Promise.all([ utils.rimraf(path.join(baseDir, 'run')), utils.rimraf(path.join(baseDir, 'logs')) ]); const app = utils.app(baseDir); await app.ready(); - await utils.sleep(100); + await scheduler.wait(100); assertFile(path.join(baseDir, 'logs/dumptiming-slowBootActionMinDuration/egg-web.log'), /\[egg:core]\[slow-boot-action] #\d+ \d+ms, name: Did Load in app\.js:didLoad/); }); }); @@ -233,7 +233,7 @@ describe('test/lib/egg.test.js', () => { it('should dump in config', async () => { const baseDir = utils.getFilepath('apps/dumpconfig-circular'); await app.ready(); - await utils.sleep(100); + await scheduler.wait(100); const json = readJson(path.join(baseDir, 'run/application_config.json')); assert.deepEqual(json.config.foo, [ '~config~foo' ]); }); @@ -286,7 +286,7 @@ describe('test/lib/egg.test.js', () => { afterEach(mm.restore); it('should custom dir', async () => { - await utils.sleep(1000); + await scheduler.wait(1000); assertFile(path.join(runDir, 'application_config.json')); assertFile(path.join(logDir, 'egg-web.log')); assertFile.fail(path.join(baseDir, 'run/application_config.json')); @@ -369,7 +369,7 @@ describe('test/lib/egg.test.js', () => { .expect(200); await Promise.all([ req1, req2, req3 ]); - await utils.sleep(1000); + await scheduler.wait(1000); const logfile = path.join(utils.getFilepath('apps/app-throw'), 'logs/app-throw/common-error.log'); const body = fs.readFileSync(logfile, 'utf8'); @@ -396,7 +396,7 @@ describe('test/lib/egg.test.js', () => { .expect('hello') .expect(200); - await utils.sleep(1000); + await scheduler.wait(1000); const logPath = path.join(utils.getFilepath('apps/base-context-class'), 'logs/base-context-class/base-context-class-web.log'); const log = fs.readFileSync(logPath, 'utf8'); diff --git a/test/lib/plugins/schedule.test.js b/test/lib/plugins/schedule.test.js index a5dc447763..c128be4d22 100644 --- a/test/lib/plugins/schedule.test.js +++ b/test/lib/plugins/schedule.test.js @@ -11,7 +11,7 @@ describe('test/lib/plugins/schedule.test.js', () => { app.debug(); app.coverage(false); await app.ready(); - await utils.sleep(7000); + await scheduler.wait(7000); await app.close(); const log = getLogContent('schedule'); const count = contains(log, 'cron wow'); diff --git a/test/lib/plugins/watcher.test.js b/test/lib/plugins/watcher.test.js index 28d5e414ae..f0ea9107fa 100644 --- a/test/lib/plugins/watcher.test.js +++ b/test/lib/plugins/watcher.test.js @@ -26,9 +26,9 @@ describe('test/lib/plugins/watcher.test.js', () => { .expect(200) .expect('app watch success'); - await utils.sleep(5000); + await scheduler.wait(5000); fs.writeFileSync(file_path1, 'aaa'); - await utils.sleep(5000); + await scheduler.wait(5000); await app.httpRequest() .get('/app-msg') @@ -40,7 +40,7 @@ describe('test/lib/plugins/watcher.test.js', () => { }); fs.writeFileSync(file_path2, 'aaa'); - await utils.sleep(5000); + await scheduler.wait(5000); await app.httpRequest() .get('/app-msg') @@ -60,7 +60,7 @@ describe('test/lib/plugins/watcher.test.js', () => { .expect('agent watch success'); fs.writeFileSync(file_path1_agent, 'bbb'); - await utils.sleep(5000); + await scheduler.wait(5000); await app.httpRequest() .get('/agent-msg') @@ -84,7 +84,7 @@ describe('test/lib/plugins/watcher.test.js', () => { after(() => app.close()); it('should warn user', async () => { - await utils.sleep(3000); + await scheduler.wait(3000); const logPath = utils.getFilepath('apps/watcher-type-default/logs/watcher-type-default/egg-agent.log'); const content = fs.readFileSync(logPath, 'utf8'); assert(content.includes('defaultEventSource watcher will NOT take effect'));