Skip to content

Commit

Permalink
Add tests for frontend maladies
Browse files Browse the repository at this point in the history
This is stolen from PR openPMD#804.
This PR fixes the issues from that one, so those tests are passing now.
  • Loading branch information
franzpoeschel committed Feb 19, 2021
1 parent 6f21962 commit 7866418
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,53 @@ TEST_CASE( "available_chunks_test_json", "[serial][json]" )
}
}

TEST_CASE( "multiple_series_handles_test", "[serial]" )
{
/*
* First test: No premature flushes through destructor when another copy
* is still around
*/
{
std::unique_ptr< openPMD::Series > series_ptr;
{
openPMD::Series series(
"sample%T.json", openPMD::AccessType::CREATE );
series_ptr = std::make_unique< openPMD::Series >( series );
/*
* we have two handles for the same Series instance now:
* series and series_ptr
* series goes out of scope before series_ptr
* destructor should only do a flush after both of them go out of
* scope, but it will currently run directly after this comment
* since no iteration has been written yet, an error will be thrown
*/
}
series_ptr->iterations[ 0 ].meshes[ "E" ][ "x" ].makeEmpty< int >( 1 );
}
/*
* Second test: A Series handle should remain accessible even if the
* original handle is destroyed
*/
{
std::unique_ptr< openPMD::Series > series_ptr;
{
openPMD::Series series(
"sample%T.json", openPMD::AccessType::CREATE );
series_ptr = std::make_unique< openPMD::Series >( series );
series_ptr->iterations[ 0 ].meshes[ "E" ][ "x" ].makeEmpty< int >(
1 );
}
/*
* series_ptr is still in scope, but the original Series instance
* has been destroyed
* since internal pointers actually refer to the original *handle*,
* doing anything with series_ptr now (such as flushing it) yields
* nullpointer accesses
*/
series_ptr->flush();
}
}

void
close_iteration_test( std::string file_ending )
{
Expand Down

0 comments on commit 7866418

Please sign in to comment.