Skip to content

Commit 6852046

Browse files
authored
fix: separte agent and application start time (#278)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Updated the `README.md` for improved clarity and structure, including expanded sections on timing metrics and method descriptions. - **Bug Fixes** - Enhanced logging behavior in the application startup process to include application type in timing logs. - **Tests** - Updated test cases for asynchronous behavior in the `EggCore` application. - Adjusted assertions for timing events to reflect new naming conventions. - Cleaned up test files by removing commented-out code and preserving test structure. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 9d368d0 commit 6852046

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ EggCore record boot progress with `Timing`, include:
247247

248248
- Process start time
249249
- Script start time(node don't implement an interface like `process.uptime` to record the script start running time, framework can implement a prestart file used with node `--require` options to set `process.scriptTime`)
250-
- Application start time
250+
- `application start` or `agent start` time
251251
- Load duration
252252
- `require` duration
253253

src/lifecycle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class Lifecycle extends EventEmitter {
8585
this.#isClosed = false;
8686
this.#init = false;
8787

88-
this.timing.start('Application Start');
88+
this.timing.start(`${this.options.app.type} Start`);
8989
// get app timeout from env or use default timeout 10 second
9090
const eggReadyTimeoutEnv = parseInt(process.env.EGG_READY_TIMEOUT_ENV || '10000');
9191
assert(
@@ -105,7 +105,7 @@ export class Lifecycle extends EventEmitter {
105105
this.ready(err => {
106106
this.triggerDidReady(err);
107107
debug('app ready');
108-
this.timing.end('Application Start');
108+
this.timing.end(`${this.options.app.type} Start`);
109109
});
110110
}
111111

test/egg.test.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ describe.skip('test/egg.test.ts', () => {
1818
let app: EggCore;
1919
after(() => app && app.close());
2020

21-
it('should set options and _options', () => {
21+
it('should set options and _options', async () => {
2222
app = new EggCore();
2323
assert.equal((app as any)._options, undefined);
2424
assert.deepEqual(app.options, {
2525
baseDir: process.cwd(),
2626
type: 'application',
2727
});
28+
await app.loader.loadApplicationExtend();
29+
await app.ready();
2830
});
2931

3032
it('should use cwd when no options', () => {
@@ -214,7 +216,7 @@ describe.skip('test/egg.test.ts', () => {
214216
assert(id.includes(file));
215217
const timeline = app.timing.toString();
216218
console.log(timeline);
217-
assert.match(timeline, / \[\d+ms NOT_END] - #1 Application Start/);
219+
assert.match(timeline, / \[\d+ms NOT_END] - #1 application Start/);
218220
assert.match(timeline, / \[\d+ms NOT_END] - #14 Before Start in app.js:3:7/);
219221
done();
220222
});
@@ -469,7 +471,7 @@ describe.skip('test/egg.test.ts', () => {
469471
const json = app.timing.toJSON();
470472
assert(json.length === 28);
471473

472-
assert(json[1].name === 'Application Start');
474+
assert(json[1].name === 'application Start');
473475
assert(json[1].end! - json[1].start === json[1].duration);
474476
assert(json[1].pid === process.pid);
475477

@@ -528,7 +530,7 @@ describe.skip('test/egg.test.ts', () => {
528530
const json = app.timing.toJSON();
529531
assert(json.length === 14);
530532

531-
assert(json[1].name === 'Application Start');
533+
assert(json[1].name === 'agent Start');
532534
assert(json[1].end! - json[1].start === json[1].duration);
533535
assert(json[1].pid === process.pid);
534536

@@ -752,7 +754,7 @@ describe.skip('test/egg.test.ts', () => {
752754
]);
753755
console.log(app.timing.toString());
754756
assert.match(app.timing.toString(), /egg start timeline:/);
755-
assert.match(app.timing.toString(), /#1 Application Start/);
757+
assert.match(app.timing.toString(), /#1 application Start/);
756758
});
757759
});
758760

test/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as EggCore from '../src/index.js';
33

44
describe('test/index.test.ts', () => {
55
it('should expose properties', () => {
6-
console.log(EggCore);
6+
// console.log(EggCore);
77
assert(EggCore.EggCore);
88
assert(EggCore.EggLoader);
99
assert(EggCore.BaseContextClass);

0 commit comments

Comments
 (0)