@@ -344,6 +344,57 @@ CO_TEST_F(BiDiServiceE2ETest, StreamThrowsDeclaredException) {
344344 co_await folly::coro::collectAll (std::move (sinkTask), std::move (streamTask));
345345}
346346
347+ CO_TEST_F (BiDiServiceE2ETest, StreamThrowsUndeclaredException) {
348+ constexpr int64_t kStreamItemsUntilThrow = 500 ;
349+
350+ struct Handler : public ServiceHandler <detail::test::TestBiDiService> {
351+ folly::coro::Task<StreamTransformation<int64_t , int64_t >> co_canThrow ()
352+ override {
353+ co_return StreamTransformation<int64_t , int64_t >{
354+ [](folly::coro::AsyncGenerator<int64_t &&>)
355+ -> folly::coro::AsyncGenerator<int64_t &&> {
356+ for (std::size_t i = 0 ; i < kStreamItemsUntilThrow ; ++i) {
357+ co_yield int64_t (i);
358+ }
359+ throw std::runtime_error{" For test" };
360+ }};
361+ }
362+ };
363+
364+ testConfig ({std::make_shared<Handler>()});
365+ auto client = makeClient<detail::test::TestBiDiService>();
366+ BidirectionalStream<int64_t , int64_t > stream = co_await client->co_canThrow ();
367+
368+ auto sinkGen =
369+ folly::coro::co_invoke ([]() -> folly::coro::AsyncGenerator<int64_t &&> {
370+ for (int64_t i = 0 ; i < 1000 ; ++i) {
371+ co_yield int64_t (i);
372+ }
373+ });
374+ auto sinkTask = folly::coro::co_invoke (
375+ [clientSink = std::move (stream.sink ),
376+ sinkGen = std::move (sinkGen)]() mutable -> folly::coro::Task<void > {
377+ co_await std::move (clientSink).sink (std::move (sinkGen));
378+ });
379+
380+ auto streamTask = folly::coro::co_invoke (
381+ [&, streamGen = std::move (stream.stream ).toAsyncGenerator ()]() mutable
382+ -> folly::coro::Task<void > {
383+ for (int64_t i = 0 ; i < kStreamItemsUntilThrow ; ++i) {
384+ auto next = co_await streamGen.next ();
385+ if (!next) {
386+ CO_FAIL () << fmt::format (
387+ " Did not receive all stream elements, expected {} but got {}" ,
388+ kStreamItemsUntilThrow ,
389+ i);
390+ }
391+ }
392+ EXPECT_THROW (
393+ co_await streamGen.next (), apache::thrift::TApplicationException);
394+ });
395+ co_await folly::coro::collectAll (std::move (sinkTask), std::move (streamTask));
396+ }
397+
347398CO_TEST_F (BiDiServiceE2ETest, IgnoreInputProduceOutput) {
348399 constexpr int64_t kTestLimit = 100 ;
349400
0 commit comments