Skip to content

Commit

Permalink
test(toolkit): Stub all instances of process.hrtime in records perfom…
Browse files Browse the repository at this point in the history
…ance test (#5503)

## Problem
We're seeing some flakiness with the `TelemetrySpan records performance`
test. I _think_ it could be related to the fact we [stub certain calls
on
process.hrtime](https://github.com/aws/aws-toolkit-vscode/blob/master/packages/core/src/test/utilities/performance.ts#L21)
instead of stubbing all instances. This can potentially cause
[nodeClock](https://github.com/aws/aws-sdk-js/blob/master/lib/realclock/nodeClock.js#L4)
to use or not use stubbed values depending on when things are executed.

Previously we would see a failure this:
```
TypeError: Cannot read properties of undefined (reading '0')
    at Object.now (/codebuild/output/src575830969/src/github.com/aws/aws-toolkit-vscode/node_modules/aws-sdk/lib/realclock/nodeClock.js:5:18)
```

## Solution
Stub all instances of process.hrtime during that test
  • Loading branch information
jpinkney-aws authored Aug 28, 2024
1 parent 5afea02 commit 78423ea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/test/utilities/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function stubPerformance(sandbox: Sinon.SinonSandbox) {
.returns({ heapTotal: initialHeapTotal, arrayBuffers: 0, external: 0, rss: 0, heapUsed: 0 })
memoryUsageStub.onCall(1).returns({ heapTotal: 10485761, arrayBuffers: 0, external: 0, rss: 0, heapUsed: 0 })

sandbox.stub(process, 'hrtime').onCall(0).returns([0, 0]).onCall(1).returns([0, totalNanoseconds])
sandbox.stub(process, 'hrtime').returns([0, totalNanoseconds])

return {
expectedUserCpuUsage: 33.333333333333336,
Expand Down

0 comments on commit 78423ea

Please sign in to comment.