kecookier commented on code in PR #12986:
URL: https://github.com/apache/gluten/pull/12986#discussion_r3976336125


##########
cpp/velox/tests/VeloxShuffleReaderTest.cc:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Regression guard for the rss_sort reader EOS infinite-loop fix. Pre-fix,
+// an EOS hit mid-page inside GlutenByteInputStream::readBytes/skip drove
+// next(true) which silently no-op'd on EOS, spinning forever. Post-fix,
+// next(true) VELOX_FAIL's on EOS. These tests drive the real Presto
+// deserialize path through a controllable fake arrow::io::InputStream and
+// assert the throw instead of a hang.
+
+#include <gtest/gtest.h>
+
+#include <arrow/buffer.h>
+#include <arrow/io/interfaces.h>
+#include <arrow/memory_pool.h>
+
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "compute/VeloxBackend.h"
+#include "config/GlutenConfig.h"
+#include "config/VeloxConfig.h"
+#include "memory/VeloxMemoryManager.h"
+#include "shuffle/VeloxShuffleReader.h"
+#include "tests/utils/TestAllocationListener.h"
+#include "tests/utils/TestStreamReader.h"
+#include "velox/common/base/tests/GTestUtils.h"
+#include "velox/serializers/PrestoSerializer.h"
+#include "velox/type/Type.h"
+#include "velox/vector/tests/utils/VectorTestBase.h"
+
+using namespace facebook::velox;
+using namespace facebook::velox::test;
+
+namespace gluten {
+
+namespace {
+// A minimal arrow::io::InputStream backed by a fixed in-memory payload
+class FakeInputStream final : public arrow::io::InputStream {
+ public:
+  explicit FakeInputStream(std::vector<uint8_t> payload = {}, bool 
negativeRead = false)
+      : payload_(std::move(payload)), negativeRead_(negativeRead) {}
+
+  arrow::Status Close() override {
+    closed_ = true;
+    return arrow::Status::OK();
+  }
+  arrow::Result<int64_t> Tell() const override {
+    return pos_;
+  }
+  bool closed() const override {
+    return closed_;
+  }
+
+  arrow::Result<int64_t> Read(int64_t nbytes, void* out) override {
+    if (negativeRead_) {
+      return static_cast<int64_t>(-1);
+    }
+    int64_t toRead = std::min<int64_t>(nbytes, 
static_cast<int64_t>(payload_.size()) - pos_);
+    if (toRead > 0) {
+      std::memcpy(out, payload_.data() + pos_, toRead);
+      pos_ += toRead;
+    }

Review Comment:
   How about simulating the infinite loop like this: #12983 
   
   
https://github.com/apache/gluten/pull/12983/changes#diff-045326b2ecdd51a0420e4d75c2fd596f350c106c32ac9224e09d43d8dc6c5771R116



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to