From ecdf72184cdf677d72df86bfccc607e27a1c1cb1 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 21 Jan 2025 00:27:04 +0800 Subject: [PATCH] f --- .github/workflows/nodejs-other.yml | 18 --- package.json | 3 +- test/cluster1/master.test.ts | 210 +++++++++++++++++++++++++++++ test/cluster2/master.test.ts | 206 +--------------------------- 4 files changed, 212 insertions(+), 225 deletions(-) delete mode 100644 .github/workflows/nodejs-other.yml create mode 100644 test/cluster1/master.test.ts diff --git a/.github/workflows/nodejs-other.yml b/.github/workflows/nodejs-other.yml deleted file mode 100644 index cf4bd4ff67..0000000000 --- a/.github/workflows/nodejs-other.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: CI other - -on: - push: - branches: [ master, next ] - pull_request: - branches: [ master, next ] - -jobs: - Job: - name: Node.js - uses: node-modules/github-actions/.github/workflows/node-test.yml@master - with: - os: 'ubuntu-latest, windows-latest' - version: '18, 20' - test: 'npm run ci:other' - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/package.json b/package.json index d95d10a774..b40864d9b6 100644 --- a/package.json +++ b/package.json @@ -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}\"", diff --git a/test/cluster1/master.test.ts b/test/cluster1/master.test.ts new file mode 100644 index 0000000000..edb452af0e --- /dev/null +++ b/test/cluster1/master.test.ts @@ -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); + }); + }); +}); diff --git a/test/cluster2/master.test.ts b/test/cluster2/master.test.ts index 1ecb9b9ffb..9d09f0079f 100644 --- a/test/cluster2/master.test.ts +++ b/test/cluster2/master.test.ts @@ -1,7 +1,6 @@ import { scheduler } from 'node:timers/promises'; import { mm } from '@eggjs/mock'; -import coffee, { Coffee } from 'coffee'; -import { MockApplication, cluster, getFilepath } from '../utils.js'; +import { MockApplication, cluster } from '../utils.js'; describe('test/cluster2/master.test.ts', () => { afterEach(mm.restore); @@ -104,207 +103,4 @@ describe('test/cluster2/master.test.ts', () => { master.expect('code', 1).ready(done); }); }); - - 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); - }); - }); });