Re: [PATCH 1/2] daemon: add tests
- From
Jeff King <peff@peff.net>
- Date
- Jan 5, 2012, 02:51 UTC
- Message-ID
- <20120105025154.GA7326@sigill.intra.peff.net>
- In-Reply-To
- <m3vcoqevjm.fsf@localhost.localdomain>
On Wed, Jan 04, 2012 at 06:24:16PM -0800, Jakub Narebski wrote:
Show 9 quoted lines
> Jeff King <peff@peff.net> writes: > > > As a side note, it looks like we just start the daemon with "git daemon > > &". Doesn't that create a race condition with the tests which > > immediately try to access it (i.e., the first test may run before the > > daemon actually opens the socket)? > > Hmmm... perhaps the trick that git-instaweb does for "plackup" web > server would be of use here, waiting for socket to be ready?
It looks like it busy loops, which is kind of ugly.
The credential-cache helper has a similar problem. It wants to kick off a daemon if one is not already running, and then connect to it. So the daemon does:
printf("ok\n");
fclose(stdout);when it has set up the socket, and the client does:
r = read_in_full(daemon.out, buf, sizeof(buf));
if (r < 0)
die_errno("unable to read result code from cache daemon");
if (r != 3 || memcmp(buf, "ok\n", 3))
die("cache daemon did not start: %.*s", r, buf);
/* now we can connect over the socket */We could probably add a "--notify-when-ready" option to git-daemon to do something similar.
-Peff