arpadboda commented on a change in pull request #810:
URL: https://github.com/apache/nifi-minifi-cpp/pull/810#discussion_r440371729



##########
File path: extensions/http-curl/tests/HTTPHandlers.h
##########
@@ -489,30 +489,39 @@ class InvokeHTTPResponse501Handler : public 
ServerAwareHandler {
 
 class TimeoutingHTTPHandler : public ServerAwareHandler {
 public:
-  TimeoutingHTTPHandler(std::chrono::milliseconds wait_ms)
-      : wait_(wait_ms) {
+  TimeoutingHTTPHandler(std::vector<std::chrono::milliseconds> wait_times)
+      : wait_times_(wait_times) {
   }
   bool handlePost(CivetServer *, struct mg_connection *conn) {
-    std::this_thread::sleep_for(wait_);
-    mg_printf(conn, "HTTP/1.1 201 OK\r\nContent-Type: 
text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    respond(conn);
     return true;
   }
   bool handleGet(CivetServer *, struct mg_connection *conn) {
-    std::this_thread::sleep_for(wait_);
-    mg_printf(conn, "HTTP/1.1 201 OK\r\nContent-Type: 
text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    respond(conn);
     return true;
   }
   bool handleDelete(CivetServer *, struct mg_connection *conn) {
-    std::this_thread::sleep_for(wait_);
-    mg_printf(conn, "HTTP/1.1 201 OK\r\nContent-Type: 
text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    respond(conn);
     return true;
   }
   bool handlePut(CivetServer *, struct mg_connection *conn) {
-    std::this_thread::sleep_for(wait_);
-    mg_printf(conn, "HTTP/1.1 201 OK\r\nContent-Type: 
text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    respond(conn);
     return true;
   }
-protected:
-  std::chrono::milliseconds wait_;
+ private:
+  void respond(struct mg_connection *conn) {
+    if (wait_times_.size() > 0 && wait_times_[0].count() > 0) {
+      std::this_thread::sleep_for(wait_times_[0]);
+    }
+    int chunk_count = std::max(static_cast<int>(wait_times_.size()) - 1, 0);
+    mg_printf(conn, "HTTP/1.1 201 OK\r\nContent-Type: 
text/plain\r\nContent-Length: %d\r\nConnection: close\r\n\r\n", chunk_count);
+    for (int chunkIdx = 0; chunkIdx < chunk_count; ++chunkIdx) {
+      mg_printf(conn, "a");

Review comment:
       Tricky :)




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to