@@ -57,18 +57,116 @@ 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
- var n = config . rateLimit * 1 ;
61
- var x = 0 ;
62
- while ( n > 0 ) {
63
- n = n - 1 ;
64
- setTimeout ( function ( ) { /* jslint ignore:line */
65
- agent
66
- . get ( '/initialize' )
67
- . end ( function ( err , res ) {
68
- console . log ( 'Limit: ' , res . headers [ 'x-ratelimit-limit' ] , '| Remaining: ' , res . headers [ 'x-ratelimit-remaining' ] ) ;
69
- } ) ;
70
- } , 1000 * n ) ;
71
- }
60
+ setTimeout ( function ( ) { /* jslint ignore:line */
61
+ agent
62
+ . 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
+
72
170
setTimeout ( function ( ) {
73
171
agent
74
172
. get ( '/initialize' )
@@ -81,7 +179,7 @@ describe('Test rate limiting', function(){
81
179
done ( ) ;
82
180
}
83
181
} ) ;
84
- } , 10000 ) ;
182
+ } , 1000 * 11 ) ;
85
183
86
184
} ) ;
87
185
} ) ;
0 commit comments