mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-22 22:09:33 +01:00
fix(host-sensors): never wait on a cold sampler, back off failing readers, one stats request at a time
This commit is contained in:
1 parent
f15afe1de3
commit
23a9d78cdd
7 files changed
+270
-28
No files matched your search
@@ -171,6 +171,26 @@ describe('createCounterStream', () => {
|
||||
expect(children).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('does not wait at all by default: a cold sampler answers nothing and the next read has the sample', async () => {
|
||||
const children: PassThrough[] = [];
|
||||
const stream = createCounterStream({
|
||||
start: () => {
|
||||
const stdout = new PassThrough();
|
||||
children.push(stdout);
|
||||
return { stdout, kill: () => true, once: () => undefined } as never;
|
||||
},
|
||||
});
|
||||
const counters = ['\\Processor Information(_Total)\\Processor Frequency'];
|
||||
const header = '"(PDH-CSV 4.0)","\\\\H\\Processor Information(_Total)\\Processor Frequency"\r\n';
|
||||
const started = Date.now();
|
||||
expect(await stream.read(counters)).toBeUndefined();
|
||||
expect(Date.now() - started).toBeLessThan(500);
|
||||
children[0].write(header + '"t","1700"\r\n');
|
||||
await new Promise((r) => setImmediate(r));
|
||||
expect(await stream.read(counters)).toEqual({ cpuMhz: 1700 });
|
||||
expect(children).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('answers nothing, within the wait, when no sample ever arrives', async () => {
|
||||
const { stream } = fake();
|
||||
expect(await stream.read(counters)).toBeUndefined();
|
||||
|
||||
Reference in new issue
Block a user