@@ -6,11 +6,17 @@ import { throttling } from "../src/index.ts";
6
6
import type { AddressInfo } from "node:net" ;
7
7
import { createServer } from "node:http" ;
8
8
9
+ /**
10
+ * According to https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28
11
+ * both 403 and 429 status codes can be returned when hitting a rate limit.
12
+ */
13
+ const restStatusCodes = [ 403 , 429 ] ;
14
+
9
15
describe (
10
16
"Retry" ,
11
17
function ( ) {
12
- describe ( "REST" , function ( ) {
13
- it ( " Should retry 'secondary-limit' and succeed" , async function ( ) {
18
+ describe . each ( restStatusCodes ) ( "REST" , function ( statusCode ) {
19
+ it ( ` Should retry 'secondary-limit' and succeed when status ${ statusCode } ` , async function ( ) {
14
20
let eventCount = 0 ;
15
21
const octokit = new TestOctokit ( {
16
22
throttle : {
@@ -34,7 +40,7 @@ describe(
34
40
request : {
35
41
responses : [
36
42
{
37
- status : 403 ,
43
+ status : statusCode ,
38
44
headers : { "retry-after" : "1" } ,
39
45
data : { message : "You have exceeded a secondary rate limit" } ,
40
46
} ,
@@ -82,12 +88,12 @@ describe(
82
88
request : {
83
89
responses : [
84
90
{
85
- status : 403 ,
91
+ status : statusCode ,
86
92
headers : { "retry-after" : "1" } ,
87
93
data : { message } ,
88
94
} ,
89
95
{
90
- status : 403 ,
96
+ status : statusCode ,
91
97
headers : { "retry-after" : "2" } ,
92
98
data : { message } ,
93
99
} ,
@@ -131,7 +137,7 @@ describe(
131
137
. end ( JSON . stringify ( { message : "Success!" } ) ) ;
132
138
} else {
133
139
res
134
- . writeHead ( 403 , {
140
+ . writeHead ( statusCode , {
135
141
"Content-Type" : "application/json" ,
136
142
"retry-after" : "1" ,
137
143
} )
@@ -177,7 +183,7 @@ describe(
177
183
}
178
184
} ) ;
179
185
180
- it ( " Should retry 'rate-limit' and succeed" , async function ( ) {
186
+ it ( ` Should retry 'rate-limit' with status code ${ statusCode } and succeed` , async function ( ) {
181
187
let eventCount = 0 ;
182
188
const octokit = new TestOctokit ( {
183
189
throttle : {
@@ -199,7 +205,7 @@ describe(
199
205
request : {
200
206
responses : [
201
207
{
202
- status : 403 ,
208
+ status : statusCode ,
203
209
headers : {
204
210
"x-ratelimit-remaining" : "0" ,
205
211
"x-ratelimit-reset" : "123" ,
0 commit comments