2021-02-05 18:59:00 -08:00
|
|
|
import {expect} from 'chai';
|
2021-02-07 08:57:12 -08:00
|
|
|
|
|
|
|
import {AgentManager, DESTROY_TIMEOUT_MS} from '../src/agent-manager';
|
2020-09-25 08:52:01 -07:00
|
|
|
import {sleep} from '../src/util/sleep';
|
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
describe('AgentManager', () => {
|
|
|
|
it('works', async () => {
|
|
|
|
const manager = new AgentManager();
|
|
|
|
const agent = manager._agent;
|
|
|
|
expect(manager._activeRequests).to.eq(0);
|
|
|
|
expect(manager._destroyTimeout).to.be.null;
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
manager.requestStart();
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
expect(manager._activeRequests).to.eq(1);
|
|
|
|
expect(manager._destroyTimeout).to.be.null;
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
manager.requestEnd();
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
expect(manager._activeRequests).to.eq(0);
|
|
|
|
expect(manager._destroyTimeout).not.to.be.null;
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
manager.requestStart();
|
|
|
|
manager.requestStart();
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
expect(manager._activeRequests).to.eq(2);
|
|
|
|
expect(manager._destroyTimeout).to.be.null;
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
manager.requestEnd();
|
|
|
|
manager.requestEnd();
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
expect(manager._activeRequests).to.eq(0);
|
|
|
|
expect(manager._destroyTimeout).not.to.be.null;
|
|
|
|
expect(manager._agent).to.eq(agent);
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
await sleep(DESTROY_TIMEOUT_MS);
|
2020-09-25 08:52:01 -07:00
|
|
|
|
2021-02-05 18:59:00 -08:00
|
|
|
expect(manager._agent).not.to.eq(agent);
|
|
|
|
}).timeout(2 * DESTROY_TIMEOUT_MS);
|
2020-09-25 08:52:01 -07:00
|
|
|
});
|