Skip to content

Commit 529cb5c

Browse files
committed
test: isolate schedule warnings and DAL fixture cleanup
1 parent be66a84 commit 529cb5c

5 files changed

Lines changed: 73 additions & 26 deletions

File tree

‎plugins/schedule/test/fixtures/unknown/agent.js‎

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import { setTimeout as sleep } from 'node:timers/promises';
2-
31
import { mm, type MockApplication } from '@eggjs/mock';
4-
import { describe, it, afterAll, beforeAll, expect } from 'vitest';
2+
import { describe, it, afterAll, beforeAll } from 'vitest';
53

6-
import { getFixtures, getScheduleLogContent } from './utils.ts';
4+
import { getFixtures } from './utils.ts';
75

8-
// TODO: flaky test on windows, Hook timed out in 20000ms
9-
describe.skipIf(process.platform === 'win32')('test/unknown.test.ts', () => {
6+
describe('test/unknown.test.ts', () => {
107
let app: MockApplication;
118
beforeAll(async () => {
12-
app = mm.cluster({ baseDir: getFixtures('unknown'), workers: 2 });
13-
// app.debug();
9+
app = mm.app({ baseDir: getFixtures('unknown') });
1410
await app.ready();
11+
app.mockLog('scheduleLogger');
12+
});
13+
afterAll(async () => {
14+
await app.close();
15+
await mm.restore();
1516
});
16-
afterAll(() => app.close());
1717

18-
it('should schedule unknown task', async () => {
19-
await sleep(3000);
20-
expect(getScheduleLogContent('unknown')).toMatch(/no-exist unknown task/);
18+
it('should warn about an unknown task', async () => {
19+
// Await the registered async message handler, including its app.ready() wait.
20+
// No cluster boot, IPC timer or file flush is needed to test the unknown-task branch.
21+
for (const listener of app.messenger.listeners('egg-schedule')) {
22+
await listener({ key: 'no-exist' });
23+
}
24+
app.expectLog(/no-exist unknown task/, 'scheduleLogger');
2125
});
2226
});

‎tegg/plugin/dal/test/transaction.test.ts‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ import { mm, type MockApplication } from '@eggjs/mock';
33
import { describe, afterEach, beforeAll, afterAll, it, expect } from 'vitest';
44

55
import FooDAO from './fixtures/apps/dal-app/modules/dal/dal/dao/FooDAO.ts';
6+
import { Foo } from './fixtures/apps/dal-app/modules/dal/Foo.ts';
67
import { FooService } from './fixtures/apps/dal-app/modules/dal/FooService.ts';
78
import { getFixtures } from './utils.ts';
89

910
describe('plugin/dal/test/transaction.test.ts', () => {
1011
let app: MockApplication;
1112

13+
async function cleanTransactionRows(): Promise<void> {
14+
const mysqlDataSourceManager = await app.getEggObjectFromName<MysqlDataSourceManager>('mysqlDataSourceManager');
15+
const dataSource = mysqlDataSourceManager.get('dal', 'foo')!;
16+
// The CRUD suite uses this database concurrently. Only delete rows owned by this suite.
17+
await dataSource.query('delete from egg_foo where name in (?, ?, ?, ?)', [
18+
'insert_succeed_transaction_1',
19+
'insert_succeed_transaction_2',
20+
'insert_failed_transaction_1',
21+
'insert_failed_transaction_2',
22+
]);
23+
}
24+
1225
afterEach(async () => {
1326
return mm.restore();
1427
});
@@ -20,16 +33,28 @@ describe('plugin/dal/test/transaction.test.ts', () => {
2033
await app.ready();
2134
}, 30_000);
2235

23-
afterEach(async () => {
24-
const mysqlDataSourceManager = await app.getEggObjectFromName<MysqlDataSourceManager>('mysqlDataSourceManager');
25-
const dataSource = mysqlDataSourceManager.get('dal', 'foo')!;
26-
await dataSource.query('delete from egg_foo;');
27-
});
36+
afterEach(cleanTransactionRows);
2837

2938
afterAll(() => {
3039
return app.close();
3140
});
3241

42+
it('should preserve unrelated rows when cleaning transaction fixtures', async () => {
43+
await app.mockModuleContextScope(async () => {
44+
const fooDao = await app.getEggObject(FooDAO);
45+
const foo = Foo.buildObj();
46+
foo.name = 'unrelated_transaction_cleanup';
47+
const { insertId } = await fooDao.insert(foo);
48+
try {
49+
await cleanTransactionRows();
50+
expect((await fooDao.findByPrimary(insertId))?.id).toBe(insertId);
51+
expect((await fooDao.delete(insertId)).affectedRows).toBe(1);
52+
} finally {
53+
await fooDao.delete(insertId);
54+
}
55+
});
56+
});
57+
3358
describe('succeed transaction', () => {
3459
it('should commit', async () => {
3560
await app.mockModuleContextScope(async () => {

‎wiki/log.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,15 @@ Full **isolate:false suite validated GREEN** under CI-faithful parallelism (`--m
597597
- Refreshed [Local CI](./workflows/local-ci.md) to describe the targeted Windows job and scripts-only build prerequisite.
598598

599599
- Windows source-level regression tests skip the Linux CLI build step: utoo interprets its tsdown path filter as a workspace selection on Windows, while these tests do not require `dist`.
600+
601+
## 2026-10-06 — next integration CI resource isolation
602+
603+
- Investigated run 37452813940 at 170ec7f3: the unknown-task log was empty after
604+
a Watcher leader port collision killed the agent; DAL transaction teardown
605+
could delete the concurrent CRUD suite's row. The DAL failure was reproduced
606+
with an isolated MySQL 8 service, and the cleanup regression fails with the
607+
old unqualified DELETE.
608+
- Scoped transaction cleanup to its fixture names and made the unknown-task
609+
warning test await the registered handler with captured logs. Refreshed
610+
[Local CI](./workflows/local-ci.md) with resource ownership and startup-error
611+
triage. Cluster port allocation races remain outside this test correction.

‎wiki/workflows/local-ci.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ source_files:
2020
- tegg/core/loader/src/impl/ModuleLoader.ts
2121
- tegg/core/metadata/src/model/graph/GlobalGraph.ts
2222
- tegg/plugin/controller/test/fixtures/apps
23+
- plugins/schedule/test/unknown.test.ts
24+
- tegg/plugin/dal/test/transaction.test.ts
25+
- https://github.com/eggjs/egg/actions/runs/37452813940
2326
updated_at: 2026-10-06
2427
status: active
2528
---
@@ -170,3 +173,15 @@ test service when sharing a host with other tasks. The 2026-10-06 retry used a
170173
temporary exact-source-restored port override into a separate local container.
171174
Sources: tegg/plugin/orm/test/fixtures/prepare.js and
172175
tegg/plugin/orm/test/fixtures/apps/orm-app/config/config.default.ts.
176+
177+
For parallel DAL plugin tests, cleanup must delete only the transaction suite's
178+
four named fixture rows. Its CRUD suite shares `test_dal_plugin.egg_foo`, so an
179+
unqualified DELETE can remove a row between the CRUD suite's insert and delete.
180+
The transaction cleanup regression checks that an unrelated row survives.
181+
182+
When a schedule log assertion is empty, inspect cluster startup errors first.
183+
Run 37452813940's Ubuntu Node.js 24 job reported a Watcher leader port collision
184+
and agent exit before the unknown-task assertion. The unknown-task test now
185+
awaits the real application's registered message handler and captures its
186+
schedule logger in memory. This tests the warning branch without depending on
187+
cluster startup or a fixed sleep; it does not fix cluster port allocation races.

0 commit comments

Comments
 (0)