-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test: stabilize ci benchmark baseline #5908
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
Open
killagu
wants to merge
7
commits into
next
Choose a base branch
from
agent/egg-dev/8ea216e0
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1db165
test: stabilize ci benchmark baseline
killagu 9b7597f
test: avoid pnpm in root workspace scripts
killagu 28085fc
test: clarify manifest cache helper
killagu c2cec14
test: avoid duplicate root pretest workspace run
killagu a50a553
test: address ci stability review feedback
killagu 84f02d4
test: avoid schedule log read race
killagu f9bd11d
test: strengthen schedule stop assertion
killagu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,57 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { setTimeout as sleep } from 'node:timers/promises'; | ||
|
|
||
| import { mm, type MockApplication } from '@eggjs/mock'; | ||
| import { describe, it, afterAll, beforeAll, expect } from 'vitest'; | ||
|
|
||
| import { contains, getFixtures, getLogContent } from './utils.ts'; | ||
| import { contains, getFixtures } from './utils.ts'; | ||
|
|
||
| function readLogIfExists(logPath: string) { | ||
| try { | ||
| return readFileSync(logPath, 'utf8'); | ||
| } catch (err) { | ||
| const error = err as { code?: string }; | ||
| if (error.code === 'ENOENT') { | ||
| return ''; | ||
| } | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| async function waitForNewLog(logPath: string, match: string, previousLog: string, timeout = 5000) { | ||
| const start = Date.now(); | ||
| while (Date.now() - start < timeout) { | ||
| const log = readLogIfExists(logPath); | ||
| const appendedLog = log.startsWith(previousLog) ? log.slice(previousLog.length) : log; | ||
| if (appendedLog.includes(match)) { | ||
| return log; | ||
| } | ||
| await sleep(100); | ||
| } | ||
| throw new Error(`Log ${logPath} did not contain "${match}"`); | ||
| } | ||
|
|
||
| describe.skipIf(process.platform === 'win32')('test/stop.test.ts', () => { | ||
| let app: MockApplication; | ||
| let app: MockApplication | undefined; | ||
| let intervalLogBeforeStart = ''; | ||
| beforeAll(async () => { | ||
| intervalLogBeforeStart = readLogIfExists(getFixtures('stop/logs/stop/stop-web.log')); | ||
| app = mm.cluster({ baseDir: getFixtures('stop'), workers: 2 }); | ||
| // app.debug(); | ||
| await app.ready(); | ||
| }); | ||
| afterAll(() => app.close()); | ||
| afterAll(() => app?.close()); | ||
|
|
||
| it('should stop interval timer after cluster closes', async () => { | ||
| const logPath = getFixtures('stop/logs/stop/stop-web.log'); | ||
| await waitForNewLog(logPath, 'interval', intervalLogBeforeStart, 12000); | ||
|
|
||
| await app!.close(); | ||
| app = undefined; | ||
| const afterCloseCount = contains(readLogIfExists(logPath), 'interval'); | ||
|
|
||
| it('should thrown', async () => { | ||
| await sleep(10000); | ||
| const log = getLogContent('stop'); | ||
| expect(contains(log, 'interval')).toBe(0); | ||
| const log = readLogIfExists(logPath); | ||
| expect(contains(log, 'interval')).toBe(afterCloseCount); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { existsSync, readdirSync, readFileSync } from 'node:fs'; | ||
| import { join, resolve } from 'node:path'; | ||
|
|
||
| const script = process.argv[2]; | ||
| if (!script) { | ||
| console.error('Usage: node scripts/run-workspace-scripts.mjs <script>'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const root = resolve(import.meta.dirname, '..'); | ||
| const workspaceFile = join(root, 'pnpm-workspace.yaml'); | ||
|
|
||
| function readWorkspacePatterns() { | ||
| const patterns = []; | ||
| let inPackages = false; | ||
|
|
||
| for (const line of readFileSync(workspaceFile, 'utf8').split('\n')) { | ||
| if (line.trim() === 'packages:') { | ||
| inPackages = true; | ||
| continue; | ||
| } | ||
| if (inPackages && line.length > 0 && !line.startsWith(' ')) { | ||
| break; | ||
| } | ||
|
|
||
| const match = /^\s+-\s+(.+?)\s*$/.exec(line); | ||
| if (inPackages && match) { | ||
| patterns.push(match[1].replace(/^['"]|['"]$/g, '')); | ||
| } | ||
| } | ||
|
|
||
| return patterns.sort((a, b) => a.localeCompare(b)); | ||
| } | ||
|
|
||
| function expandWorkspacePattern(pattern) { | ||
| if (!pattern.endsWith('/*')) { | ||
| return [join(root, pattern)]; | ||
| } | ||
|
|
||
| const baseDir = join(root, pattern.slice(0, -2)); | ||
| return readdirSync(baseDir, { withFileTypes: true }) | ||
| .filter((entry) => entry.isDirectory()) | ||
| .sort((a, b) => a.name.localeCompare(b.name)) | ||
| .map((entry) => join(baseDir, entry.name)); | ||
| } | ||
|
|
||
| let matched = 0; | ||
| const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm'; | ||
|
|
||
| for (const workspaceDir of readWorkspacePatterns().flatMap(expandWorkspacePattern)) { | ||
| const packageJsonPath = join(workspaceDir, 'package.json'); | ||
| if (!existsSync(packageJsonPath)) { | ||
| continue; | ||
| } | ||
|
|
||
| const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); | ||
| if (!packageJson.scripts?.[script]) { | ||
| continue; | ||
| } | ||
|
|
||
| matched++; | ||
| console.log(`> ${packageJson.name ?? workspaceDir} ${script}`); | ||
| const result = spawnSync(npmCommand, ['run', '--silent', script], { | ||
| cwd: workspaceDir, | ||
| stdio: 'inherit', | ||
| }); | ||
| if (result.status !== 0) { | ||
| process.exit(result.status ?? 1); | ||
| } | ||
| } | ||
|
|
||
| if (matched === 0) { | ||
| console.log(`No workspace scripts found for "${script}"`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.