@@ -563,6 +563,56 @@ TEST_F(LiveBlockingTests, TestConnectWhenGatewayNotUp) {
563563 ASSERT_THROW (builder_.BuildBlocking (), databento::TcpError);
564564}
565565
566+ TEST_F (LiveBlockingTests, TestNextRecordThrowsOnGatewayClose) {
567+ constexpr auto kTsOut = false ;
568+ constexpr OhlcvMsg kRec {DummyHeader<OhlcvMsg>(RType::Ohlcv1M), 1 , 2 , 3 , 4 , 5 };
569+
570+ bool should_close{};
571+ std::mutex should_close_mutex;
572+ std::condition_variable should_close_cv;
573+ bool has_closed{};
574+ std::mutex has_closed_mutex;
575+ std::condition_variable has_closed_cv;
576+ const mock::MockLsgServer mock_server{
577+ dataset::kXnasItch , kTsOut ,
578+ [kRec , &should_close, &should_close_cv, &should_close_mutex, &has_closed,
579+ &has_closed_cv, &has_closed_mutex](mock::MockLsgServer& self) {
580+ self.Accept ();
581+ self.Authenticate ();
582+ self.SendRecord (kRec );
583+ {
584+ std::unique_lock<std::mutex> lock{should_close_mutex};
585+ should_close_cv.wait (lock, [&should_close] { return should_close; });
586+ }
587+ self.Close ();
588+ {
589+ const std::lock_guard<std::mutex> lock{has_closed_mutex};
590+ has_closed = true ;
591+ has_closed_cv.notify_one ();
592+ }
593+ }};
594+
595+ LiveBlocking target = builder_.SetDataset (dataset::kXnasItch )
596+ .SetSendTsOut (kTsOut )
597+ .SetAddress (kLocalhost , mock_server.Port ())
598+ .BuildBlocking ();
599+ const auto rec = target.NextRecord ();
600+ ASSERT_TRUE (rec.Holds <OhlcvMsg>());
601+ EXPECT_EQ (rec.Get <OhlcvMsg>(), kRec );
602+ // Signal server to close connection
603+ {
604+ const std::lock_guard<std::mutex> lock{should_close_mutex};
605+ should_close = true ;
606+ should_close_cv.notify_one ();
607+ }
608+ // Wait for server to close
609+ {
610+ std::unique_lock<std::mutex> lock{has_closed_mutex};
611+ has_closed_cv.wait (lock, [&has_closed] { return has_closed; });
612+ }
613+ ASSERT_THROW (target.NextRecord (), databento::DbnResponseError);
614+ }
615+
566616TEST_F (LiveBlockingTests, TestReconnectAndResubscribe) {
567617 constexpr auto kTsOut = false ;
568618 constexpr TradeMsg kRec {DummyHeader<TradeMsg>(RType::Mbp0),
0 commit comments