Skip to content

Commit

Permalink
fix: separte agent and application start time (#278)
Browse files Browse the repository at this point in the history
<!-- 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 -->
  • Loading branch information
fengmk2 authored Dec 20, 2024
1 parent 9d368d0 commit 6852046
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ EggCore record boot progress with `Timing`, include:

- Process start time
- 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`)
- Application start time
- `application start` or `agent start` time
- Load duration
- `require` duration

Expand Down
4 changes: 2 additions & 2 deletions src/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Lifecycle extends EventEmitter {
this.#isClosed = false;
this.#init = false;

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

Expand Down
12 changes: 7 additions & 5 deletions test/egg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ describe.skip('test/egg.test.ts', () => {
let app: EggCore;
after(() => app && app.close());

it('should set options and _options', () => {
it('should set options and _options', async () => {
app = new EggCore();
assert.equal((app as any)._options, undefined);
assert.deepEqual(app.options, {
baseDir: process.cwd(),
type: 'application',
});
await app.loader.loadApplicationExtend();
await app.ready();
});

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

assert(json[1].name === 'Application Start');
assert(json[1].name === 'application Start');
assert(json[1].end! - json[1].start === json[1].duration);
assert(json[1].pid === process.pid);

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

assert(json[1].name === 'Application Start');
assert(json[1].name === 'agent Start');
assert(json[1].end! - json[1].start === json[1].duration);
assert(json[1].pid === process.pid);

Expand Down Expand Up @@ -752,7 +754,7 @@ describe.skip('test/egg.test.ts', () => {
]);
console.log(app.timing.toString());
assert.match(app.timing.toString(), /egg start timeline:/);
assert.match(app.timing.toString(), /#1 Application Start/);
assert.match(app.timing.toString(), /#1 application Start/);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as EggCore from '../src/index.js';

describe('test/index.test.ts', () => {
it('should expose properties', () => {
console.log(EggCore);
// console.log(EggCore);
assert(EggCore.EggCore);
assert(EggCore.EggLoader);
assert(EggCore.BaseContextClass);
Expand Down

0 comments on commit 6852046

Please sign in to comment.