Copilot commented on code in PR #3679:
URL: https://github.com/apache/brpc/pull/3679#discussion_r4387042258


##########
test/fuzzing/fuzz_concurrency.cpp:
##########
@@ -0,0 +1,49 @@
+// 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.
+
+// Fuzz the auto concurrency limiter 
(src/brpc/policy/auto_concurrency_limiter.cpp):
+// fuzz bytes drive a stream of (error_code, latency_us) responses and
+// request ticks through the real gradient-based limiter, including the
+// recovery/reset paths exercised by bursts of errors.
+
+#include "brpc/policy/auto_concurrency_limiter.h"
+
+extern "C" int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+    if (size < 8) {
+        return 0;
+    }
+
+    brpc::policy::AutoConcurrencyLimiter limiter;
+
+    const size_t n = size / 8;
+    for (size_t i = 0; i < n; ++i) {
+        uint64_t v = 0;
+        for (size_t b = 0; b < 8; ++b) {
+            v = (v << 8) | data[i * 8 + b];
+        }
+        const int error_code = static_cast<int>(v & 0xff);
+        const int64_t latency_us = static_cast<int64_t>(v >> 8) % 10000000;
+        limiter.OnResponded(error_code, latency_us);

Review Comment:
   `OnResponded()` uses real time rather than `latency_us`: with default 
settings, completing a sample window takes roughly 20 ms or more, and 
remeasurement cannot start until at least 25 seconds after construction. 
Because each input creates a fresh limiter, fast inputs miss the intended 
limit-update and reset paths, making coverage depend on execution speed rather 
than input bytes. Drive sampling and reset deadlines with deterministic 
synthetic time, following the sampling approach in 
`test/brpc_auto_concurrency_limiter_unittest.cpp`, so ordinary inputs can 
reproducibly reach these transitions.



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