[PATCH 1 of 1] Tests: unbreak reading new stderr data after eof

Sergey Kandaurov pluknet at nginx.com
Mon May 29 13:31:54 UTC 2023


> On 26 May 2023, at 20:46, Maxim Dounin <mdounin at mdounin.ru> wrote:
> 
> Hello!
> 
> On Fri, May 26, 2023 at 03:24:12PM +0400, Sergey Kandaurov wrote:
> 
>> # HG changeset patch
>> # User Sergey Kandaurov <pluknet at nginx.com>
>> # Date 1685100180 -14400
>> #      Fri May 26 15:23:00 2023 +0400
>> # Node ID dc3539be2a14a0cd0b8be9e1e9aae8c95b806828
>> # Parent  4dad7cf8ebe807f9230a82dde5fc02b5e12e390b
>> Tests: unbreak reading new stderr data after eof.
>> 
>> Tests don't expect to stop reading redirected stderr when end of file is
>> reached, but rather to read new data being appended, similar to "tail -f".
>> The behaviour is first changed in Ubuntu 23.04 Perl 5.36, by applying the
>> upstream patch [1], and is expected for inclusion in the next Perl 5.38.
>> The fix is to set filehandle's position to the end of file to clear the
>> error state and allow to continue readline() further from that position.
>> 
>> [1] https://github.com/Perl/perl5/commit/80c1f1e45e8e
>> 
>> Updated mail_error_log.t and stream_error_log.t for consistency.
>> 
>> diff --git a/error_log.t b/error_log.t
>> --- a/error_log.t
>> +++ b/error_log.t
>> @@ -183,7 +183,9 @@ sub lines {
>> 	my ($t, $file, $pattern) = @_;
>> 
>> 	if ($file eq 'stderr') {
>> -		return map { $_ =~ /\Q$pattern\E/ } (<$stderr>);
>> +		my $value = map { $_ =~ /\Q$pattern\E/ } (<$stderr>);
>> +		seek $stderr, 0, Fcntl::SEEK_END;
>> +		return $value;
>> 	}
>> 
>> 	my $path = $t->testdir() . '/' . $file;
> 
> The SEEK_END here would introduce a race: if some data are added 
> after reading, SEEK_END will silently skip it.  While probably not 
> important here, it might be a good idea to avoid introducing 
> unneeded races when possible.  In particular, SEEK_SET might be a 
> better option (untested).

Sure, tnx for the point.
For the record, SEEK_SET appears to avoid races.

> 
> Upcoming perldelta recommends $handle->clearerr() instead, which 
> indeed seems to be a more explicit option (untested too).
> 
> https://github.com/Perl/perl5/blob/8db19a86dfa8408a91845da20ea7063f7646a913/pod/perldelta.pod#readline-no-longer-clears-the-stream-error-and-eof-flags
> 

As we don't need to change the position, clearerr() fits better.
Pushed the updated change.

-- 
Sergey Kandaurov


More information about the nginx-devel mailing list