From d3948978e0b01fde0acadd1b1f8546a666fd0d31 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 24 Jul 2020 21:17:47 +0300 Subject: [PATCH] Fix file unit tests --- components/streams/src/filestream.cpp | 4 ++++ components/streams/test/filestream_unit.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/streams/src/filestream.cpp b/components/streams/src/filestream.cpp index 9121abbdd..102d05890 100644 --- a/components/streams/src/filestream.cpp +++ b/components/streams/src/filestream.cpp @@ -399,6 +399,10 @@ bool File::end() { UNIQUE_LOCK(mutex_, lk); + while (jobs_ > 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + if (mode_ == Mode::Read) { if (istream_) { istream_->close(); diff --git a/components/streams/test/filestream_unit.cpp b/components/streams/test/filestream_unit.cpp index ec05be42f..25c33b580 100644 --- a/components/streams/test/filestream_unit.cpp +++ b/components/streams/test/filestream_unit.cpp @@ -43,7 +43,8 @@ TEST_CASE("ftl::stream::File write and read", "[stream]") { }); REQUIRE( reader->begin(false) ); - //reader->tick(); + reader->tick(100); + reader->end(); //REQUIRE( tspkt.timestamp == 0 ); REQUIRE( tspkt.streamID == (uint8_t)2 ); @@ -73,7 +74,8 @@ TEST_CASE("ftl::stream::File write and read", "[stream]") { }); REQUIRE( reader->begin(false) ); - //reader->tick(); + reader->tick(100); + reader->end(); REQUIRE( count == 3 ); REQUIRE( tspkt.timestamp > 0 ); @@ -105,21 +107,22 @@ TEST_CASE("ftl::stream::File write and read", "[stream]") { }); REQUIRE( reader->begin(false) ); - //reader->tick(); + reader->tick(100); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); REQUIRE( count == 1 ); //REQUIRE( tspkt.timestamp == 0 ); //auto itime = tspkt.timestamp; count = 0; - reader->tick(0); + reader->tick(101); std::this_thread::sleep_for(std::chrono::milliseconds(10)); REQUIRE( count == 1 ); //REQUIRE( tspkt.timestamp == itime+ftl::timer::getInterval() ); count = 0; - reader->tick(0); + reader->tick(102); std::this_thread::sleep_for(std::chrono::milliseconds(10)); REQUIRE( count == 1 ); -- GitLab