Unverified Commit 92e1b3fe authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

test(fixture): improve finding ports to reduce flaky (#55151)




### What

Found a flaky test like https://github.com/vercel/next.js/actions/runs/6125719281/job/16628276301?pr=55118#step:29:174, `get-port` throws by port is not available. Peeking bit, there seems an upstream fix hope to improve the situation but unfortunately it happened after get-port switched to native esm only, so bumping is non trivial work. Instead adapting get-port-please as a replacwement but leave get-port as fallback for a while to verify its stability. Once we are certain, we can remove old get-port entirely. 
parent ddc26c99
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
"form-data": "4.0.0", "form-data": "4.0.0",
"fs-extra": "9.0.0", "fs-extra": "9.0.0",
"get-port": "5.1.1", "get-port": "5.1.1",
"get-port-please": "3.1.1",
"glob": "7.1.6", "glob": "7.1.6",
"gzip-size": "5.1.1", "gzip-size": "5.1.1",
"html-validator": "5.1.18", "html-validator": "5.1.18",
......
...@@ -296,6 +296,9 @@ importers: ...@@ -296,6 +296,9 @@ importers:
get-port: get-port:
specifier: 5.1.1 specifier: 5.1.1
version: 5.1.1 version: 5.1.1
get-port-please:
specifier: 3.1.1
version: 3.1.1
glob: glob:
specifier: 7.1.6 specifier: 7.1.6
version: 7.1.6 version: 7.1.6
...@@ -14573,6 +14576,10 @@ packages: ...@@ -14573,6 +14576,10 @@ packages:
through2: 2.0.5 through2: 2.0.5
dev: true dev: true
/get-port-please@3.1.1:
resolution: {integrity: sha512-3UBAyM3u4ZBVYDsxOQfJDxEa6XTbpBDrOjp4mf7ExFRt5BKs/QywQQiJsh2B+hxcZLSapWqCRvElUe8DnKcFHA==}
dev: true
/get-port@5.1.1: /get-port@5.1.1:
resolution: {integrity: sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==} resolution: {integrity: sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==}
engines: {node: '>=8'} engines: {node: '>=8'}
......
...@@ -13,6 +13,7 @@ import path from 'path' ...@@ -13,6 +13,7 @@ import path from 'path'
import spawn from 'cross-spawn' import spawn from 'cross-spawn'
import { writeFile } from 'fs-extra' import { writeFile } from 'fs-extra'
import getPort from 'get-port' import getPort from 'get-port'
import { getRandomPort } from 'get-port-please'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import qs from 'querystring' import qs from 'querystring'
import treeKill from 'tree-kill' import treeKill from 'tree-kill'
...@@ -171,7 +172,18 @@ export function renderViaHTTP( ...@@ -171,7 +172,18 @@ export function renderViaHTTP(
} }
export function findPort() { export function findPort() {
return getPort() // [NOTE] What are we doing here?
// There are some flaky tests failures caused by `No available ports found` from 'get-port'.
// This may be related / fixed by upstream https://github.com/sindresorhus/get-port/pull/56,
// however it happened after get-port switched to pure esm which is not easy to adapt by bump.
// get-port-please seems to offer the feature parity so we'll try to use it, and leave get-port as fallback
// for a while until we are certain to switch to get-port-please entirely.
try {
return getRandomPort()
} catch (e) {
require('console').warn('get-port-please failed, falling back to get-port')
return getPort()
}
} }
export interface NextOptions { export interface NextOptions {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment