Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
chore: add rate limiting to CI (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Oct 20, 2021
1 parent d51c860 commit f09a480
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
if: "${{ matrix.node-version == '*' }}"
- name: Tests
run: npm run test:ci
env:
ZISI_TEST_RATE_LIMIT: 3
- name: Get test coverage flags
id: test-coverage-flags
run: |-
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"nyc": "^15.0.0",
"sinon": "^11.1.1",
"sort-on": "^4.1.1",
"throat": "^6.0.1",
"typescript": "^4.4.3"
},
"engines": {
Expand Down
22 changes: 17 additions & 5 deletions tests/helpers/test_many.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
const { env, platform } = require('process')
const { env } = require('process')

const throat = require('throat')

const getRateLimitedTestFunction = (originalTestFunction) => {
const rateLimit = Number.parseInt(env.ZISI_TEST_RATE_LIMIT)

if (Number.isNaN(rateLimit)) {
return originalTestFunction
}

return throat(rateLimit, originalTestFunction)
}

/**
* @template M, O
Expand All @@ -18,12 +30,10 @@ const makeTestMany = (test, matrix) => {

// Weird workaround to avoid running too many tests in parallel on
// Windows, which causes problems in the CI.
const isSerial = variationNames.length >= 3 && platform === 'win32'
const testFunction = isSerial ? testFn.serial : testFn
const testTitle = `${title} [${name}]`

if (name.startsWith('todo:')) {
testFunction.todo(testTitle)
testFn.todo(testTitle)

return
}
Expand All @@ -34,7 +44,9 @@ const makeTestMany = (test, matrix) => {
throw new Error(`Unknown variation in test: ${name}`)
}

testFunction(testTitle, assertions.bind(null, variation))
const rateLimitedTestFn = getRateLimitedTestFunction(testFn)

rateLimitedTestFn(testTitle, assertions.bind(null, variation))
})
}

Expand Down

1 comment on commit f09a480

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 9s

largeDepsNft: 58.7s

largeDepsZisi: 1m 13.2s

Please sign in to comment.