Skip to content

Commit 7d119b6

Browse files
evanjzoumeta-codesync[bot]
authored andcommitted
Stream throws undeclared exception
Summary: Test undeclared exceptions in the stream Reviewed By: sazonovkirill Differential Revision: D85378813 fbshipit-source-id: 3bf3eb8d877bc4e75c1445e7655051db7b62d32e
1 parent f349bc2 commit 7d119b6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

third-party/thrift/src/thrift/lib/cpp2/async/tests/BiDiServiceE2ETest.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
347398
CO_TEST_F(BiDiServiceE2ETest, IgnoreInputProduceOutput) {
348399
constexpr int64_t kTestLimit = 100;
349400

0 commit comments

Comments
 (0)