Skip to content

Commit

Permalink
fix race condition by having reading then writing the file in same sc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
mohawk2 committed Jan 12, 2025
1 parent 769dbca commit 117fbe0
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 213 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- build issues fixed (#6) - thanks @a-shahba

0.76 2024-10-09
- handle PDL 2.064+ types like signed byte (#5) - thanks @a-shahba for report

Expand Down
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ t/total.t
t/unlink.t
t/vlenString.t
t/xData.t
t/ztotal_index.t
tkviewtest
typemap
varlen.hdf5
79 changes: 79 additions & 0 deletions t/total.t
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,84 @@ is( join(",",sort @groups), 'dude2,mygroup' );
@groups = $group2->groups;

is( scalar(@groups), 0 );
undef $hdfobj;

{
# Script to test the attribute index functionality of the PDL::IO::HDF5 Class
# New File Check:
my $filename = "total.hdf5";
ok(my $hdfobj = PDL::IO::HDF5->new($filename));

# It is normally a no-no to call a internal method, but we
# are just testing here:
$hdfobj->_buildAttrIndex;

my $baseline = {
'/' => {
attr1 => 'dudeman23',
attr2 => 'What??',
},
'/dude2' => {
attr1 => 'dudeman23',
attr2 => 'What??',
},
'/mygroup' => {
attr1 => 'dudeman23',
attr2 => 'What??',
},
'/mygroup/subgroup' => {
attr1 => 'dudeman23',
attr2 => 'What??',
},
};
is_deeply($hdfobj->{attrIndex}, $baseline);

my @values = $hdfobj->allAttrValues('attr1');
$baseline = [ 'dudeman23', 'dudeman23', 'dudeman23', 'dudeman23' ];
is_deeply \@values, $baseline;

@values = $hdfobj->allAttrValues('attr1','attr2');
$baseline = [
[ 'dudeman23', 'What??', ], [ 'dudeman23', 'What??', ],
[ 'dudeman23', 'What??', ], [ 'dudeman23', 'What??', ]
];
is_deeply \@values, $baseline;

my @names = $hdfobj->allAttrNames;
is_deeply \@names, [ 'attr1', 'attr2', ];

# Test building the groupIndex
$hdfobj->_buildGroupIndex('attr1','attr2');
$hdfobj->_buildGroupIndex('attr2');
$hdfobj->_buildGroupIndex('attr1','attr3');

$baseline = {
'attr1attr2' => {
'dudeman23What??' => [ '/', '/dude2', '/mygroup', '/mygroup/subgroup' ]
},
'attr1attr3' => {
'dudeman23_undef_' => [ '/', '/dude2', '/mygroup', '/mygroup/subgroup' ]
},
'attr2' => {
'What??' => [ '/', '/dude2', '/mygroup', '/mygroup/subgroup' ]
}
};

my $result = $hdfobj->{groupIndex};
is_deeply $result, $baseline or diag explain $result;

my @groups = $hdfobj->getGroupsByAttr( 'attr1' => 'dudeman23',
'attr2' => 'What??');
$baseline = [
'/',
'/dude2',
'/mygroup',
'/mygroup/subgroup',
];
is_deeply \@groups, $baseline;

# clean up file
}
unlink $filename if( -e $filename);

done_testing;
212 changes: 0 additions & 212 deletions t/ztotal_index.t

This file was deleted.

0 comments on commit 117fbe0

Please sign in to comment.