Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: separte agent and application start time #278

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading