-
Notifications
You must be signed in to change notification settings - Fork 78
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
testscript: panic: fail now! in stop command on Windows #228
Comments
Do they always fail like that on Windows, or just sometimes? Do you have a minimal reproducer? Beyond making the investigation easier, it would also serve as a regression test for the eventual fix. |
Also, could you share an entire goroutine trace? I think the problem is that we don't set up the recover for |
I don't have a lot of data on this (I have ran it on GitHub 3-4 times, it always fails on Windows; I have since disabled these tests on Windows, and they always passes on Linux/MacOs, which is good), but I will close my eyes and boot up my Windows VM later today and see what happens. |
FYI I think the problem is that
|
Drive-by comment unrelated to the error you are seeing, @bep: I've not had a particularly enjoyable time trying to test server processes using a command to start the server, and then another one to close it. Instead, I've tended to use special files in the testscript itself to indicate that a server should be started for the purposes of a given test, and then tear down happens at the end. This also means that the setup command can more easily wait until the server is known to be ready before starting the script. |
Yes, I'm actually doing that. My current problem is the stopping of the server, which seem to somehow end with |
To clarify, I think Paul means starting and stopping your server program from Go code, via testscript's |
This test repo always fails on Windows: https://github.com/bep/repro-testscript-228 Log here: Not sure why this is falsy on Windows: Line 540 in a4f6fab
|
OK, I guess this is a what to be expected on Windows when killing the process (as in, no SIGINT). I will find a workaround, but I'll keep this issue open if someone has a fix. |
Exactly so. |
@bep I'd strongly consider doing the server setup and teardown in the
You can "mark" scripts that expect a server to be running using a special file in the script archive:
Check for the existence of such a file in the |
For a fairly involved example I've recently written https://github.com/cue-lang/cuelang.org/blob/a0df30d1ef4858b51bdfe96b7f6c507a0f08fb81/internal/fsnotify/fsnotify_test.go#L57 (which coincidentally might be a package of interest to Hugo). |
@myitcv Maybe. The thing is:
|
Just to highlight that you don't necessarily lose any capabilities with the special file approach. You could just as easily put the arguments to the server in the special file, extract them using code like this, then pass the resulting
I'm totally with you on this, just sharing my experience of having tested a number of commands where a server (or equivalent mode) became too painful. As you will notice from the |
@myitcv I'm a little confused. I see the |
Just to clarify, I'm be talking about the example from The When each script runs, before In the Note the use of If the file exists, its contents are used to parse a Here is an example of one of the scripts in the The file Hence in my suggestion re the running of a server, you could use the existence of a special file within a testscript script archive to signal that |
Updated my latest comment with a link to one of the |
@myitcv thanks for the detailed explanation. OK, I understand how to set it up. The thing is, though, when I compare the 2 scripts below:
And:
I would much, much prefer the first variant any day of the week. And one great thing about it is that the average developer coming in to fix 1 thing in a project he/she has no experience with, can read that script and understand exactly what it does (also, it does not require 1K lines of custom test setup behind the scenes). This particular issue (#228) is obviously a bug. It may be hard (impossible?) to fix for the My current workaround is a custom |
At the risk of derailing this bug report still further, just to point out a couple of things:
I've found The checking of I take your point about it being unusual to not have a command at the start of a script, but it's a "problem" that is (again in my experience) relatively easily overcome with a script naming format like Again, none of what I am saying is a rule in any way, just sharing my experience from having written a number of such test setups. |
Which is why in my real tests have both a
Not that my tests rely on this, but what you say isn't obvious when reading the docs:
I suggest, however, that we instead focus on the issue. The testscript package is incredibly useful, it would be even better if everyone didn't have to create elaborate workarounds to test servers, which is a common enough requirement. |
I agree that we should fix the panics in any case. Whether or not testscript's support for background commands should be redesigned (or avoided?) is a different matter. |
Just to summarise my findings (so people don't have to wade through all of the above to get the gist of it:
|
When an entire script runs and the end is reached, any background processes begun with a '&' command get interrupted or killed, depending on the platform and timeout, and we wait for them to finish. We also checked their resulting status code and failed if they didn't exit with a status code of 0. However, as explained in the comment, this would always fail on Windows, given that it doesn't have interrupt signals so we would kill directly, causing a "signal: killed" error. Worse, any failures here caused a `panic: fail now!` as that is how we bubble up errors when a script command is being run, but such panics were not being recovered once we reached the end of a script. Now that we don't check the result anymore here, the panics are gone. Fixes rogpeppe#228. Fixes rogpeppe#260.
When an entire script runs and the end is reached, any background processes begun with a '&' command get interrupted or killed, depending on the platform and timeout, and we wait for them to finish. We also checked their resulting status code and failed if they didn't exit with a status code of 0. However, as explained in the comment, this would always fail on Windows, given that it doesn't have interrupt signals so we would kill directly, causing a "signal: killed" error. Worse, any failures here caused a `panic: fail now!` as that is how we bubble up errors when a script command is being run, but such panics were not being recovered once we reached the end of a script. Now that we don't check the result anymore here, the panics are gone. Fixes rogpeppe#228. Fixes rogpeppe#260.
When an entire script runs and the end is reached, any background processes begun with a '&' command get interrupted or killed, depending on the platform and timeout, and we wait for them to finish. We also checked their resulting status code and failed if they didn't exit with a status code of 0. However, as explained in the comment, this would always fail on Windows, given that it doesn't have interrupt signals so we would kill directly, causing a "signal: killed" error. Worse, any failures here caused a `panic: fail now!` as that is how we bubble up errors when a script command is being run, but such panics were not being recovered once we reached the end of a script. Now that we don't check the result anymore here, the panics are gone. Fixes #228. Fixes #260.
I'm creating this issue in the hope that someone could give me some helping hints before I give in and start up my Windows VM.
The short take is:
The text was updated successfully, but these errors were encountered: