lidavidm commented on a change in pull request #9808:
URL: https://github.com/apache/arrow/pull/9808#discussion_r604951143
##########
File path: cpp/src/arrow/util/async_generator_test.cc
##########
@@ -570,14 +659,134 @@ TEST(TestAsyncUtil, StackOverflow) {
#endif
-TEST(TestAsyncUtil, Background) {
+class BackgroundGeneratorTestFixture : public GeneratorTestFixture {
+ protected:
+ AsyncGenerator<TestInt> Make(const std::vector<TestInt>& it,
+ int max_q = kDefaultBackgroundMaxQ,
+ int q_restart = kDefaultBackgroundQRestart) {
+ bool slow = GetParam();
+ return BackgroundAsyncVectorIt(it, slow, max_q, q_restart);
+ }
+};
+
+TEST_P(BackgroundGeneratorTestFixture, Empty) {
+ auto background = Make({});
+ AssertGeneratorExhausted(background);
+}
+
+TEST_P(BackgroundGeneratorTestFixture, Basic) {
std::vector<TestInt> expected = {1, 2, 3};
- auto background = BackgroundAsyncVectorIt(expected);
+ auto background = Make(expected);
auto future = CollectAsyncGenerator(background);
ASSERT_FINISHES_OK_AND_ASSIGN(auto collected, future);
ASSERT_EQ(expected, collected);
}
+TEST_P(BackgroundGeneratorTestFixture, BadResult) {
+ std::shared_ptr<ManualIteratorControl<TestInt>> iterator_control;
+ auto iterator = MakePushIterator<TestInt>(&iterator_control);
+ // Enough valid items to fill the queue and then some
+ for (int i = 0; i < 5; i++) {
+ iterator_control->Push(i);
+ }
+ // Next fail
+ iterator_control->Push(Status::Invalid("XYZ"));
+ ASSERT_OK_AND_ASSIGN(
+ auto generator,
+ MakeBackgroundGenerator(std::move(iterator),
internal::GetCpuThreadPool(), 4, 2));
+
+ ASSERT_FINISHES_OK_AND_EQ(TestInt(0), generator());
+ // Have not yet restarted so next results should always be valid
+ ASSERT_FINISHES_OK_AND_EQ(TestInt(1), generator());
+ ASSERT_FINISHES_OK_AND_EQ(TestInt(2), generator());
Review comment:
It looks like this sometimes fails on Windows.
```
[ RUN ]
BackgroundGeneratorTests/BackgroundGeneratorTestFixture.BadResult/1
C:/projects/arrow/cpp/src/arrow/util/async_generator_test.cc(701): error:
Failed
'_error_or_value70.status()' failed with Invalid: XYZ
[ FAILED ]
BackgroundGeneratorTests/BackgroundGeneratorTestFixture.BadResult/1, where
GetParam() = true (0 ms)
```
The previous call does restart the background thread, so it's possible it'll
get to the failing value in this call.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]