Skip to content

Commit

Permalink
Add WebSocket test project. See #1332.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Dec 2, 2015
1 parent 2babc54 commit 8c71e54
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/vibe.http.websocket/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "1332",
"dependencies": {
"vibe-d:http": { "path": "../../" }
},
"versions": ["VibeDefaultMain"]
}
34 changes: 34 additions & 0 deletions tests/vibe.http.websocket/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import vibe.core.core;
import vibe.core.log;
import vibe.http.server;
import vibe.http.websockets;

shared static this()
{
auto settings = new HTTPServerSettings;
// 10k + issue number -> Avoid bind errors
settings.port = 11332;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, handleWebSockets(&onWS));

runTask({
scope(exit) exitEventLoop(true);

auto ws = connectWebSocket(URL("http://127.0.0.1:11332/"));
ws.send("foo");
assert(ws.receiveText() == "hello");
ws.send("bar");
assert(!ws.waitForData);
ws.close();
logInfo("WebSocket test successful");
});
}

void onWS(scope WebSocket ws)
{
assert(ws.receiveText() == "foo");
ws.send("hello");
assert(ws.receiveText() == "bar");
ws.close();
}

0 comments on commit 8c71e54

Please sign in to comment.