-
Notifications
You must be signed in to change notification settings - Fork 5
wait for tcp port available (win32) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: windows
Are you sure you want to change the base?
Changes from 1 commit
ed21f8d
35cb5c8
0d9dd39
c7cf6c7
34bc5e6
5c589fd
fbd8076
5b75dcd
d1bf330
5cf785d
a58db73
425fcde
7865e33
cccc7ed
9aef07f
bc67f2d
1f0f1af
3ef6fc5
3493b4b
e99fd6e
030cdbf
8663e04
08d5c04
18c0dd2
8b1b9f7
293263c
47797fe
c850246
b8d7ef2
2d204f4
b05e0d8
9140764
45f29f3
e526c69
8ab9dd8
cf15c04
575e5d7
4fbb40b
054e412
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,12 +64,14 @@ class Server extends EventEmitter { | |
| * @param {object} [options] - Optional settings | ||
| * @param {boolean} [options.stdout=false] - Forward server output from STDOUT to STDOUT | ||
| * @param {boolean} [options.stderr=true] - Forward server output from STDERR to STDERR | ||
| * @param {number} [options.win32Timeout=30000] - (Windows only) Max time to wait for server ready, in mS | ||
| * @returns {Promise} | ||
| */ | ||
| launch (cmd, args, options = {}) { | ||
| if (typeof this._process !== 'undefined') throw new Error('Server already launched'); | ||
| const stdout = typeof options.stdout !== 'undefined' ? options.stdout : false; | ||
| const stderr = typeof options.stderr !== 'undefined' ? options.stderr : true; | ||
| const win32Timeout = typeof options.win32Timeout !== 'undefined' ? options.win32Timeout : 30000; | ||
|
|
||
| const proc = (this._process = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe', this._fd] })); | ||
| this._srv.close(); | ||
|
|
@@ -90,7 +92,23 @@ class Server extends EventEmitter { | |
| }); | ||
|
|
||
| // Should be resolved by the "spawn" event, but that is only supported in Node 15+ | ||
| return Promise.resolve; | ||
| if (process.platform !== 'win32') return Promise.resolve; | ||
| return new Promise((resolve) => { | ||
|
||
| const retryTime = 60; | ||
dmanto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const now = new Date(); | ||
dmanto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const timeToStop = new Date(now.getTime() + win32Timeout); | ||
| const port = this.port; | ||
| (function loop () { | ||
| const connection = net.connect(port, resolve); | ||
| connection.on('error', err => { | ||
| if (err.code === 'ECONNREFUSED') { | ||
|
||
| if (new Date() < timeToStop) { | ||
|
||
| setTimeout(loop, retryTime); | ||
| } | ||
| } | ||
| }); | ||
| })(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as i can see there is no reason at all for this to be Windows specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will have no effect on other platforms, at least how is it written.
If you mean to wait for connection ready at the TCP port in all cases, it could be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way it is done now makes little sense. Since the module doesn't become more portable, it just allows someone to use it in a Windows specific way. Instead of enabling one test to run on all platforms.