mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-27 02:27:53 +01:00
Dispose disposables in tests
This commit is contained in:
@@ -11,19 +11,22 @@ import { createRandomIPCHandle, createStaticIPCHandle, NodeSocket } from 'vs/bas
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { tmpdir } from 'os';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
class MessageStream {
|
||||
class MessageStream extends Disposable {
|
||||
|
||||
private _currentComplete: ((data: VSBuffer) => void) | null;
|
||||
private _messages: VSBuffer[];
|
||||
|
||||
constructor(x: Protocol | PersistentProtocol) {
|
||||
super();
|
||||
this._currentComplete = null;
|
||||
this._messages = [];
|
||||
x.onMessage(data => {
|
||||
this._register(x.onMessage(data => {
|
||||
this._messages.push(data);
|
||||
this._trigger();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private _trigger(): void {
|
||||
@@ -121,6 +124,8 @@ class Ether {
|
||||
|
||||
suite('IPC, Socket Protocol', () => {
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
let ether: Ether;
|
||||
|
||||
setup(() => {
|
||||
@@ -142,6 +147,10 @@ suite('IPC, Socket Protocol', () => {
|
||||
a.send(buffer);
|
||||
const msg2 = await bMessages.waitForOne();
|
||||
assert.strictEqual(msg2.readUInt8(0), 123);
|
||||
|
||||
bMessages.dispose();
|
||||
a.dispose();
|
||||
b.dispose();
|
||||
});
|
||||
|
||||
|
||||
@@ -161,11 +170,18 @@ suite('IPC, Socket Protocol', () => {
|
||||
a.send(VSBuffer.fromString(JSON.stringify(data)));
|
||||
const msg = await bMessages.waitForOne();
|
||||
assert.deepStrictEqual(JSON.parse(msg.toString()), data);
|
||||
|
||||
bMessages.dispose();
|
||||
a.dispose();
|
||||
b.dispose();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('PersistentProtocol reconnection', () => {
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
let ether: Ether;
|
||||
|
||||
setup(() => {
|
||||
@@ -222,6 +238,11 @@ suite('PersistentProtocol reconnection', () => {
|
||||
assert.strictEqual(b2.toString(), 'a4');
|
||||
assert.strictEqual(a.unacknowledgedCount, 1);
|
||||
assert.strictEqual(b.unacknowledgedCount, 0);
|
||||
|
||||
aMessages.dispose();
|
||||
bMessages.dispose();
|
||||
a.dispose();
|
||||
b.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user