-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add failing test for WebsocketClientTransport
Signed-off-by: Kevin Viglucci <kviglucci@gmail.com>
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const path = require("path"); | ||
const karma = require("karma"); | ||
const { RSocketServer } = require("@rsocket/core"); | ||
const { | ||
WebsocketServerTransport, | ||
} = require("@rsocket/transport-websocket-server"); | ||
const WebSocket = require("ws"); | ||
const parseConfig = karma.config.parseConfig; | ||
const Server = karma.Server; | ||
|
||
const rsocketServerPort = 9091; | ||
const rSocketServer = new RSocketServer({ | ||
transport: new WebsocketServerTransport({ | ||
wsCreator: (options) => { | ||
return new WebSocket.Server({ | ||
port: rsocketServerPort, | ||
}); | ||
}, | ||
}), | ||
acceptor: { | ||
accept: async () => ({ | ||
requestResponse: (payload, responderStream) => { | ||
const timeout = setTimeout( | ||
() => | ||
responderStream.onNext( | ||
{ | ||
data: Buffer.concat([Buffer.from("Echo: "), payload.data]), | ||
}, | ||
true | ||
), | ||
80 | ||
); | ||
return { | ||
cancel: () => { | ||
clearTimeout(timeout); | ||
console.log("cancelled"); | ||
}, | ||
onExtension: () => { | ||
console.log("Received Extension request"); | ||
}, | ||
}; | ||
}, | ||
}), | ||
}, | ||
}); | ||
|
||
let karmaServer = null; | ||
let karmaConfig = null; | ||
let rSocketServerClosable = null; | ||
parseConfig( | ||
path.resolve("./karma.conf.js"), | ||
{ port: 9876 }, | ||
{ promiseConfig: true, throwErrors: true } | ||
) | ||
.then(async (_karmaConfig) => { | ||
rSocketServerClosable = await rSocketServer.bind(); | ||
console.log(`RSocket Server started on port ${rsocketServerPort}`); | ||
karmaConfig = _karmaConfig; | ||
karmaServer = new Server(_karmaConfig, async function doneCallback( | ||
exitCode | ||
) { | ||
console.log(`Karma exited with code: ${exitCode}`); | ||
await rSocketServerClosable.close(); | ||
process.exit(exitCode); | ||
}); | ||
return karmaServer.start(); | ||
}) | ||
.catch((rejectReason) => { | ||
console.error(rejectReason); | ||
process.exit(1); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/rsocket-browser-tck/src/WebsocketClientTransport.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { RSocketConnector } from "@rsocket/core"; | ||
import { WebsocketClientTransport } from "@rsocket/transport-websocket-client"; | ||
|
||
// const Buffer = require("buffer/").Buffer; | ||
|
||
// window.Buffer = Buffer; | ||
|
||
describe("WebsocketClientTransport", () => { | ||
describe("connector", function () { | ||
it("connect", async () => { | ||
const url = "ws://localhost:9091"; | ||
const connector = new RSocketConnector({ | ||
transport: new WebsocketClientTransport({ | ||
url, | ||
}), | ||
}); | ||
const rsocket = await connector.connect(); | ||
await new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(null); | ||
}, 80); | ||
}); | ||
await rsocket.close(); | ||
}); | ||
}); | ||
}); |