Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 20, 2025
1 parent c2d1da0 commit ecdf721
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 225 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/nodejs-other.yml

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"prepublishOnly": "tshy && tshy-after && attw --pack --profile node16",
"ci:app": "npm run ci \"test/app/**/*.test.ts\"",
"ci:app": "npm run ci \"test/app/**/*.test.ts,test/*.test.ts\"",
"ci:cluster1": "npm run ci \"test/cluster1/**/*.test.ts\"",
"ci:cluster2": "npm run ci \"test/cluster2/**/*.test.ts\"",
"ci:lib": "npm run ci \"test/lib/**/*.test.ts\"",
"ci:other": "npm run ci \"test/*.test.ts\"",
"site:dev": "cross-env APP_ROOT=./site dumi dev",
"site:build": "cross-env APP_ROOT=./site dumi build",
"site:prettier": "prettier --config site/.prettierrc --ignore-path site/.prettierignore --write \"site/**/*.{js,jsx,tsx,ts,less,md,json}\"",
Expand Down
210 changes: 210 additions & 0 deletions test/cluster1/master.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import { mm } from '@eggjs/mock';
import coffee, { Coffee } from 'coffee';
import { MockApplication, cluster, getFilepath } from '../utils.js';

describe('test/cluster1/master.test.ts', () => {
afterEach(mm.restore);

describe('Master started log', () => {
let app: MockApplication;

afterEach(() => app.close());

it('should dev env stdout message include "Egg started"', done => {
app = cluster('apps/master-worker-started');
app.coverage(false);
app.expect('stdout', /Egg started/).ready(done);
});

it('should production env stdout message include "Egg started"', done => {
mm.env('prod');
mm.consoleLevel('NONE');
mm.home(getFilepath('apps/mock-production-app/config'));
app = cluster('apps/mock-production-app');
app.coverage(true);
app.expect('stdout', /Egg started/).ready(done);
});
});

describe('--cluster', () => {
let app: MockApplication;
before(() => {
mm.consoleLevel('NONE');
app = cluster('apps/cluster_mod_app');
app.coverage(false);
return app.ready();
});
after(() => app.close());

it('should online cluster mode startup success', () => {
return app.httpRequest()
.get('/')
.expect('hi cluster')
.expect(200);
});

it('should assign a free port by master', () => {
return app.httpRequest()
.get('/clusterPort')
.expect(/\d+/)
.expect(200);
});
});

describe('--dev', () => {
let app: MockApplication;
before(() => {
app = cluster('apps/cluster_mod_app');
app.coverage(false);
return app.ready();
});
after(() => app.close());

it('should dev cluster mode startup success', () => {
return app.httpRequest()
.get('/')
.expect('hi cluster')
.expect(200);
});
});

describe('multi-application in one server', () => {
let app1: MockApplication;
let app2: MockApplication;
before(async () => {
// mm.consoleLevel('NONE');
app1 = cluster('apps/cluster_mod_app');
app1.coverage(false);
app2 = cluster('apps/cluster_mod_app');
app2.coverage(false);
await Promise.all([
app1.ready(),
app2.ready(),
]);
});
after(async () => {
await Promise.all([
app1.close(),
app2.close(),
]);
});

it('should online cluster mode startup success, app1', () => {
return app1.httpRequest()
.get('/')
.expect('hi cluster')
.expect(200);
});

it('should assign a free port by master, app1', () => {
return app1.httpRequest()
.get('/clusterPort')
.expect(/\d+/)
.expect(200);
});

it('should online cluster mode startup success, app2', () => {
return app2.httpRequest()
.get('/')
.expect('hi cluster')
.expect(200);
});

it('should assign a free port by master, app2', () => {
return app2.httpRequest()
.get('/clusterPort')
.expect(/\d+/)
.expect(200);
});
});

describe('start app with custom env', () => {
describe('cluster mode, env: prod', () => {
let app: MockApplication;
before(() => {
mm.env('prod');
mm.home(getFilepath('apps/custom-env-app'));
app = cluster('apps/custom-env-app');
app.coverage(false);
return app.ready();
});
after(() => app.close());

it('should start with prod env', () => {
return app.httpRequest()
.get('/')
.expect({
env: 'prod',
})
.expect(200);
});
});
});

describe.skip('framework start', () => {
let app: MockApplication;
before(() => {
// dependencies relation:
// aliyun-egg-app -> aliyun-egg-biz -> aliyun-egg -> egg
mm.home(getFilepath('apps/aliyun-egg-app'));
app = cluster('apps/aliyun-egg-app', {
customEgg: getFilepath('apps/aliyun-egg-biz'),
});
app.coverage(false);
return app.ready();
});
after(() => app.close());

it('should start success', () => {
return app.httpRequest()
.get('/')
.expect({
'aliyun-egg-core': true,
'aliyun-egg-plugin': true,
'aliyun-egg-agent': true,
})
.expect(200);
});
});

describe('spawn start', () => {
let app: Coffee;
afterEach(() => {
// make sure process exit
(app as any).proc.kill('SIGTERM');
});

it('should not cause master die when agent start error', done => {
app = coffee.spawn('node', [ getFilepath('apps/agent-die/start.js') ]);

// spawn can't communication, so `end` event won't emit
setTimeout(() => {
app.emit('close', 0);
app.notExpect('stderr', /TypeError: process\.send is not a function/);
done();
}, 10000);
});

it.skip('should start without customEgg', done => {
app = coffee.fork(getFilepath('apps/master-worker-started/dispatch.js'));

setTimeout(() => {
app.emit('close', 0);
app.expect('stdout', /agent_worker#1:\d+ started /);
done();
}, 10000);
});

it.skip('should start without customEgg and worker_threads', done => {
app = coffee.fork(getFilepath('apps/master-worker-started-worker_threads/dispatch.js'))
.debug();

setTimeout(() => {
app.emit('close', 0);
app.expect('stdout', /agent_worker#1:\d+ started /);
app.expect('stdout', /"startMode":"worker_threads"/);
done();
}, 10000);
});
});
});
Loading

0 comments on commit ecdf721

Please sign in to comment.