aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.52k stars 443 forks source link

test(flaky): fix unresolved promise causing linux failures #6088

Open Hweinstock opened 8 hours ago

Hweinstock commented 8 hours ago

Problem

https://github.com/aws/aws-toolkit-vscode/issues/6043 To reproduce, add a 5 second delay to the after hook at the top level. One way to do this is to insert this at line 84.

after(async function () {
        clock.uninstall()
        await sleep(5000)
    })

Despite asserting that the promise rejects within the test, the promise rejects after the test as well. Not entirely sure why this happening.

Solution

What does appear to work, is manually handling the callback of the promise. That is, explicitly defining a then and catch method to assert the rejection, and awaiting the promise at the end of the test to ensure it resolves before the test finishes. Not sure why this works, but I am unable to reproduce the error with this change.

Notes


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.