Skip to content

Commit fde2fe5

Browse files
authored
test(ec2): fix flaky tests regarding child node updates. (#5698)
## Problem The issue is here: https://github.com/aws/aws-toolkit-vscode/blob/9eea1f3700930df79620ef26ff6a43450e593580/packages/core/src/awsService/ec2/explorer/ec2ParentNode.ts#L55-L64 This fires off multiple asynchronous calls on each child, with the function returning before any are resolved. Thus, the child node could be deleted from the set after this function returned (potentially when another piece of code is using it). This leads to `undefined` errors within that function. ## Solution Refactor the code to make use of a `for...of` with `await` pattern. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 27f869b commit fde2fe5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

packages/core/src/awsService/ec2/explorer/ec2ParentNode.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ export class Ec2ParentNode extends AWSTreeNodeBase {
5252
)
5353
}
5454

55-
private updatePendingNodes() {
56-
this.pollingSet.forEach(async (instanceId) => {
55+
private async updatePendingNodes() {
56+
for (const instanceId of this.pollingSet.values()) {
5757
const childNode = this.ec2InstanceNodes.get(instanceId)!
58-
await childNode.updateStatus()
59-
if (!childNode.isPending()) {
60-
this.pollingSet.delete(instanceId)
61-
await childNode.refreshNode()
62-
}
63-
})
58+
await this.updatePendingNode(childNode)
59+
}
60+
}
61+
62+
private async updatePendingNode(node: Ec2InstanceNode) {
63+
await node.updateStatus()
64+
if (!node.isPending()) {
65+
this.pollingSet.delete(node.InstanceId)
66+
await node.refreshNode()
67+
}
6468
}
6569

6670
public async clearChildren() {

0 commit comments

Comments
 (0)