make test for DBI fails on Win98

make test for DBI fails on Win98

am 26.08.2007 23:41:08 von bart.lateur

What are the plans on supporting DBI on older platforms? Since DBI 1.57
(also in 1.58 and 1.59), some tests fail on Win98 (ActivePerl 5.8.8
build 822, module compiled with MinGW 3.4.2 (+ nmake)), while all tests
pass on XP.

The culprit appears to be in DBI::ProfileDumper. A typical error message
line:

t/41prof_dump.............flock() unimplemented on this platform at
D:\programs\ActivePerl5.8\cpan\build\DBI-1.59\blib\lib/DBI/P rofileDumper.pm
line 237.
DBI::ProfileDumper on_destroy failed: flock() unimplemented on this
platform at
D:\programs\ActivePerl5.8\cpan\build\DBI-1.59\blib\lib/DBI/P rofileDumper.pm
line 237.# Looks like you planned 15 tests but only ran 7.
# Looks like your test died just after 7.

--
Bart.

Re: make test for DBI fails on Win98

am 27.08.2007 11:17:16 von Tim.Bunce

On Sun, Aug 26, 2007 at 11:41:08PM +0200, Bart Lateur wrote:
> What are the plans on supporting DBI on older platforms? Since DBI 1.57
> (also in 1.58 and 1.59), some tests fail on Win98 (ActivePerl 5.8.8
> build 822, module compiled with MinGW 3.4.2 (+ nmake)), while all tests
> pass on XP.
>
> The culprit appears to be in DBI::ProfileDumper. A typical error message line:
>
> t/41prof_dump.............flock() unimplemented on this platform at

Try the appended patch and let me know if it works for you.

Tim.

Index: lib/DBI/ProfileDumper.pm
============================================================ =======
--- lib/DBI/ProfileDumper.pm (revision 9873)
+++ lib/DBI/ProfileDumper.pm (working copy)
@@ -183,6 +183,7 @@
use Fcntl qw(:flock);
use Symbol;

+my $HAS_FLOCK = do { local $@; eval { flock STDOUT, 0; 1 } };
my $program_header;


@@ -234,7 +235,7 @@
or croak("Unable to open '$filename' for $class output: $!");
}
# lock the file (before checking size and writing the header)
- flock($fh, LOCK_EX);
+ flock($fh, LOCK_EX) if $HAS_FLOCK;
# write header if file is empty - typically because we just opened it
# in '>' mode, or perhaps we used '>>' but the file had been truncated externally.
if (-s $fh == 0) {
Index: lib/DBI/ProfileData.pm
============================================================ =======
--- lib/DBI/ProfileData.pm (revision 9873)
+++ lib/DBI/ProfileData.pm (working copy)
@@ -88,6 +88,10 @@
sub LAST_AT () { 6 };
sub PATH () { 7 };

+
+my $HAS_FLOCK = do { local $@; eval { flock STDOUT, 0; 1 } };
+
+
=head2 $prof = DBI::ProfileData->new(File => "dbi.prof")

=head2 $prof = DBI::ProfileData->new(File => "dbi.prof", Filter => sub { ... })
@@ -200,7 +204,7 @@

# lock the file in case it's still being written to
# (we'll be foced to wait till the write is complete)
- flock($fh, LOCK_SH);
+ flock($fh, LOCK_SH) if $HAS_FLOCK;

if (-s $fh) { # not empty
$self->_read_header($fh, $filename, $read_header ? 0 : 1);

Re: make test for DBI fails on Win98

am 27.08.2007 23:02:47 von bart.lateur

On Mon, 27 Aug 2007 10:17:16 +0100, Tim Bunce wrote:

>Try the appended patch and let me know if it works for you.

Yes, after the patch all tests pass.

Funny, CPAN.pm also recently introduced similar code with similar
problems. Is this a conspiracy, or just thoughtlessness? :)

Win98 has other typical solutions, such as: you can't open a file for
output in 2 programs at the same time. Surely there must be a way to
emulate flock on Win98, using an extra lock file... That way you'd only
be covered for programs written in Perl, adhering to the same
convention, but probably that should suffice. Just thinking out loud...

--
Bart.

Re: make test for DBI fails on Win98

am 28.08.2007 13:46:16 von Tim.Bunce

On Mon, Aug 27, 2007 at 11:02:47PM +0200, Bart Lateur wrote:
> On Mon, 27 Aug 2007 10:17:16 +0100, Tim Bunce wrote:
>
> >Try the appended patch and let me know if it works for you.
>
> Yes, after the patch all tests pass.
>
> Funny, CPAN.pm also recently introduced similar code with similar
> problems. Is this a conspiracy, or just thoughtlessness? :)

I'm not sure ignoring Win98 can be called thoughtlessness these days.
Umm, hardly worthy of a conspiracy either.

:)

> Win98 has other typical solutions, such as: you can't open a file for
> output in 2 programs at the same time. Surely there must be a way to
> emulate flock on Win98, using an extra lock file... That way you'd only
> be covered for programs written in Perl, adhering to the same
> convention, but probably that should suffice. Just thinking out loud...

Patches welcome at perl5-porters@perl.org ...

Tim.

Re: make test for DBI fails on Win98

am 28.08.2007 16:44:33 von Tim.Bunce

On Mon, Aug 27, 2007 at 10:33:21AM -0700, Jeff Zucker wrote:
> Tim Bunce wrote:
>
> On Sun, Aug 26, 2007 at 11:41:08PM +0200, Bart Lateur wrote:
> t/41prof_dump.............flock() unimplemented on this platform at
>
> Try the appended patch and let me know if it works for you.
>
> +my $HAS_FLOCK = do { local $@; eval { flock STDOUT, 0; 1 } };
>
> While that's the method I use in DBD::File, there appear to be some
> phantom problems with it. I think that you can get a true value
> for that but still not be able to call flock(). So I get (rare)
> reports of tests hanging when flock() is called even if it is only
> called when $HAS_FLOCK is true. If I recall correctly, from users
> with NFS.

With NFS and running the test in an NFS mounted filesystem, probably.
NFS implementations can suffer problems with lock daemons.

> I'm not sure if there is a good solution.

I've changed the code so the default can be overridden via an env var
and callers can force use of non-use of flock. That'll do for now.

Thanks Jeff.

Tim.