10000 Update AbuseLimitHandlerTest · hub4j/github-api@d10f7e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d10f7e0

Browse files
committed
Update AbuseLimitHandlerTest
1 parent 6609bd4 commit d10f7e0

File tree

8 files changed

+387
-367
lines changed

8 files changed

+387
-367
lines changed

src/main/java/org/kohsuke/github/AbuseLimitHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
108108
}
109109
};
110110

111+
// If "Retry-After" missing, wait for unambiguously over one minute per GitHub guidance
112+
static long DEFAULT_WAIT_MILLIS = 61 * 1000;
113+
111114
/*
112115
* Exposed for testability. Given an http response, find the retry-after header field and parse it as either a
113116
* number or a date (the spec allows both). If no header is found, wait for a reasonably amount of time.
@@ -116,7 +119,7 @@ long parseWaitTime(HttpURLConnection uc) {
116119
String v = uc.getHeaderField("Retry-After");
117120
if (v == null) {
118121
// can't tell, wait for unambiguously over one minute per GitHub guidance
119-
return 61 * 1000;
122+
return DEFAULT_WAIT_MILLIS;
120123
}
121124

122125
try {

src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java

Lines changed: 282 additions & 311 deletions
Large diffs are not rendered by default.

src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/2-r_h_t_fail.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
}
1212
},
1313
"response": {
14-
"status": 403,
14+
"status": 429,
1515
"body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}",
1616
"headers": {
1717
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
1818
"Content-Type": "application/json; charset=utf-8",
1919
"Server": "GitHub.com",
20-
"Status": "403 Forbidden",
21-
"gh-limited-by": "search-elapsed-time-shared-grouped",
22-
"X-RateLimit-Limit": "5000",
23-
"X-RateLimit-Remaining": "4000",
24-
"X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}",
20+
"Status": "429 Too Many Requests",
21+
"Retry-After": "8",
2522
"Cache-Control": "private, max-age=60, s-maxage=60",
2623
"Vary": [
2724
"Accept, Authorization, Cookie, X-GitHub-OTP",
@@ -45,8 +42,8 @@
4542
},
4643
"uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
4744
"persistent": true,
48-
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests",
45+
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1",
4946
"requiredScenarioState": "Started",
50-
"newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests-2",
47+
"newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1-2",
5148
"insertionIndex": 2
5249
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
2+
"id": "574da117-6845-46d8-b2c1-4415546ca670",
33
"name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests",
44
"request": {
55
"url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests",
@@ -11,21 +11,23 @@
1111
}
1212
},
1313
"response": {
14-
"status": 429,
15-
"body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}",
14+
"status": 200,
15+
"bodyFileName": "3-r_h_t_fail.json",
1616
"headers": {
1717
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
1818
"Content-Type": "application/json; charset=utf-8",
1919
"Server": "GitHub.com",
20-
"Status": "429 Too Many Requests",
21-
"Retry-After": "42",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4922",
23+
"X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}",
2224
"Cache-Control": "private, max-age=60, s-maxage=60",
2325
"Vary": [
2426
"Accept, Authorization, Cookie, X-GitHub-OTP",
2527
"Accept-Encoding"
2628
],
27-
"ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"",
28-
"Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT",
29+
"ETag": "W/\"858224998ac7d1fd6dcd43f73d375297\"",
30+
"Last-Modified": "Thu, 06 Feb 2020 18:33:43 GMT",
2931
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
3032
"X-Accepted-OAuth-Scopes": "repo",
3133
"X-GitHub-Media-Type": "unknown, github.v3",
@@ -37,13 +39,12 @@
3739
"X-XSS-Protection": "1; mode=block",
3840
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3941
"Content-Security-Policy": "default-src 'none'",
40-
"X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC"
42+
"X-GitHub-Request-Id": "CC37:2605:3FADC:4EA8C:5E3C5C02"
4143
}
4244
},
43-
"uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
45+
"uuid": "574da117-6845-46d8-b2c1-4415546ca670",
4446
"persistent": true,
45-
"scenarioName": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests",
46-
"requiredScenarioState": "Started",
47-
"newScenarioState": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests-2",
48-
"insertionIndex": 2
47+
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1",
48+
"requiredScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1-2",
49+
"insertionIndex": 3
4950
}

src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/2-r_h_t_fail.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
}
1212
},
1313
"response": {
14-
"status": 403,
14+
"status": 429,
1515
"body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}",
1616
"headers": {
1717
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
1818
"Content-Type": "application/json; charset=utf-8",
1919
"Server": "GitHub.com",
20-
"Status": "403 Forbidden",
21-
"gh-limited-by": "search-elapsed-time-shared-grouped",
22-
"X-RateLimit-Limit": "5000",
23-
"X-RateLimit-Remaining": "4000",
24-
"X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}",
20+
"Status": "429 Too Many Requests",
21+
"Retry-After": "{{now offset='8 seconds' timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
2522
"Cache-Control": "private, max-age=60, s-maxage=60",
2623
"Vary": [
2724
"Accept, Authorization, Cookie, X-GitHub-OTP",
@@ -45,8 +42,8 @@
4542
},
4643
"uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
4744
"persistent": true,
48-
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After",
45+
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2",
4946
"requiredScenarioState": "Started",
50-
"newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After-2",
47+
"newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2-2",
5148
"insertionIndex": 2
5249
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
2+
"id": "574da117-6845-46d8-b2c1-4415546ca670",
33
"name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After",
44
"request": {
55
"url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After",
@@ -11,21 +11,23 @@
1111
}
1212
},
1313
"response": {
14-
"status": 429,
15-
"body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}",
14+
"status": 200,
15+
"bodyFileName": "3-r_h_t_fail.json",
1616
"headers": {
1717
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
1818
"Content-Type": "application/json; charset=utf-8",
1919
"Server": "GitHub.com",
20-
"Status": "429 Too Many Requests",
21-
"Retry-After": "Mon, 21 Oct 2115 07:28:00 GMT",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4922",
23+
"X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}",
2224
"Cache-Control": "private, max-age=60, s-maxage=60",
2325
"Vary": [
2426
"Accept, Authorization, Cookie, X-GitHub-OTP",
2527
"Accept-Encoding"
2628
],
27-
"ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"",
28-
"Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT",
29+
"ETag": "W/\"858224998ac7d1fd6dcd43f73d375297\"",
30+
"Last-Modified": "Thu, 06 Feb 2020 18:33:43 GMT",
2931
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
3032
"X-Accepted-OAuth-Scopes": "repo",
3133
"X-GitHub-Media-Type": "unknown, github.v3",
@@ -37,13 +39,12 @@
3739
"X-XSS-Protection": "1; mode=block",
3840
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3941
"Content-Security-Policy": "default-src 'none'",
40-
"X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC"
42+
"X-GitHub-Request-Id": "CC37:2605:3FADC:4EA8C:5E3C5C02"
4143
}
4244
},
43-
"uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
45+
"uuid": "574da117-6845-46d8-b2c1-4415546ca670",
4446
"persistent": true,
45-
"scenarioName": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After",
46-
"requiredScenarioState": "Started",
47-
"newScenarioState": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After-2",
48-
"insertionIndex": 2
47+
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2",
48+
"requiredScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2-2",
49+
"insertionIndex": 3
4950
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
3+
"name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 429,
15+
"body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}",
16+
"headers": {
17+
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "429 Too Many Requests",
21+
"gh-limited-by": "search-elapsed-time-shared-grouped",
22+
"Cache-Control": "private, max-age=60, s-maxage=60",
23+
"Vary": [
24+
"Accept, Authorization, Cookie, X-GitHub-OTP",
25+
"Accept-Encoding"
26+
],
27+
"ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"",
28+
"Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT",
29+
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
30+
"X-Accepted-OAuth-Scopes": "repo",
31+
"X-GitHub-Media-Type": "unknown, github.v3",
32+
"Access-Control-Expose-Headers": "ETag, Link, Location, gh-limited-by, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
33+
"Access-Control-Allow-Origin": "*",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "1; mode=block",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC"
41+
}
42+
},
43+
"uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
44+
"persistent": true,
45+
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3",
46+
"requiredScenarioState": "Started",
47+
"newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3-2",
48+
"insertionIndex": 2
49+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
2+
"id": "574da117-6845-46d8-b2c1-4415546ca670",
33
"name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After",
44
"request": {
55
"url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After",
@@ -11,21 +11,23 @@
1111
}
1212
},
1313
"response": {
14-
"status": 429,
15-
"body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}",
14+
"status": 200,
15+
"bodyFileName": "3-r_h_t_fail.json",
1616
"headers": {
1717
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
1818
"Content-Type": "application/json; charset=utf-8",
1919
"Server": "GitHub.com",
20-
"Status": "429 Too Many Requests",
21-
"gh-limited-by": "search-elapsed-time-shared-grouped",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4922",
23+
"X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}",
2224
"Cache-Control": "private, max-age=60, s-maxage=60",
2325
"Vary": [
2426
"Accept, Authorization, Cookie, X-GitHub-OTP",
2527
"Accept-Encoding"
2628
],
27-
"ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"",
28-
"Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT",
29+
"ETag": "W/\"858224998ac7d1fd6dcd43f73d375297\"",
30+
"Last-Modified": "Thu, 06 Feb 2020 18:33:43 GMT",
2931
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
3032
"X-Accepted-OAuth-Scopes": "repo",
3133
"X-GitHub-Media-Type": "unknown, github.v3",
@@ -37,13 +39,12 @@
3739
"X-XSS-Protection": "1; mode=block",
3840
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3941
"Content-Security-Policy": "default-src 'none'",
40-
"X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC"
42+
"X-GitHub-Request-Id": "CC37:2605:3FADC:4EA8C:5E3C5C02"
4143
}
4244
},
43-
"uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261",
45+
"uuid": "574da117-6845-46d8-b2c1-4415546ca670",
4446
"persistent": true,
45-
"scenarioName": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After",
46-
"requiredScenarioState": "Started",
47-
"newScenarioState": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After-2",
48-
"insertionIndex": 2
47+
"scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3",
48+
"requiredScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3-2",
49+
"insertionIndex": 3
4950
}

0 commit comments

Comments
 (0)
0