@@ -57,130 +57,66 @@ var agent = request.agent(app);
57
57
describe ( 'Test rate limiting' , function ( ) {
58
58
59
59
it ( 'should reach request rate limit' , function ( done ) {
60
- setTimeout ( function ( ) { /* jslint ignore:line */
61
- agent
60
+ agent
61
+ . get ( '/initialize' )
62
+ . then ( function ( res ) {
63
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
64
+ return agent
65
+ . get ( '/initialize' ) ;
66
+ } )
67
+ . then ( function ( res ) {
68
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
69
+ return agent
70
+ . get ( '/initialize' ) ;
71
+ } )
72
+ . then ( function ( res ) {
73
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
74
+ return agent
75
+ . get ( '/initialize' ) ;
76
+ } )
77
+ . then ( function ( res ) {
78
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
79
+ return agent
80
+ . get ( '/initialize' ) ;
81
+ } )
82
+ . then ( function ( res ) {
83
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
84
+ return agent
85
+ . get ( '/initialize' ) ;
86
+ } )
87
+ . then ( function ( res ) {
88
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
89
+ return agent
90
+ . get ( '/initialize' ) ;
91
+ } )
92
+ . then ( function ( res ) {
93
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
94
+ return agent
95
+ . get ( '/initialize' ) ;
96
+ } )
97
+ . then ( function ( res ) {
98
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
99
+ return agent
100
+ . get ( '/initialize' ) ;
101
+ } )
102
+ . then ( function ( res ) {
103
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
104
+ return agent
105
+ . get ( '/initialize' ) ;
106
+ } )
107
+ . then ( function ( res ) {
108
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
109
+ return agent
62
110
. get ( '/initialize' )
63
- . end ( function ( err , res ) {
64
- if ( err ) {
65
- return console . error ( err ) ;
66
- }
67
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
68
- } ) ;
69
- } , 1000 * 1 ) ;
70
-
71
- setTimeout ( function ( ) { /* jslint ignore:line */
72
- agent
73
- . get ( '/initialize' )
74
- . end ( function ( err , res ) {
75
- if ( err ) {
76
- return console . error ( err ) ;
77
- }
78
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
79
- } ) ;
80
- } , 1000 * 2 ) ;
81
-
82
- setTimeout ( function ( ) { /* jslint ignore:line */
83
- agent
84
- . get ( '/initialize' )
85
- . end ( function ( err , res ) {
86
- if ( err ) {
87
- return console . error ( err ) ;
88
- }
89
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
90
- } ) ;
91
- } , 1000 * 3 ) ;
92
-
93
- setTimeout ( function ( ) { /* jslint ignore:line */
94
- agent
95
- . get ( '/initialize' )
96
- . end ( function ( err , res ) {
97
- if ( err ) {
98
- return console . error ( err ) ;
99
- }
100
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
101
- } ) ;
102
- } , 1000 * 4 ) ;
103
-
104
- setTimeout ( function ( ) { /* jslint ignore:line */
105
- agent
106
- . get ( '/initialize' )
107
- . end ( function ( err , res ) {
108
- if ( err ) {
109
- return console . error ( err ) ;
110
- }
111
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
112
- } ) ;
113
- } , 1000 * 5 ) ;
114
-
115
- setTimeout ( function ( ) { /* jslint ignore:line */
116
- agent
117
- . get ( '/initialize' )
118
- . end ( function ( err , res ) {
119
- if ( err ) {
120
- return console . error ( err ) ;
121
- }
122
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
123
- } ) ;
124
- } , 1000 * 6 ) ;
125
-
126
- setTimeout ( function ( ) { /* jslint ignore:line */
127
- agent
128
- . get ( '/initialize' )
129
- . end ( function ( err , res ) {
130
- if ( err ) {
131
- return console . error ( err ) ;
132
- }
133
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
134
- } ) ;
135
- } , 1000 * 7 ) ;
136
-
137
- setTimeout ( function ( ) { /* jslint ignore:line */
138
- agent
139
- . get ( '/initialize' )
140
- . end ( function ( err , res ) {
141
- if ( err ) {
142
- return console . error ( err ) ;
143
- }
144
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
145
- } ) ;
146
- } , 1000 * 8 ) ;
147
-
148
- setTimeout ( function ( ) { /* jslint ignore:line */
149
- agent
150
- . get ( '/initialize' )
151
- . end ( function ( err , res ) {
152
- if ( err ) {
153
- return console . error ( err ) ;
154
- }
155
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
156
- } ) ;
157
- } , 1000 * 9 ) ;
158
-
159
- setTimeout ( function ( ) { /* jslint ignore:line */
160
- agent
161
- . get ( '/initialize' )
162
- . end ( function ( err , res ) {
163
- if ( err ) {
164
- return console . error ( err ) ;
165
- }
166
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
167
- } ) ;
168
- } , 1000 * 10 ) ;
169
-
170
- setTimeout ( function ( ) {
171
- agent
172
- . get ( '/initialize' )
173
- . expect ( 429 )
174
- . end ( function ( err , res ) {
175
- if ( err ) {
176
- done ( err ) ;
177
- } else {
178
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
179
- done ( ) ;
180
- }
181
- } ) ;
182
- } , 1000 * 11 ) ;
183
-
111
+ . expect ( 429 ) ;
112
+ } )
113
+ . then ( function ( res ) {
114
+ console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] , ' | Body: ' , res . body ) ;
115
+ done ( ) ;
116
+ } )
117
+ . catch ( function ( err ) {
118
+ done ( err ) ;
119
+ } ) ;
184
120
} ) ;
185
121
} ) ;
186
122
0 commit comments