Skip to content

Commit c900c12

Browse files
committed
fix(testing-drivers): count outstanding partitions across the whole job list
`hookPreaggs` is the twin of the loop the previous commit fixed, and had the same defect plus a worse one. `postBuildJobs` returns one token per partition and the outstanding tally was tested inside the loop over them, so a first token reporting `done` resolved the build while later partitions were still scheduled - the suite then queried a rollup table that did not exist yet. Count over the whole array instead. The `failure` branch also rejected without stopping the poll, and an empty job list never settled at all because the check lived in a loop body that never ran; both follow from the same restructuring. Verified with the postgres-core suite, which is what exercises this function: 6 passed, snapshots unchanged, so the recorded driver calls are identical. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VDVoT5YNCrewPZ87jyzmkF
1 parent bd1e4e1 commit c900c12

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

packages/cubejs-testing-drivers/src/helpers/buildPreaggs.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ export async function hookPreaggs(
178178
);
179179

180180
return new Promise((resolve, reject) => {
181+
let timeout: NodeJS.Timeout;
182+
let stop: () => void;
181183
const interval = setInterval(async () => {
182-
const inProcess = [];
183184
const selectors: {
184185
token: string,
185186
table: string,
@@ -196,22 +197,31 @@ export async function hookPreaggs(
196197
tokens,
197198
);
198199

199-
selectors.forEach((info) => {
200-
const { status } = info;
201-
if (status.indexOf('failure') >= 0) {
202-
reject(`Cube pre-aggregations build failed: ${status}`);
203-
}
204-
if (status !== 'done' && status !== 'missing_partition') {
205-
inProcess.push(info);
206-
}
207-
if (inProcess.length === 0) {
208-
clearInterval(interval);
209-
resolve(true);
210-
}
211-
});
200+
const failed = selectors.find((info) => info.status.indexOf('failure') >= 0);
201+
if (failed) {
202+
stop();
203+
reject(`Cube pre-aggregations build failed: ${failed.status}`);
204+
return;
205+
}
206+
// Counted over the whole array rather than inside a loop over it.
207+
// `postBuildJobs` returns one token per partition, and the tally used to be
208+
// tested after each element, so a first token reporting `done` resolved the
209+
// build while later partitions were still scheduled - and the suite then
210+
// queried a rollup table that did not exist yet.
211+
const inProcess = selectors.filter(
212+
(info) => info.status !== 'done' && info.status !== 'missing_partition'
213+
);
214+
if (inProcess.length === 0) {
215+
stop();
216+
resolve(true);
217+
}
212218
}, 1000);
213219

214-
setTimeout(() => {
220+
stop = () => {
221+
clearInterval(interval);
222+
clearTimeout(timeout);
223+
};
224+
timeout = setTimeout(() => {
215225
clearInterval(interval);
216226
reject('Cube pre-aggregations build failed: timeout.');
217227
}, 60000);

0 commit comments

Comments
 (0)