Skip to content

Commit

Permalink
Add SmokeTest for SSL chunked response
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Jan 8, 2024
1 parent e33b09d commit 9681439
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(int argc, char **argv) {
char *CXX = strcpy(calloc(1024, 1), or_else(getenv("CXX"), "g++"));
char *EXEC_SUFFIX = strcpy(calloc(1024, 1), maybe(getenv("EXEC_SUFFIX")));

char *EXAMPLE_FILES[] = {"Http3Server", "Broadcast", "HelloWorld", "Crc32", "ServerName",
char *EXAMPLE_FILES[] = {"SmokeTest", "Http3Server", "Broadcast", "HelloWorld", "Crc32", "ServerName",
"EchoServer", "BroadcastingEchoServer", "UpgradeSync", "UpgradeAsync", "ParameterRoutes"};

strcat(CXXFLAGS, " -march=native -O3 -Wpedantic -Wall -Wextra -Wsign-conversion -Wconversion -std=c++20 -Isrc -IuSockets/src");
Expand Down
62 changes: 62 additions & 0 deletions examples/SmokeTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "App.h"

/* This is not an example; it is a smoke test used in CI testing */

struct Stream {
int offset;
bool aborted;
};

std::string constantChunk;

void streamData(auto *res, auto stream, int chunk) {

if (stream->aborted) {
return;
}

if (chunk < 1600) {
res->cork([res, stream, chunk]() {
auto ok = res->write(constantChunk);
if (ok) {
streamData(res, stream, chunk + 1);
return;
}

uWS::Loop::get()->defer([res, stream, chunk]() {
streamData(res, stream, chunk + 1);
});
});
} else {
res->cork([res]() {
res->end();
});
}
}

int main() {

for (int i = 0; i < 65536; i++) {
constantChunk.append("a", 1);
}

uWS::SSLApp({
.key_file_name = "misc/key.pem",
.cert_file_name = "misc/cert.pem",
.passphrase = "1234"
}).get("/*", [](auto *res, auto */*req*/) {

auto stream = std::make_shared<Stream>(0, false);
streamData(res, stream, 0);

res->onAborted([stream]() {
stream->aborted = true;
});
}).listen(3000, [](auto *listen_socket) {
if (listen_socket) {
std::cout << "Listening on port " << 3000 << std::endl;
}
}).run();

std::cout << "Failed to listen on port 3000" << std::endl;
}

0 comments on commit 9681439

Please sign in to comment.