Skip to content

refactor: replace try/finally with t.after() hooks in tests#2800

Merged
brendandburns merged 2 commits intomax-regen-genfrom
copilot/sub-pr-2770-one-more-time
Mar 19, 2026
Merged

refactor: replace try/finally with t.after() hooks in tests#2800
brendandburns merged 2 commits intomax-regen-genfrom
copilot/sub-pr-2770-one-more-time

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

Test cleanup for undici MockAgent (close + restore global dispatcher) was done in try/finally blocks. Using t.after() is the idiomatic pattern for the Node.js built-in test runner and keeps cleanup co-located with setup rather than buried at the end of test logic.

Changes

  • src/integration_test.ts: Register t.after() hook immediately after setGlobalDispatcher(mockAgent) to close the agent and restore the original dispatcher
  • src/top_test.ts: Same refactor across all 9 test cases — hook registered right after systemUnderTest() (which internally calls setGlobalDispatcher)

Before

it('should ...', async () => {
    const originalDispatcher = getGlobalDispatcher();
    const [topPodsFunc, _, mockAgent] = systemUnderTest();
    // setup interceptors...
    try {
        const result = await topPodsFunc();
        // assertions...
    } finally {
        await mockAgent.close();
        setGlobalDispatcher(originalDispatcher);
    }
});

After

it('should ...', async (t) => {
    const originalDispatcher = getGlobalDispatcher();
    const [topPodsFunc, _, mockAgent] = systemUnderTest();
    t.after(async () => {
        await mockAgent.close();
        setGlobalDispatcher(originalDispatcher);
    });
    // setup interceptors...
    const result = await topPodsFunc();
    // assertions...
});

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI mentioned this pull request Mar 18, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 18, 2026
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 18, 2026
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 18, 2026
Copilot AI changed the title [WIP] [#2738] Adjust code for new OpenAPI generator refactor: replace try/finally with t.after() hooks in tests Mar 18, 2026
Copilot AI requested a review from brendandburns March 18, 2026 22:32
@brendandburns brendandburns marked this pull request as ready for review March 19, 2026 17:38
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 19, 2026
@brendandburns brendandburns merged commit 7d2213d into max-regen-gen Mar 19, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants