Skip to content

Commit 9daba45

Browse files
CopilotLayZeeDK
andcommitted
Fix e2e benchmarks: use beforeEachIteration instead of afterEachIteration
Replace afterEachIteration with beforeEachIteration to ensure files are reset BEFORE each benchmark iteration runs, not after. This ensures files are always in the expected location when the benchmark starts, preventing "file not found" errors during warmup and actual benchmark runs. Co-authored-by: LayZeeDK <6364586+LayZeeDK@users.noreply.github.com>
1 parent d48b270 commit 9daba45

File tree

2 files changed

+47
-56
lines changed

2 files changed

+47
-56
lines changed

packages/workspace-e2e/src/performance-benchmark.bench.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ describe('Move-File Generator E2E Performance', () => {
9797
);
9898
});
9999

100-
afterEachIteration(() => {
101-
// Move files back to lib1 for next iteration
102-
[smallFileName, mediumFileName, largeFileName].forEach((fileName) => {
100+
beforeEachIteration(() => {
101+
// Ensure files are in lib1 before each iteration
102+
const fileContentMap: Map<string, string> = new Map([
103+
[smallFileName, smallFileContent],
104+
[mediumFileName, mediumFileContent],
105+
[largeFileName, largeFileContent],
106+
]);
107+
108+
fileContentMap.forEach((content, fileName) => {
103109
const lib2Path = join(
104110
projectDirectory,
105111
benchmarkLib2,
@@ -114,13 +120,9 @@ describe('Move-File Generator E2E Performance', () => {
114120
'lib',
115121
fileName,
116122
);
117-
try {
118-
const content = readFileSync(lib2Path, 'utf-8');
119-
writeFileSync(lib1Path, content);
120-
rmSync(lib2Path, { force: true });
121-
} catch {
122-
// File might not have been moved yet, ignore
123-
}
123+
// Always write the file to lib1 and remove from lib2
124+
writeFileSync(lib1Path, content);
125+
rmSync(lib2Path, { force: true });
124126
});
125127
});
126128

@@ -174,8 +176,8 @@ describe('Move-File Generator E2E Performance', () => {
174176
}
175177
});
176178

177-
afterEachIteration(() => {
178-
// Move files back to lib1
179+
beforeEachIteration(() => {
180+
// Ensure files are in lib1 before each iteration
179181
fileContents.forEach((content, fileName) => {
180182
const lib2Path = join(
181183
projectDirectory,
@@ -191,12 +193,9 @@ describe('Move-File Generator E2E Performance', () => {
191193
'lib',
192194
fileName,
193195
);
194-
try {
195-
writeFileSync(lib1Path, content);
196-
rmSync(lib2Path, { force: true });
197-
} catch {
198-
// File might not have been moved yet, ignore
199-
}
196+
// Always write the file to lib1 and remove from lib2
197+
writeFileSync(lib1Path, content);
198+
rmSync(lib2Path, { force: true });
200199
});
201200
});
202201

packages/workspace-e2e/src/performance-stress-test.bench.ts

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ describe('Move-File Generator E2E Stress Tests', () => {
114114
}
115115
});
116116

117-
afterEachIteration(() => {
117+
beforeEachIteration(() => {
118118
const projectCount = libs.length;
119-
// Move utility file back to first project
119+
// Ensure utility file is in first project before each iteration
120120
const movedPath = join(
121121
projectDirectory,
122122
libs[projectCount - 1],
@@ -132,24 +132,20 @@ describe('Move-File Generator E2E Stress Tests', () => {
132132
utilityFile,
133133
);
134134

135-
try {
136-
writeFileSync(originalPath, utilityContent);
137-
rmSync(movedPath, { force: true });
135+
writeFileSync(originalPath, utilityContent);
136+
rmSync(movedPath, { force: true });
138137

139-
// Reset index file
140-
const sourceIndexPath = join(
141-
projectDirectory,
142-
libs[0],
143-
'src',
144-
'index.ts',
145-
);
146-
writeFileSync(
147-
sourceIndexPath,
148-
`export * from './lib/${utilityFile.replace('.ts', '')}';\n`,
149-
);
150-
} catch {
151-
// File might not have been moved yet, ignore
152-
}
138+
// Reset index file
139+
const sourceIndexPath = join(
140+
projectDirectory,
141+
libs[0],
142+
'src',
143+
'index.ts',
144+
);
145+
writeFileSync(
146+
sourceIndexPath,
147+
`export * from './lib/${utilityFile.replace('.ts', '')}';\n`,
148+
);
153149
});
154150

155151
it('should efficiently move files across workspace with 10+ projects', () => {
@@ -241,8 +237,8 @@ describe('Move-File Generator E2E Stress Tests', () => {
241237
}
242238
});
243239

244-
afterEachIteration(() => {
245-
// Move file back to source library
240+
beforeEachIteration(() => {
241+
// Ensure file is in source library before each iteration
246242
const movedPath = join(
247243
projectDirectory,
248244
targetLib,
@@ -258,24 +254,20 @@ describe('Move-File Generator E2E Stress Tests', () => {
258254
targetFile,
259255
);
260256

261-
try {
262-
writeFileSync(originalPath, targetFileContent);
263-
rmSync(movedPath, { force: true });
257+
writeFileSync(originalPath, targetFileContent);
258+
rmSync(movedPath, { force: true });
264259

265-
// Reset index file
266-
const sourceIndexPath = join(
267-
projectDirectory,
268-
sourceLib,
269-
'src',
270-
'index.ts',
271-
);
272-
writeFileSync(
273-
sourceIndexPath,
274-
`export * from './lib/${targetFile.replace('.ts', '')}';\n`,
275-
);
276-
} catch {
277-
// File might not have been moved yet, ignore
278-
}
260+
// Reset index file
261+
const sourceIndexPath = join(
262+
projectDirectory,
263+
sourceLib,
264+
'src',
265+
'index.ts',
266+
);
267+
writeFileSync(
268+
sourceIndexPath,
269+
`export * from './lib/${targetFile.replace('.ts', '')}';\n`,
270+
);
279271
});
280272

281273
it('should efficiently process workspace with 100+ large files', () => {

0 commit comments

Comments
 (0)