Skip to content

Commit

Permalink
Adds HTTP readiness checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Tingan Ho committed Aug 20, 2017
1 parent f675bfe commit 33fc760
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_executable(generate-diagnostics ${PROJECT_SOURCE_DIR}/tasks/GenerateDiagnost
add_executable(generate-json-rpc-client-stub ${PROJECT_SOURCE_DIR}/tasks/GenerateJsonRpcClientStub.cpp)
add_executable(run-tests ${PROJECT_SOURCE_DIR}/src/TestFramework/Exec.cpp)

target_link_libraries(l10ns glob jsoncpp jsonrpccpp-common jsonrpccpp-client ${Boost_LIBRARIES})
target_link_libraries(l10ns glob jsoncpp jsonrpccpp-common jsonrpccpp-client curl ${Boost_LIBRARIES})

target_link_libraries(accept-baseline glob ${Boost_LIBRARIES})
target_link_libraries(clean-project glob ${Boost_LIBRARIES})
Expand Down
16 changes: 14 additions & 2 deletions src/Extensions/JavaScript/Source/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ interface Files {
}

function main() {
let firstRequest = true;
const server = http.createServer((req, res) => {
if (firstRequest) {
const body = '{}';
res.writeHead(200, { Connection: 'close', 'Content-Length': Buffer.byteLength(body) });
res.write(body);
res.end();
firstRequest = false;
return;
}

let data: Buffer[] = [];
req.on('data', (chunk: Buffer) => {
data.push(chunk);
Expand All @@ -51,11 +61,13 @@ function main() {
}

function write(id: number, result: any) {
res.write(JSON.stringify({
const body = JSON.stringify({
id,
jsonrpc: '2.0',
result,
} as RPCResponse));
} as RPCResponse);
res.writeHead(200, { Connection: 'close', 'Content-Length': Buffer.byteLength(body) });
res.write(body);
res.end();
}
});
Expand Down
20 changes: 20 additions & 0 deletions src/Program/ExtensionTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Extension.cpp"
#include "Core.cpp"
#include <signal.h>
#include <curl/curl.h>

using namespace L10ns;
using namespace TestFramework;
Expand All @@ -19,6 +20,10 @@ void kill_all_processes(int signum) {
exit(signum);
}

size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) {
return size * nmemb;
}

void run_extension_tests(Session* session) {
string extension_file = join_paths(*session->root_dir, "Extension.json");
Extension* extension;
Expand All @@ -27,6 +32,21 @@ void run_extension_tests(Session* session) {
extension = Extension::create(session, extension_file);
child = extension->start_server();
signal(SIGINT, kill_all_processes);

CURL *curl;
CURLcode res;
curl = curl_easy_init();
while (true) {
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8888");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
continue;
}

curl_easy_cleanup(curl);
break;
}
};

auto for_each_compilation_test_file = [&](std::function<void (const string&)> callback) -> void {
Expand Down

0 comments on commit 33fc760

Please sign in to comment.