feat(lease): allow leases to be passively released (fixes #69)

This commit is contained in:
Connor Peet 2018-05-05 18:59:57 -07:00
Родитель 1e9f8113a2
Коммит 65394ba8bb
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -151,6 +151,15 @@ export class Lease extends EventEmitter {
});
}
/**
* releasePassively stops making heartbeats for the lease, and allows it
* to expire automatically when its TTL rolls around. Use `revoke()` to
* actively tell etcd to terminate the lease.
*/
public release() {
this.close();
}
/**
* Put returns a put builder that operates within the current lease.
*/

Просмотреть файл

@ -30,7 +30,7 @@ describe('lease()', () => {
it('throws if trying to use too short of a ttl, or an undefined ttl', () => {
expect(() => client.lease(0)).to.throw(/must be at least 1 second/);
expect(() => (<any> client.lease)()).to.throw(/must be at least 1 second/);
expect(() => (<any>client.lease)()).to.throw(/must be at least 1 second/);
});
it('reports a loss and errors if the client is invalid', async () => {
@ -152,6 +152,13 @@ describe('lease()', () => {
expect(res.TTL).to.equal('60');
});
it('stops touching the lease if released passively', async () => {
const kaFired = watchEmission('keepaliveFired');
lease.release();
clock.tick(20000);
expect(kaFired.fired).to.be.false;
});
it('tears down if the lease gets revoked', async () => {
await client.leaseClient.leaseRevoke({ ID: await lease.grant() });
clock.tick(20000);