Skip to content

Commit 177aa07

Browse files
committed
ensure timer stops with tests
1 parent a5cf7f3 commit 177aa07

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/ec2/explorer/ec2ParentNode.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export class Ec2ParentNode extends AWSTreeNodeBase {
7575
}
7676
})
7777
this.refreshNode()
78+
if (!this.isPolling()) {
79+
this.clearPollTimer()
80+
}
81+
}
82+
83+
public clearPollTimer() {
84+
globals.clock.clearInterval(this.pollTimer!)
85+
this.pollTimer = undefined
7886
}
7987

8088
public async clearChildren() {

src/test/ec2/explorer/ec2ParentNode.test.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('ec2ParentNode', function () {
2222
let instances: Ec2Instance[]
2323
let clock: FakeTimers.InstalledClock
2424
let refreshStub: sinon.SinonStub<[], Promise<void>>
25+
let clearTimerStub: sinon.SinonStub<[], void>
2526

2627
const testRegion = 'testRegion'
2728
const testPartition = 'testPartition'
@@ -44,6 +45,7 @@ describe('ec2ParentNode', function () {
4445
before(function () {
4546
clock = installFakeClock()
4647
refreshStub = sinon.stub(Ec2ParentNode.prototype, 'refreshNode')
48+
clearTimerStub = sinon.stub(Ec2ParentNode.prototype, 'clearPollTimer')
4749
})
4850

4951
beforeEach(function () {
@@ -124,21 +126,12 @@ describe('ec2ParentNode', function () {
124126
sinon.assert.calledOn(refreshStub, testNode)
125127
})
126128

127-
// it('deletes node from polling set when state changes', async function () {
128-
// const mockChildNode: Ec2InstanceNode = mock()
129-
// when(mockChildNode.getStatus()).thenReturn('running')
130-
// testNode.startPolling(mockChildNode)
131-
// await clock.tickAsync(4000)
132-
// assert.strictEqual(testNode.isPolling(), false)
133-
// })
134-
135-
// it('stops polling once node status has been updated', async function () {
136-
// const mockChildNode: Ec2InstanceNode = mock()
137-
// when(mockChildNode.getStatus()).thenReturn('running')
138-
// testNode.startPolling(mockChildNode)
139-
// await clock.tickAsync(4000)
140-
// sinon.assert.calledOn(refreshStub, testNode)
141-
// await clock.tickAsync(4000)
142-
// sinon.assert.calledOnce(refreshStub)
143-
// })
129+
it('stops timer once polling nodes are empty', async function () {
130+
await testNode.updateChildren()
131+
assert.strictEqual(testNode.isPolling(), true)
132+
testNode.pollingNodes.delete('0')
133+
await clock.tickAsync(6000)
134+
assert.strictEqual(testNode.isPolling(), false)
135+
sinon.assert.calledOn(clearTimerStub, testNode)
136+
})
144137
})

0 commit comments

Comments
 (0)