Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
progress: Track total times following redirects
Update the progress timers `t_nslookup`, `t_connect`, `t_appconnect`, `t_pretransfer`, and `t_starttransfer` to track the total times for these activities when a redirect is followed. Previously, only the times for the most recent request would be tracked. As a related change, rename `Curl_pgrsResetTimesSizes` to `Curl_pgrsResetTransferSizes` now that the function only resets transfer sizes and no longer modified any of the progress timers. Added test case 1399. Fixes #522 and Known Bug 1.8 Reported-by: joshhe
- Loading branch information
Showing
8 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<testcase> | ||
<info> | ||
<keywords> | ||
unittest | ||
Curl_pgrsTime | ||
</keywords> | ||
</info> | ||
|
||
# | ||
# Client-side | ||
<client> | ||
<server> | ||
none | ||
</server> | ||
<features> | ||
unittest | ||
</features> | ||
<name> | ||
Curl_pgrsTime unit tests | ||
</name> | ||
<tool> | ||
unit1399 | ||
</tool> | ||
</client> | ||
|
||
</testcase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*************************************************************************** | ||
* _ _ ____ _ | ||
* Project ___| | | | _ \| | | ||
* / __| | | | |_) | | | ||
* | (__| |_| | _ <| |___ | ||
* \___|\___/|_| \_\_____| | ||
* | ||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. | ||
* | ||
* This software is licensed as described in the file COPYING, which | ||
* you should have received as part of this distribution. The terms | ||
* are also available at https://curl.haxx.se/docs/copyright.html. | ||
* | ||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell | ||
* copies of the Software, and permit persons to whom the Software is | ||
* furnished to do so, under the terms of the COPYING file. | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
* KIND, either express or implied. | ||
* | ||
***************************************************************************/ | ||
#include "curlcheck.h" | ||
|
||
#include "urldata.h" | ||
#include "timeval.h" | ||
#include "progress.h" | ||
#include "time.h" | ||
|
||
const int usec_magnitude = 1000000; | ||
const int test_execution_time = 500; | ||
int aggregate_timerids[] = { | ||
TIMER_NAMELOOKUP, | ||
TIMER_CONNECT, | ||
TIMER_APPCONNECT, | ||
TIMER_PRETRANSFER, | ||
TIMER_STARTTRANSFER, | ||
}; | ||
|
||
static bool unit_setup(void) | ||
{ | ||
return false; | ||
} | ||
|
||
static void unit_stop(void) | ||
{ | ||
|
||
} | ||
|
||
static void complete_aggregate_timed_activities(struct Curl_easy *data) | ||
{ | ||
for(unsigned int i = 0; i < sizeof(aggregate_timerids); i++) { | ||
Curl_pgrsTime(data, aggregate_timerids[i]); | ||
} | ||
} | ||
|
||
static bool within_seconds(time_t time, int seconds) | ||
{ | ||
long diff = (long) (time - (usec_magnitude * seconds)); | ||
return labs(diff) < test_execution_time; | ||
} | ||
|
||
UNITTEST_START | ||
struct Curl_easy data; | ||
struct timeval now = Curl_tvnow(); | ||
|
||
/* set the startsingle time to a second ago. This time is used by | ||
* Curl_pgrsTime to calculate how much time the events takes */ | ||
data.progress.t_startsingle.tv_sec = now.tv_sec - 1; | ||
data.progress.t_startsingle.tv_usec = now.tv_usec; | ||
|
||
/* pretend we've just completed activities */ | ||
complete_aggregate_timed_activities(&data); | ||
|
||
fail_unless(within_seconds(data.progress.t_nslookup, 1), | ||
"about 1 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_connect, 1), | ||
"about 1 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_appconnect, 1), | ||
"about 1 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_pretransfer, 1), | ||
"about 1 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_starttransfer, 1), | ||
"about 1 second should have passed"); | ||
|
||
/* pretend we've just completed activities again */ | ||
complete_aggregate_timed_activities(&data); | ||
|
||
fail_unless(within_seconds(data.progress.t_nslookup, 2), | ||
"about 2 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_connect, 2), | ||
"about 2 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_appconnect, 2), | ||
"about 2 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_pretransfer, 2), | ||
"about 2 second should have passed"); | ||
fail_unless(within_seconds(data.progress.t_starttransfer, 2), | ||
"about 2 second should have passed"); | ||
UNITTEST_STOP |