westonpace commented on a change in pull request #11294:
URL: https://github.com/apache/arrow/pull/11294#discussion_r731329143



##########
File path: python/pyarrow/tests/test_dataset.py
##########
@@ -422,6 +422,42 @@ def test_scanner(dataset, dataset_reader):
     assert table.num_rows == scanner.count_rows()
 
 
+def test_scanner_backpressure():
+    batch = pa.record_batch([pa.array([1, 2, 3])], names=['data'])
+    num_read = 0
+    min_read = 64  # From kDefaultBackpressureHigh in scanner.h
+    end = 200
+
+    def counting_generator():
+        nonlocal num_read
+        while num_read < end:
+            time.sleep(0.01)
+            num_read += 1
+            yield batch
+
+    scanner = ds.Scanner.from_batches(
+        counting_generator(), batch.schema, use_threads=True, use_async=True)
+
+    _batch_iter = scanner.to_batches()  # This line starts the scan
+
+    start = time.time()
+
+    def duration():
+        return time.time() - start
+
+    last_num_read = 0
+    backpressure_probably_hit = False
+    while duration() < 10:
+        if num_read > min_read and num_read == last_num_read:
+            backpressure_probably_hit = True
+            break
+        last_num_read = num_read
+        time.sleep(0.5)

Review comment:
       If we do something like 
https://issues.apache.org/jira/browse/ARROW-14367 we can remove the timing 
dependency.  That being said, I understand the concern, and there was similar 
concern in the dataset write backpressure PR: 
https://github.com/apache/arrow/pull/11286#discussion_r728555922
   
   I will remove this test from this PR and rely on the existing python test.  
When ARROW-14367 is implemented the timing dependency can be removed from the 
other test (and we can maybe reintroduce this test at that point).




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to