This commit is contained in:
Connor Peet 2020-06-20 19:48:39 -07:00
Родитель 204eb2da17
Коммит 9dce5500cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CF8FD2EA0DBC61BD
2 изменённых файлов: 17 добавлений и 11 удалений

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

@ -154,16 +154,22 @@ export class Lease extends EventEmitter {
* Revoke frees the lease from etcd. Keys that the lease owns will be
* evicted.
*/
public revoke(options: grpc.CallOptions | undefined = this.options): Promise<void> {
public async revoke(options: grpc.CallOptions | undefined = this.options): Promise<void> {
this.close();
return this.leaseID.then(id => {
if (!(id instanceof Error)) {
// if an error, we didn't grant in the first place
return this.client.leaseRevoke({ ID: id }, options).then(() => undefined);
}
return undefined;
});
const id = await this.leaseID;
if (id instanceof Error) {
// if an error, we didn't grant in the first place
return;
}
try {
await this.client.leaseRevoke({ ID: id }, options);
} catch (e) {
if (!(e instanceof EtcdLeaseInvalidError)) {
throw e;
}
}
}
/**

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

@ -149,7 +149,7 @@ describe('lease()', () => {
});
it('emits a loss if the touched key is lost', async () => {
lease = client.lease(10);
lease = client.lease(100, { autoKeepAlive: false });
(lease as any).leaseID = Promise.resolve('123456789');
const lost = onceEvent(lease, 'lost');
@ -217,12 +217,12 @@ describe('lease()', () => {
expect(failedEvent.fired).to.be.false;
clock.tick(10000);
await unmockedDelay(2); // drain task queues
expect(failedEvent.fired).to.be.true;
proxy.resume(TrafficDirection.FromEtcd);
await lease.revoke();
proxiedClient.close();
await proxy.deactivate();
proxy.deactivate();
});
it('tears down if the lease gets revoked', async () => {