-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: process_max_fds is process limit, not OS (#314)
* fix: missing test for process_max_fds * fix: process_max_fds is process limit, not OS Fix: #311 * fixup! fix: process_max_fds is process limit, not OS
- Loading branch information
1 parent
f71eb75
commit 9b204e4
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const exec = require('child_process').execSync; | ||
|
||
describe('processMaxFileDescriptors', () => { | ||
const register = require('../../index').register; | ||
const processMaxFileDescriptors = require('../../lib/metrics/processMaxFileDescriptors'); | ||
|
||
beforeAll(() => { | ||
register.clear(); | ||
}); | ||
|
||
afterEach(() => { | ||
register.clear(); | ||
}); | ||
|
||
if (process.platform !== 'linux') { | ||
it('should not add metric to the registry', () => { | ||
expect(register.getMetricsAsJSON()).toHaveLength(0); | ||
|
||
processMaxFileDescriptors()(); | ||
|
||
expect(register.getMetricsAsJSON()).toHaveLength(0); | ||
}); | ||
} else { | ||
it('should add metric to the registry', () => { | ||
expect(register.getMetricsAsJSON()).toHaveLength(0); | ||
|
||
processMaxFileDescriptors()(); | ||
|
||
const metrics = register.getMetricsAsJSON(); | ||
|
||
expect(metrics).toHaveLength(1); | ||
expect(metrics[0].help).toEqual( | ||
'Maximum number of open file descriptors.' | ||
); | ||
expect(metrics[0].type).toEqual('gauge'); | ||
expect(metrics[0].name).toEqual('process_max_fds'); | ||
expect(metrics[0].values).toHaveLength(1); | ||
}); | ||
|
||
it('should have a reasonable metric value', done => { | ||
const maxFiles = Number(exec('ulimit -Hn', { encoding: 'utf8' })); | ||
|
||
expect(register.getMetricsAsJSON()).toHaveLength(0); | ||
processMaxFileDescriptors(register, { ready })(); | ||
|
||
function ready() { | ||
const metrics = register.getMetricsAsJSON(); | ||
|
||
expect(metrics).toHaveLength(1); | ||
expect(metrics[0].values).toHaveLength(1); | ||
|
||
expect(metrics[0].values[0].value).toBeLessThanOrEqual(maxFiles); | ||
expect(metrics[0].values[0].value).toBeGreaterThan(0); | ||
|
||
return done(); | ||
} | ||
}); | ||
} | ||
}); |