Skip to content

Commit 1edcf05

Browse files
authored
Merge pull request #21 from asambstack/ACE_3374_playwright_terminal_errors
Ace 3374 playwright terminal errors
2 parents 25d66d7 + ff95edf commit 1edcf05

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/core/Context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Context extends EventEmitter {
207207
});
208208

209209
this.outgoingSocket.on(kUpstreamClosed, (code, msg) => {
210-
this.incomingSocket.close();
210+
this.incomingSocket.close(code, msg);
211211
this.emit(kCleanup, this.connectionId);
212212
logger.info(
213213
`${OUTGOING} [${this.connectionId}] [CLOSE] - Socket closed with ${code} and ${msg}`

lib/core/IncomingWebSocket.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ class IncomingWebSocket extends EventEmitter {
115115
/**
116116
* Closes the socket connection.
117117
*/
118-
close() {
118+
close(code, msg) {
119119
this.teardown = true;
120+
if(code >= 1000 && code < 1004)
121+
this.socket.close(code, msg);
120122
this.socket.terminate();
121123
}
122124

test/core/incomingWebSocket.test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,39 @@ describe('IncomingWebSocket', () => {
137137

138138
describe('#close', () => {
139139
let terminateSpy;
140-
before(() => {
140+
let closeSpy;
141+
beforeEach(() => {
141142
terminateSpy = spy();
143+
closeSpy = spy();
142144
incomingWs.socket.terminate = terminateSpy;
143-
incomingWs.close();
145+
incomingWs.socket.close = closeSpy;
146+
});
147+
148+
it('should close and terminate the websocket when code is >= 1000 and < 1004', () => {
149+
incomingWs.close(1001, 'msg');
150+
assert(closeSpy.calledWith(1001, 'msg'));
151+
assert(terminateSpy.calledOnce);
152+
});
153+
154+
it('should not call close, only terminate the websocket when code is 1005', () => {
155+
incomingWs.close(1005, 'msg');
156+
assert.isFalse(closeSpy.called);
157+
assert(terminateSpy.calledOnce);
158+
});
159+
160+
it('should not call close, only terminate the websocket when code is 1006', () => {
161+
incomingWs.close(1006, 'msg');
162+
assert.isFalse(closeSpy.called);
163+
assert(terminateSpy.calledOnce);
144164
});
145165

146166
it('should terminate the websocket', () => {
167+
incomingWs.close(1001, 'msg');
147168
assert(terminateSpy.calledOnce);
148169
});
149170

150171
it('should set teardown to true', () => {
172+
incomingWs.close(1001, 'msg');
151173
expect(incomingWs.teardown).to.equal(true);
152174
});
153175
});

0 commit comments

Comments
 (0)