Commit ead6ab2e authored by Yang Tse's avatar Yang Tse
Browse files

Abort test if it seems that it would have run forever. This is just to prevent

test hanging and actually is an indication that there's a condition that is
not being properly handled at some point in the library.

Loop counter limits might need to be further increased on false positives.
parent 5c3dc49f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ int test(char *URL)
  int running;
  int max_fd;
  int rc;
  int loop=10;
  int loop1 = 10;
  int loop2 = 20;

  curl_global_init(CURL_GLOBAL_ALL);
  c = curl_easy_init();
@@ -42,12 +43,15 @@ int test(char *URL)

      interval.tv_sec = 1;
      interval.tv_usec = 0;
      int loop2 = 20;

      fprintf(stderr, "curl_multi_perform()\n");

      do {
        res = curl_multi_perform(m, &running);
      } while (res == CURLM_CALL_MULTI_PERFORM);
      } while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM));
      if (loop2 <= 0)
        break;
      if(!running) {
        /* This is where this code is expected to reach */
        int numleft;
@@ -82,7 +86,12 @@ int test(char *URL)

      /* we only allow a certain number of loops to avoid hanging here
         forever */
    } while(--loop>0);
    } while(--loop1>0);
    if ((loop1 <= 0) || (loop2 <= 0)) {
      fprintf(stderr, "ABORTING TEST, since it seems "
              "that it would have run forever.\n");
      ret = 77;
    }
  }

  curl_multi_remove_handle(m, c);
+21 −8
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ int test(char *URL)
  int still_running;
  int i = -1;
  CURLMsg *msg;
  int loop1 = 20;
  int loop2 = 40;

  multi = curl_multi_init();

@@ -14,8 +16,10 @@ int test(char *URL)
  curl_easy_setopt(curls, CURLOPT_URL, URL);
  curl_multi_add_handle(multi, curls);

  while ( CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running) );
  while(still_running) {
  while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM == 
         curl_multi_perform(multi, &still_running)));

  while ((loop1>0) && (--loop2>0) && (still_running)) {
    struct timeval timeout;
    int rc;
    fd_set fdread;
@@ -34,15 +38,24 @@ int test(char *URL)
        break;
      case 0:
      default:
        while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running));
        loop1 = 20;
        while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM == 
               curl_multi_perform(multi, &still_running)));
        break;
    }
  }
  if ((loop1 <= 0) || (loop2 <= 0)) {
    fprintf(stderr, "ABORTING TEST, since it seems "
            "that it would have run forever.\n");
    i = 77;
  }
  else {
    msg = curl_multi_info_read(multi, &still_running);
    if(msg)
      /* this should now contain a result code from the easy handle,
         get it */
      i = msg->data.result;
  }

  curl_multi_cleanup(multi);
  curl_easy_cleanup(curls);
+22 −8
Original line number Diff line number Diff line
@@ -175,6 +175,9 @@ int test(char *URL)
  int i = 0;
  CURLMsg *msg;

  int loop1 = 40;
  int loop2 = 20;

  if(arg2) {
    portnum = atoi(arg2);
  }
@@ -205,15 +208,16 @@ int test(char *URL)

    res = curl_multi_add_handle(multi, p.curl);

    while(!done) {
    while ((--loop1>0) && (loop2>0) && (!done)) {
      fd_set rd, wr, exc;
      int max_fd;
      struct timeval interval;

      interval.tv_sec = 1;
      interval.tv_usec = 0;
      loop2 = 20;

      while (res == CURLM_CALL_MULTI_PERFORM) {
      while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
        res = curl_multi_perform(multi, &running);
        fprintf(stderr, "running=%d res=%d\n",running,res);
        if (running <= 0) {
@@ -221,7 +225,7 @@ int test(char *URL)
          break;
        }
      }
      if(done)
      if ((loop2 <= 0) || (done))
        break;

      if (res != CURLM_OK) {
@@ -249,13 +253,23 @@ int test(char *URL)

      res = CURLM_CALL_MULTI_PERFORM;
    }

    if ((loop1 <= 0) || (loop2 <= 0)) {
      fprintf(stderr, "ABORTING TEST, since it seems "
              "that it would have run forever.\n");
      i = 77;
    }
    else {
      msg = curl_multi_info_read(multi, &running);
      /* this should now contain a result code from the easy handle, get it */
      if(msg)
        i = msg->data.result;
    }
  }

  if ((loop1>0) && (loop2>0)) {
    fprintf(stderr, "all done\n");
  }

  curl_multi_remove_handle(multi, p.curl);
  curl_easy_cleanup(p.curl);
+12 −3
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ int test(char *URL)
  int running;
  char done=FALSE;
  CURLM *m;
  int loop1 = 40;
  int loop2 = 20;

  if (!arg2) {
    fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
@@ -82,22 +84,23 @@ int test(char *URL)

  res = (int)curl_multi_add_handle(m, curl);

  while(!done) {
  while ((--loop1>0) && (loop2>0) && (!done)) {
    fd_set rd, wr, exc;
    int max_fd;
    struct timeval interval;

    interval.tv_sec = 1;
    interval.tv_usec = 0;
    loop2 = 20;

    while (res == CURLM_CALL_MULTI_PERFORM) {
    while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
      res = (int)curl_multi_perform(m, &running);
      if (running <= 0) {
        done = TRUE;
        break;
      }
    }
    if(done)
    if ((loop2 <= 0) || (done))
      break;

    if (res != CURLM_OK) {
@@ -125,6 +128,12 @@ int test(char *URL)
    res = CURLM_CALL_MULTI_PERFORM;
  }

  if ((loop1 <= 0) || (loop2 <= 0)) {
    fprintf(stderr, "ABORTING TEST, since it seems "
            "that it would have run forever.\n");
    res = 77;
  }

#ifdef LIB529
  /* test 529 */
  curl_multi_remove_handle(m, curl);
+12 −3
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ int test(char *URL)
  CURLM *m;
  int current=0;
  int i;
  int loop1 = 40;
  int loop2 = 20;

  /* In windows, this will init the winsock stuff */
  curl_global_init(CURL_GLOBAL_ALL);
@@ -67,15 +69,16 @@ int test(char *URL)

  fprintf(stderr, "Start at URL 0\n");

  while(!done) {
  while ((--loop1>0) && (loop2>0) && (!done)) {
    fd_set rd, wr, exc;
    int max_fd;
    struct timeval interval;

    interval.tv_sec = 1;
    interval.tv_usec = 0;
    loop2 = 20;

    while (res == CURLM_CALL_MULTI_PERFORM) {
    while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
      res = (int)curl_multi_perform(m, &running);
      if (running <= 0) {
#ifdef LIB527
@@ -112,7 +115,7 @@ int test(char *URL)
        break;
      }
    }
    if(done)
    if ((loop2 <= 0) || (done))
      break;

    if (res != CURLM_OK) {
@@ -140,6 +143,12 @@ int test(char *URL)
    res = CURLM_CALL_MULTI_PERFORM;
  }

  if ((loop1 <= 0) || (loop2 <= 0)) {
    fprintf(stderr, "ABORTING TEST, since it seems "
            "that it would have run forever.\n");
    res = 77;
  }

#ifndef LIB527
  /* get NUM_HANDLES easy handles */
  for(i=0; i < NUM_HANDLES; i++) {
Loading