Skip to content

Commit 17322c2

Browse files
committed
inject resetAndDestroy into socket in test for older versions of node
1 parent d077116 commit 17322c2

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

test/MockFtpServer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ module.exports = class MockFtpServer {
3939
})
4040
this.dataConn = undefined
4141
this.dataServer = net.createServer(conn => {
42+
if(!conn.resetAndDestroy) {
43+
conn.resetAndDestroy = () => {
44+
conn._handle.reset(() => {
45+
this.conn.emit("close")
46+
})
47+
conn._handle.onread = () =>{};
48+
conn._handle = null;
49+
}
50+
}
4251
this.dataConn = conn
4352
this.connections.push(conn)
4453
this.didOpenDataConn()

test/downloadSpec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,17 @@ describe("Download to stream", function() {
148148
dataSocket.destroy(new Error("Error that should be ignored because task has completed successfully"))
149149
})
150150
it("handles early data socket closure", async () => {
151+
/**
152+
* type of this.client
153+
* @type {Client}
154+
*/
155+
this.client;
156+
151157
this.server.addHandlers({
152158
"pasv": () => `227 Entering Passive Mode (${this.server.dataAddressForPasvResponse})`,
153159
"retr": ({arg}) => {
154160
//close data connection such that client receives ECONNRESET
155-
this.server.dataConn.resetAndDestroy?.()
161+
this.server.dataConn.resetAndDestroy()
156162

157163
return `550 ${arg}: No such file or directory.`
158164
}

0 commit comments

Comments
 (0)