chore: try to fix flaking lease test

This commit is contained in:
Connor Peet 2020-06-15 23:00:49 -07:00
Родитель 3fafea2e23
Коммит dacc0805c7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CF8FD2EA0DBC61BD
3 изменённых файлов: 12 добавлений и 12 удалений

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

@ -94,7 +94,7 @@ describe('lease()', () => {
await lease.revoke();
proxiedClient.close();
proxy.deactivate();
await proxy.deactivate();
});
it('marks leases as failed if the server is not contacted for a while', async () => {
@ -108,7 +108,7 @@ describe('lease()', () => {
const err = await onceEvent(lease, 'lost');
expect(err.message).to.match(/our lease has expired/);
proxiedClient.close();
proxy.deactivate();
await proxy.deactivate();
});
it('emits a lost event if the lease is invalidated', async () => {

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

@ -72,9 +72,9 @@ export class Proxy {
/**
* Destroys a previously-active proxy server.
*/
public deactivate() {
this.server.close();
public async deactivate() {
this.isActive = false;
await new Promise(r => this.server.close(r));
}
/**
@ -95,7 +95,7 @@ export class Proxy {
ALPNProtocols: ['h2'],
},
() => {
if (serverBuffer.length > 0) {
if (serverBuffer.length > 0 && !ended) {
serverCnx.write(Buffer.concat(serverBuffer));
}
@ -105,11 +105,11 @@ export class Proxy {
let ended = false;
const end = (err?: Error) => {
ended = true;
if (err instanceof Error) {
throw err;
}
ended = true;
clientCnx.end();
serverCnx.end();
this.connections = this.connections.filter(c => c.end !== end);
@ -120,17 +120,17 @@ export class Proxy {
clientCnx.write(data);
}
});
serverCnx.on('close', end);
serverCnx.on('end', end);
serverCnx.on('error', end);
clientCnx.on('data', (data: Buffer) => {
if (serverConnected && !ended) {
serverCnx.write(data);
} else {
} else if (!ended) {
serverBuffer.push(data);
}
});
clientCnx.on('close', end);
clientCnx.on('end', end);
clientCnx.on('error', end);
this.connections.push({ end });

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

@ -69,7 +69,7 @@ describe('watch()', () => {
await expectWatching(watcher, 'foo1');
proxiedClient.close();
proxy.deactivate();
await proxy.deactivate();
});
// todo(connor4312): this is disabled pending resolution on:
@ -98,7 +98,7 @@ describe('watch()', () => {
});
proxiedClient.close();
proxy.deactivate();
await proxy.deactivate();
});
it('caps watchers revisions', async () => {
@ -189,7 +189,7 @@ describe('watch()', () => {
expect(getWatchers()).to.deep.equal([]);
proxiedClient.close();
proxy.deactivate();
await proxy.deactivate();
});
});
});