Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ca8e01

Browse files
fix(site): wait until port is available in e2e (#15537)
Related:coder/internal#212This PR modifies the logic responsible for creating a server in E2Etests to check if the port is free. Alternatively, we could refactor theframework to dynamically create server instances, but this solutionmight be a cheaper quick win.Note:I'll leave it as is now, it might be worth asking somebody with afrontend skillset to double-check this contribution.---------Signed-off-by: Danny Kopping <danny@coder.com>Co-authored-by: Danny Kopping <danny@coder.com>
1 parent5861e51 commit8ca8e01

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎site/e2e/helpers.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{typeChildProcess,exec,spawn}from"node:child_process";
22
import{randomUUID}from"node:crypto";
3+
importnetfrom"node:net";
34
importpathfrom"node:path";
45
import{Duplex}from"node:stream";
56
import{typeBrowserContext,typePage,expect,test}from"@playwright/test";
@@ -687,6 +688,8 @@ export class Awaiter {
687688
exportconstcreateServer=async(
688689
port:number,
689690
):Promise<ReturnType<typeofexpress>>=>{
691+
awaitwaitForPort(port);// Wait until the port is available
692+
690693
conste=express();
691694
// We need to specify the local IP address as the web server
692695
// tends to fail with IPv6 related error:
@@ -695,6 +698,44 @@ export const createServer = async (
695698
returne;
696699
};
697700

701+
asyncfunctionwaitForPort(
702+
port:number,
703+
host="0.0.0.0",
704+
timeout=30000,
705+
):Promise<void>{
706+
conststart=Date.now();
707+
while(Date.now()-start<timeout){
708+
constavailable=awaitisPortAvailable(port,host);
709+
if(available){
710+
return;
711+
}
712+
console.warn(`${host}:${port} is in use, checking again in 1s`);
713+
awaitnewPromise((resolve)=>setTimeout(resolve,1000));// Wait 1 second before retrying
714+
}
715+
thrownewError(
716+
`Timeout: port${port} is still in use after${timeout/1000} seconds.`,
717+
);
718+
}
719+
720+
functionisPortAvailable(port:number,host="0.0.0.0"):Promise<boolean>{
721+
returnnewPromise((resolve)=>{
722+
constprobe=net
723+
.createServer()
724+
.once("error",(err:NodeJS.ErrnoException)=>{
725+
if(err.code==="EADDRINUSE"){
726+
resolve(false);// port is in use
727+
}else{
728+
resolve(false);// some other error occurred
729+
}
730+
})
731+
.once("listening",()=>{
732+
probe.close();
733+
resolve(true);// port is available
734+
})
735+
.listen(port,host);
736+
});
737+
}
738+
698739
exportconstfindSessionToken=async(page:Page):Promise<string>=>{
699740
constcookies=awaitpage.context().cookies();
700741
constsessionCookie=cookies.find((c)=>c.name==="coder_session_token");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp