Skip to content

Commit

Permalink
chore: properly increase available ports (#4666)
Browse files Browse the repository at this point in the history
* chore: properly increase available ports

* chore: only use available ports and not guess ports

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
danez and kodiakhq[bot] authored Jun 7, 2022
1 parent 32a753d commit 9240a0f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
# This improves Windows network performance, we need this since we open many ports in our tests
- name: Increase Windows port limit and reduce time wait delay
run: |
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters /v MaxUserPort /t REG_DWORD /d 32768 /f
netsh int ipv4 set dynamicport tcp start=1025 num=64511
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters /v TcpTimedWaitDelay /t REG_DWORD /d 30 /f
if: "${{ matrix.os == 'windows-latest' && !steps.release-check.outputs.IS_RELEASE }}"
- name: Git checkout
Expand Down
13 changes: 0 additions & 13 deletions npm-shrinkwrap.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@
"nock": "^13.2.4",
"p-timeout": "^4.0.0",
"rewiremock": "^3.14.3",
"seedrandom": "^3.0.5",
"serialize-javascript": "^6.0.0",
"sinon": "^13.0.0",
"sort-on": "^4.1.0",
Expand Down
21 changes: 3 additions & 18 deletions tests/integration/utils/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,11 @@ const execa = require('execa')
const getPort = require('get-port')
const omit = require('omit.js').default
const pTimeout = require('p-timeout')
const seedrandom = require('seedrandom')

const cliPath = require('./cli-path')
const { handleQuestions } = require('./handle-questions')
const { killProcess } = require('./process')

// each process gets a starting port based on the pid
const rng = seedrandom(`${process.pid}`)
const getRandomPortStart = function () {
const startPort = Math.floor(rng() * RANDOM_PORT_SHIFT) + RANDOM_PORT_SHIFT
return startPort
}

// To avoid collisions with frameworks ports
const RANDOM_PORT_SHIFT = 1e4
const FRAMEWORK_PORT_SHIFT = 1e3

let currentPort = getRandomPortStart()

const ENVS_TO_OMIT = ['LANG', 'LC_ALL']

const getExecaOptions = ({ cwd, env }) => ({
Expand All @@ -34,15 +20,14 @@ const getExecaOptions = ({ cwd, env }) => ({
})

const startServer = async ({ cwd, offline = true, env = {}, args = [], expectFailure = false, prompt }) => {
const tryPort = currentPort
currentPort += 1
const port = await getPort({ port: tryPort })
const port = await getPort()
const staticPort = await getPort()
const host = 'localhost'
const url = `http://${host}:${port}`
console.log(`Starting dev server on port: ${port} in directory ${path.basename(cwd)}`)
const ps = execa(
cliPath,
['dev', offline ? '--offline' : '', '-p', port, '--staticServerPort', port + FRAMEWORK_PORT_SHIFT, ...args],
['dev', offline ? '--offline' : '', '-p', port, '--staticServerPort', staticPort, ...args],
getExecaOptions({ cwd, env }),
)

Expand Down

1 comment on commit 9240a0f

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

Package size: 294 MB

Please sign in to comment.