зеркало из https://github.com/microsoft/etcd3.git
fix: various test flakes
This commit is contained in:
Родитель
204eb2da17
Коммит
9dce5500cc
22
src/lease.ts
22
src/lease.ts
|
@ -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 () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче