1898184e3Ssthen#!/usr/bin/perl
2898184e3Ssthen#
3898184e3Ssthen# Tests for various caching errors
4898184e3Ssthen#
5898184e3Ssthen
6de8cc8edSafresh1use strict;
7de8cc8edSafresh1use warnings;
8de8cc8edSafresh1
9898184e3Ssthenuse Config;
10de8cc8edSafresh1
11de8cc8edSafresh1my $file = "tf24-$$.txt";
12898184e3Ssthenunless ($Config{d_alarm}) {
13898184e3Ssthen  print "1..0\n"; exit;
14898184e3Ssthen}
15898184e3Ssthen
16898184e3Ssthen$: = Tie::File::_default_recsep();
17898184e3Ssthenmy $data = join $:, "record0" .. "record9", "";
18898184e3Ssthenmy $V = $ENV{INTEGRITY};        # Verbose integrity checking?
19898184e3Ssthen
20898184e3Ssthenprint "1..3\n";
21898184e3Ssthen
22898184e3Ssthenmy $N = 1;
23898184e3Ssthenuse Tie::File;
24898184e3Ssthenprint "ok $N\n"; $N++;
25898184e3Ssthen
265759b3d2Safresh1open F, '>', $file or die $!;
27898184e3Ssthenbinmode F;
28898184e3Ssthenprint F $data;
29898184e3Ssthenclose F;
30898184e3Ssthen
31898184e3Ssthen# Limit cache size to 30 bytes
32898184e3Ssthenmy $MAX = 30;
33898184e3Ssthen#  -- that's enough space for 3 records, but not 4, on both \n and \r\n systems
34de8cc8edSafresh1my @a;
35898184e3Ssthenmy $o = tie @a, 'Tie::File', $file, memory => $MAX, autodefer => 1;
36898184e3Ssthenprint $o ? "ok $N\n" : "not ok $N\n";
37898184e3Ssthen$N++;
38898184e3Ssthen
39898184e3Ssthen# (3) In 0.50 this goes into an infinite loop.  Explanation:
40898184e3Ssthen#
41898184e3Ssthen#   Suppose you overfill the defer buffer by so much that the memory
42898184e3Ssthen#   limit is also exceeded.  You'll go into _splice to prepare to
43898184e3Ssthen#   write out the defer buffer, and _splice will call _fetch, which
44898184e3Ssthen#   will then try to flush the read cache---but the read cache is
45898184e3Ssthen#   already empty, so you're stuck in an infinite loop.
46898184e3Ssthen#
47*f2a19305Safresh1# Ten seconds should be plenty of time for it to complete if it works
48*f2a19305Safresh1# on an unloaded box. Using 20 under parallel builds seems prudent.
49*f2a19305Safresh1my $alarm_time = $ENV{TEST_JOBS} || $ENV{HARNESS_OPTIONS} ? 20 : 10;
50*f2a19305Safresh1local $SIG{ALRM} = sub { die "$0 Timeout after $alarm_time seconds at test 3\n" };
51*f2a19305Safresh1alarm $alarm_time unless $^P;
52898184e3Ssthen@a = "record0" .. "record9";
53898184e3Ssthenprint "ok 3\n";
54898184e3Ssthenalarm 0;
55898184e3Ssthen
56898184e3SsthenEND {
57898184e3Ssthen  undef $o;
58898184e3Ssthen  untie @a;
59898184e3Ssthen  1 while unlink $file;
60898184e3Ssthen}
61