Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 11, 2013 at 01:05:12PM +0100, Adam Spiers wrote:

> +test_expect_success 'setup: have stdbuf?' '
> +	if which stdbuf >/dev/null 2>&1
> +	then
> +		test_set_prereq STDBUF
> +	fi
> +'
> +
> +test_expect_success STDBUF 'streaming support for --stdin' '
> +	(
> +		echo one
> +		sleep 2
> +		echo two
> +	) | stdbuf -oL git check-ignore -v -n --stdin >out &
> +	pid=$! &&
> +	sleep 1 &&
> +	grep "^\.gitignore:1:one	one" out &&
> +	test $( wc -l <out ) = 1 &&
> +	sleep 2 &&
> +	grep "^::	two" out &&
> +	test $( wc -l <out ) = 2 &&
> +	( wait $pid || kill $pid || : ) 2>/dev/null
> +'

I always get a little nervous with sleeps in the test suite, as they are
indicative that we are trying to avoid some race condition, which means
that the test can fail when the system is under load, or when a tool
like valgrind is used which drastically alters the timing (e.g., if
check-ignore takes longer than 1 second to produce its answer, we may
fail here).

Is there a simpler way to test this?

Like:

  # Set up a long-running "check-ignore" connected by pipes.
  mkfifo in out &&
  (git check-ignore ... <in >out &) &&

  # We cannot just "echo >in" because check-ignore
  # would get EOF after echo exited; instead we open
  # the descriptor in our shell, and then echo to the
  # fd. We make sure to close it at the end, so that
  # the subprocess does get EOF and dies properly.
  exec 9>in &&
  test_when_finished "exec 9>&-" &&

  # Now we can do interactive tests
  echo >&9 one &&
  read response <out &&
  test "$response" = ... &&
  echo >&9 two &&
  read response <out &&
  test "$response" = ...

Hmm. Maybe simpler wasn't the right word. :) But it avoids any sleeps or
race conditions.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]