Skip to content

Commit 8c6fba5

Browse files
committed
fix race condition by having reading then writing the file in same script
1 parent 769dbca commit 8c6fba5

File tree

3 files changed

+79
-213
lines changed

3 files changed

+79
-213
lines changed

MANIFEST

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ t/total.t
1717
t/unlink.t
1818
t/vlenString.t
1919
t/xData.t
20-
t/ztotal_index.t
2120
tkviewtest
2221
typemap
2322
varlen.hdf5

t/total.t

+79
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,84 @@ is( join(",",sort @groups), 'dude2,mygroup' );
170170
@groups = $group2->groups;
171171

172172
is( scalar(@groups), 0 );
173+
undef $hdfobj;
174+
175+
{
176+
# Script to test the attribute index functionality of the PDL::IO::HDF5 Class
177+
# New File Check:
178+
my $filename = "total.hdf5";
179+
ok(my $hdfobj = PDL::IO::HDF5->new($filename));
180+
181+
# It is normally a no-no to call a internal method, but we
182+
# are just testing here:
183+
$hdfobj->_buildAttrIndex;
184+
185+
my $baseline = {
186+
'/' => {
187+
attr1 => 'dudeman23',
188+
attr2 => 'What??',
189+
},
190+
'/dude2' => {
191+
attr1 => 'dudeman23',
192+
attr2 => 'What??',
193+
},
194+
'/mygroup' => {
195+
attr1 => 'dudeman23',
196+
attr2 => 'What??',
197+
},
198+
'/mygroup/subgroup' => {
199+
attr1 => 'dudeman23',
200+
attr2 => 'What??',
201+
},
202+
};
203+
is_deeply($hdfobj->{attrIndex}, $baseline);
204+
205+
my @values = $hdfobj->allAttrValues('attr1');
206+
$baseline = [ 'dudeman23', 'dudeman23', 'dudeman23', 'dudeman23' ];
207+
is_deeply \@values, $baseline;
208+
209+
@values = $hdfobj->allAttrValues('attr1','attr2');
210+
$baseline = [
211+
[ 'dudeman23', 'What??', ], [ 'dudeman23', 'What??', ],
212+
[ 'dudeman23', 'What??', ], [ 'dudeman23', 'What??', ]
213+
];
214+
is_deeply \@values, $baseline;
215+
216+
my @names = $hdfobj->allAttrNames;
217+
is_deeply \@names, [ 'attr1', 'attr2', ];
218+
219+
# Test building the groupIndex
220+
$hdfobj->_buildGroupIndex('attr1','attr2');
221+
$hdfobj->_buildGroupIndex('attr2');
222+
$hdfobj->_buildGroupIndex('attr1','attr3');
223+
224+
$baseline = {
225+
'attr1attr2' => {
226+
'dudeman23What??' => [ '/', '/dude2', '/mygroup', '/mygroup/subgroup' ]
227+
},
228+
'attr1attr3' => {
229+
'dudeman23_undef_' => [ '/', '/dude2', '/mygroup', '/mygroup/subgroup' ]
230+
},
231+
'attr2' => {
232+
'What??' => [ '/', '/dude2', '/mygroup', '/mygroup/subgroup' ]
233+
}
234+
};
235+
236+
my $result = $hdfobj->{groupIndex};
237+
is_deeply $result, $baseline or diag explain $result;
238+
239+
my @groups = $hdfobj->getGroupsByAttr( 'attr1' => 'dudeman23',
240+
'attr2' => 'What??');
241+
$baseline = [
242+
'/',
243+
'/dude2',
244+
'/mygroup',
245+
'/mygroup/subgroup',
246+
];
247+
is_deeply \@groups, $baseline;
248+
249+
# clean up file
250+
}
251+
unlink $filename if( -e $filename);
173252

174253
done_testing;

t/ztotal_index.t

-212
This file was deleted.

0 commit comments

Comments
 (0)