@@ -79,6 +79,23 @@ describe.each([
79
79
} ) ,
80
80
) . rejects . toThrow ( 'push failed with status 400' ) ;
81
81
} ) ;
82
+
83
+ it ( 'should timeout when taking too long' , ( ) => {
84
+ const mockHttp = nock ( 'http://192.168.99.100:9091' )
85
+ . post ( '/metrics/job/testJob/key/va%26lue' , body )
86
+ . delay ( 100 )
87
+ . reply ( 200 ) ;
88
+
89
+ expect . assertions ( 1 ) ;
90
+ return instance
91
+ . pushAdd ( {
92
+ jobName : 'testJob' ,
93
+ groupings : { key : 'va&lue' } ,
94
+ } )
95
+ . catch ( err => {
96
+ expect ( err . message ) . toStrictEqual ( 'Pushgateway request timed out' ) ;
97
+ } ) ;
98
+ } ) ;
82
99
} ) ;
83
100
84
101
describe ( 'push' , ( ) => {
@@ -114,6 +131,18 @@ describe.each([
114
131
} ) ,
115
132
) . rejects . toThrow ( 'push failed with status 400' ) ;
116
133
} ) ;
134
+
135
+ it ( 'should timeout when taking too long' , ( ) => {
136
+ const mockHttp = nock ( 'http://192.168.99.100:9091' )
137
+ . put ( '/metrics/job/test%26Job' , body )
138
+ . delay ( 100 )
139
+ . reply ( 200 ) ;
140
+
141
+ expect . assertions ( 1 ) ;
142
+ return instance . push ( { jobName : 'test&Job' } ) . catch ( err => {
143
+ expect ( err . message ) . toStrictEqual ( 'Pushgateway request timed out' ) ;
144
+ } ) ;
145
+ } ) ;
117
146
} ) ;
118
147
119
148
describe ( 'delete' , ( ) => {
@@ -136,6 +165,18 @@ describe.each([
136
165
'push failed with status 400' ,
137
166
) ;
138
167
} ) ;
168
+
169
+ it ( 'should timeout when taking too long' , ( ) => {
170
+ const mockHttp = nock ( 'http://192.168.99.100:9091' )
171
+ . delete ( '/metrics/job/testJob' )
172
+ . delay ( 100 )
173
+ . reply ( 200 ) ;
174
+
175
+ expect . assertions ( 1 ) ;
176
+ return instance . delete ( { jobName : 'testJob' } ) . catch ( err => {
177
+ expect ( err . message ) . toStrictEqual ( 'Pushgateway request timed out' ) ;
178
+ } ) ;
179
+ } ) ;
139
180
} ) ;
140
181
141
182
describe ( 'when using basic authentication' , ( ) => {
@@ -238,7 +279,7 @@ describe.each([
238
279
239
280
beforeEach ( ( ) => {
240
281
registry = undefined ;
241
- instance = new Pushgateway ( 'http://192.168.99.100:9091' ) ;
282
+ instance = new Pushgateway ( 'http://192.168.99.100:9091' , { timeout : 10 } ) ;
242
283
const promClient = require ( '../index' ) ;
243
284
const cnt = new promClient . Counter ( { name : 'test' , help : 'test' } ) ;
244
285
cnt . inc ( 100 ) ;
@@ -254,7 +295,11 @@ describe.each([
254
295
255
296
beforeEach ( ( ) => {
256
297
registry = new Registry ( regType ) ;
257
- instance = new Pushgateway ( 'http://192.168.99.100:9091' , null , registry ) ;
298
+ instance = new Pushgateway (
299
+ 'http://192.168.99.100:9091' ,
300
+ { timeout : 10 } ,
301
+ registry ,
302
+ ) ;
258
303
const promeClient = require ( '../index' ) ;
259
304
const cnt = new promeClient . Counter ( {
260
305
name : 'test' ,
0 commit comments