Skip to content
Snippets Groups Projects
Unverified Commit 1c9d3d5c authored by chris48s's avatar chris48s Committed by GitHub
Browse files

tweaks to libraries.io token pooling code (#10074)

* decrease batch size

* set nextReset in seconds

* update test assertions
parent 2857d9bf
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ export default class LibrariesIoApiProvider {
})
if (this.withPooling) {
this.standardTokens = new TokenPool({ batchSize: 45 })
this.standardTokens = new TokenPool({ batchSize: 10 })
tokens.forEach(t => this.standardTokens.add(t, {}, defaultRateLimit))
}
}
......@@ -48,7 +48,8 @@ export default class LibrariesIoApiProvider {
// If the header is absent, we just use the current timestamp to
// advance the value to _something_
const retryAfter = headers['retry-after']
const nextReset = Date.now() + (retryAfter ? +retryAfter * 1000 : 0)
const nextReset =
((Date.now() + (retryAfter ? +retryAfter * 1000 : 0)) / 1000) >>> 0
return {
rateLimit,
......
......@@ -80,7 +80,7 @@ describe('LibrariesIoApiProvider', function () {
expect(token.update).to.have.been.calledWith(
remaining,
nextReset * 1000 + tickTime,
((nextReset * 1000 + tickTime) / 1000) >>> 0,
)
expect(token.invalidate).not.to.have.been.called
})
......@@ -98,7 +98,10 @@ describe('LibrariesIoApiProvider', function () {
const mockRequest = sinon.stub().resolves(response)
await provider.fetch(mockRequest, '/npm/badge-maker')
expect(token.update).to.have.been.calledWith(remaining, tickTime)
expect(token.update).to.have.been.calledWith(
remaining,
(tickTime / 1000) >>> 0,
)
expect(token.invalidate).not.to.have.been.called
})
......@@ -109,7 +112,10 @@ describe('LibrariesIoApiProvider', function () {
const mockRequest = sinon.stub().resolves(response)
await provider.fetch(mockRequest, '/npm/badge-maker')
expect(token.update).to.have.been.calledWith(remaining - 1, tickTime)
expect(token.update).to.have.been.calledWith(
remaining - 1,
(tickTime / 1000) >>> 0,
)
expect(token.invalidate).not.to.have.been.called
})
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment