Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@rushstack/rush-daemon",
"comment": "Fix an early coalesced phased result writing its summary before the failed operation's output summarizer was closed.",
"type": "patch"
}
],
"packageName": "@rushstack/rush-daemon",
"email": "TheLarkInn@users.noreply.github.com"
}
22 changes: 14 additions & 8 deletions libraries/rush-daemon/src/PhasedRequestRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,21 @@ class PhasedRequestBatchCoordinator {
}
entry.unsubscribe?.();
entry.unsubscribe = undefined;
entry.finishPromise = this.#produceResultAsync(entry, true, undefined, [], undefined, true).catch(
(error: unknown) => {
// Unlike a batch-wide failure, an early result's failure concerns only this client.
if (!entry.completed) {
this.#completeEntry(entry);
entry.reject(error);
}
entry.finishPromise = this.#produceEarlyResultAsync(entry).catch((error: unknown) => {
// Unlike a batch-wide failure, an early result's failure concerns only this client.
if (!entry.completed) {
this.#completeEntry(entry);
entry.reject(error);
}
);
});
}

async #produceEarlyResultAsync(entry: IBatchEntry): Promise<void> {
// The sink is notified from the record's `finalizeOperation()`, which synchronously precedes the close of
// the record's StdioSummarizer and ProblemCollector. The summary reads the failure tail from the closed
// summarizer, so yield once to let the notifying record finish closing before the summary is written.
await Promise.resolve();
await this.#produceResultAsync(entry, true, undefined, [], undefined, true);
}

#requestIterationAbort(): void {
Expand Down
51 changes: 51 additions & 0 deletions libraries/rush-daemon/src/test/PhasedRequestSummary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,57 @@ describe('phased request summary', () => {
}
});

it('writes the failure summary before an early result while the coalesced batch continues', async () => {
let releaseC: () => void = () => undefined;
const cHeld: Promise<void> = new Promise<void>((resolve) => {
releaseC = resolve;
});
const fixture: ITestRoutingFixture = createRoutingFixture(
new Map([
[
OPERATION_A,
new TestOperationRunner(OPERATION_A, OperationStatus.Failure, async (terminal) =>
terminal.writeErrorLine('a-failure-detail')
)
],
[OPERATION_B, new TestOperationRunner(OPERATION_B)],
[OPERATION_C, new TestOperationRunner(OPERATION_C, OperationStatus.Success, () => cHeld)]
]),
[[OPERATION_B, OPERATION_A]]
);
fixture.graph.parallelism = 2;
try {
const router: PhasedRequestRouter = new PhasedRequestRouter(fixture.session);
const clientA: TestPhasedRequestClient = new TestPhasedRequestClient('one');
const clientC: TestPhasedRequestClient = new TestPhasedRequestClient('two');
const resultAPromise = router.executeAsync(createRequest('a', OPERATION_A), clientA);
const resultCPromise = router.executeAsync(createRequest('c', OPERATION_C), clientC);

const resultA = await resultAPromise;
// The early result is published while the shared iteration still runs the other client's selection.
expect(fixture.graph.status).toBe(OperationStatus.Executing);
expect(resultA).toMatchObject({ exitCode: 1, outcome: 'failure' });
const stdoutA: string = getActivity(clientA, 'stdout');
const summaryA: string = getSummary(stdoutA);
expect(summaryA).toContain('==[ FAILURE: 1 operation ]==');
expect(summaryA).toContain(`--[ FAILURE: ${OPERATION_A} ]--`);
expect(summaryA).toContain('a-failure-detail');
expect(summaryA).not.toContain(OPERATION_C);
expect(stdoutA).toMatch(DURATION_LINE);
expect(getActivity(clientA, 'stderr')).toContain('Operations failed.');
expect(clientA.writes[clientA.writes.length - 1].result).toBe(resultA);

releaseC();
const resultC = await resultCPromise;
expect(resultC).toMatchObject({ exitCode: 0, outcome: 'success' });
const summaryC: string = getSummary(getActivity(clientC, 'stdout'));
expect(summaryC).toContain('==[ SUCCESS: 1 operation ]==');
expect(summaryC).not.toContain(OPERATION_A);
} finally {
await fixture.session[Symbol.asyncDispose]();
}
});

it('gives each coalesced request a summary of only its own selection', async () => {
const fixture: ITestRoutingFixture = createFixture();
try {
Expand Down
Loading