Integration testing program that internally forks itself

91 views
Skip to first unread message

Vjeran

unread,
Oct 27, 2022, 12:05:49 PM10/27/22
to golang-nuts
We have a program that forks itself in order to do some work
so calling `./program do` internally finds its path using os.Executable and calls `./program do2`

Now when trying to do integration tests program spawns itself and repeats test causing an infinite loop?

Any ideas how to handle it?

Jan Mercl

unread,
Oct 27, 2022, 12:47:43 PM10/27/22
to Vjeran, golang-nuts
Any recursion that does not have a terminating condition will try to recurse infinitely ;-)

I'm passing a command line flag in such situations - when testing, but the best option depends on the particular use. Elsewhere, in a command that starts a server or talks to the server, I used, for example, an ephemeral @named socket, which nicely handled both the termination condition and the communication and is even safe for concurrent processes competing with each other.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6f62afc4-af7a-4548-85c5-6514c2e20a49n%40googlegroups.com.

Peter Galbavy

unread,
Oct 28, 2022, 3:36:08 AM10/28/22
to golang-nuts
I also use a flag to do this, and I have a local package that then removes this flag (or any of a defined list) before re-execing the binary:



It may not be perfect, but it works for my usage.

Peter

Bryan C. Mills

unread,
Oct 28, 2022, 1:04:42 PM10/28/22
to golang-nuts
Generally I use environment variables for that sort of test, so that the part of the program that constructs the arguments for the program doesn't have to know to pass a special additional argument.

Reply all
Reply to author
Forward
0 new messages