Debian Codegraph @

t/5defer/fork.t

raw
1 #
2 # make sure delayed persist works in forks.
3 #
4 # NOTE: The below text was the old behaviour. The test was changed once
5 # the deferral timestamp was move into shared memory. It now reflects
6 # the ideally desired behaviour.
7 #
8 # Note that this test is really misleading. It seems to indicate a
9 # behavior that is correct, which is incorrect. What it really does is
10 # document the behavior of defer as it is now, in case it changes
11 # somehow in the future.
12 #
13 # Ideally, deferrals should work by delaying writes across all processes
14 # based on the last write by any process. To do that though, would mean
15 # each potential write would need to read the persist file first, which
16 # defeats the purpose of defer.
17 #
18 # Instead, deferrals work based on internal timestamps in each process.
19 #
20 # Interestingly though, this test fails on psuedofork platforms.
21 # Apparently the underlying threads keep the internal timestamps in sync
22 # across "processes".
23 #
24 use strict;
25 use warnings;
26 use MyTest;
27 use File::Temp;
28
29 use vars qw(@OPTS $tmpdir $fn0 $fn1 $fn2);
30
31 BEGIN {
32 $tmpdir = File::Temp->newdir('UUID-test-XXXXXXXX', TMPDIR => 1, CLEANUP => 0);
33 $fn0 = File::Temp::tempnam($tmpdir, 'UUID.test.');
34 $fn1 = File::Temp::tempnam($tmpdir, 'UUID.test.');
35 $fn2 = File::Temp::tempnam($tmpdir, 'UUID.test.');
36 @OPTS = ('uuid1', ':persist='.$fn0, ':defer=999999');
37 ok 1, 'began';
38 }
39
40 use UUID @OPTS;
41
42 ok 1, 'loaded';
43
44 my ($ts0, $ts1);
45
46 ok -d $tmpdir, 'tmpdir exists';
47 ok !-e $fn0, 'start persist missing';
48 ok !-e $fn1, 'later persist missing';
49 ok !-e $fn2, 'last persist missing';
50 is UUID::_defer(), 999999, 'defer init long';
51
52 {
53 my $kid = fork;
54 if (!defined $kid) {
55 fail 'fork1';
56 }
57 elsif ($kid == 0) {
58 uuid1();
59 exit 0;
60 }
61 else {
62 pass 'fork1';
63 waitpid $kid, 0;
64 }
65 }
66
67 ok -e $fn0, 'start persist found';
68
69 UUID::_persist($fn1);
70
71 uuid1();
72
73 ok !-e $fn1, 'later persist still missing';
74
75 ok UUID::_defer(0.00000001), 'defer changed';
76 UUID::_persist($fn2);
77
78 uuid1();
79
80 ok -e $fn2, 'last persist found';
81
82 # close state so Win32 can cleanup
83 UUID::_persist(undef);
84 unlink $fn0;
85 unlink $fn1;
86 unlink $fn2;
87 rmdir $tmpdir;
88
89 done_testing;