diff --git a/src/inc/til/spsc.h b/src/inc/til/spsc.h index 374306637fb9..344a031718c2 100644 --- a/src/inc/til/spsc.h +++ b/src/inc/til/spsc.h @@ -425,6 +425,7 @@ namespace til::spsc { drop(); _arc = std::exchange(other._arc, nullptr); + return *this; } ~producer() @@ -543,6 +544,7 @@ namespace til::spsc { drop(); _arc = std::exchange(other._arc, nullptr); + return *this; } ~consumer() diff --git a/src/til/ut_til/SPSCTests.cpp b/src/til/ut_til/SPSCTests.cpp index 77f3d1116136..ad1d64243ae0 100644 --- a/src/til/ut_til/SPSCTests.cpp +++ b/src/til/ut_til/SPSCTests.cpp @@ -50,12 +50,44 @@ class SPSCTests TEST_CLASS_PROPERTY(L"TestTimeout", L"0:0:10") // 10s timeout END_TEST_CLASS() + TEST_METHOD(SmokeTest); TEST_METHOD(DropEmptyTest); TEST_METHOD(DropSameRevolutionTest); TEST_METHOD(DropDifferentRevolutionTest); TEST_METHOD(IntegrationTest); }; +void SPSCTests::SmokeTest() +{ + // This test mostly ensures that the API wasn't broken. + + // construction + auto [tx, rx] = til::spsc::channel(32); + std::array data{}; + + // move constructor + til::spsc::producer tx2(std::move(tx)); + til::spsc::consumer rx2(std::move(rx)); + + // move assignment operator + tx = std::move(tx2); + rx = std::move(rx2); + + // push + tx.emplace(0); + tx.push(data.begin(), data.end()); + tx.push(til::spsc::block_initially, data.begin(), data.end()); + tx.push(til::spsc::block_forever, data.begin(), data.end()); + tx.push_n(data.begin(), data.size()); + tx.push_n(til::spsc::block_initially, data.begin(), data.size()); + tx.push_n(til::spsc::block_forever, data.begin(), data.size()); + + // pop + std::optional x = rx.pop(); + rx.pop_n(til::spsc::block_initially, data.begin(), data.size()); + rx.pop_n(til::spsc::block_forever, data.begin(), data.size()); +} + void SPSCTests::DropEmptyTest() { auto [tx, rx] = til::spsc::channel(5);