Skip to content

Commit

Permalink
Fixes linux tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tingan Ho committed Aug 20, 2017
1 parent 309adf9 commit 9736729
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 53 deletions.
84 changes: 41 additions & 43 deletions src/Extensions/JavaScript/Source/Main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import net = require('net');
import fs = require('fs');
import http = require('http');
import { extractKeysFromFile, Key } from './KeyExtractor/Extractor';

interface SyncParams {
Expand All @@ -26,46 +25,45 @@ interface Files {
[name: string]: Key[];
}

function sendFinishStatus() {
fs.createWriteStream('', { fd: 4 }).write('1');
}

const server = net.createServer((client) => {
client.setEncoding('utf8');
client.on('data', (data) => {
const rpc = JSON.parse(data.toString()) as RPCRequest;
switch (rpc.method) {
case 'sync':
const files: Files = {};
const callExpressionIdentifiers = rpc.params.function_names;
for (const f of rpc.params.files) {
const keys = extractKeysFromFile(f, callExpressionIdentifiers);
files[f] = keys;
}
write(rpc.id, files);
break;
case 'compile':
break;
default:
throw new Error(`Unknown method '${rpc.method}'`);
}
});
client.pipe(client);
function main() {
const server = http.createServer((req, res) => {
let data: Buffer[] = [];
req.on('data', (chunk: Buffer) => {
data.push(chunk);
})
.on('end', () => {
const body = Buffer.concat(data).toString();
const rpc = JSON.parse(body) as RPCRequest;
switch (rpc.method) {
case 'sync':
const files: Files = {};
const callExpressionIdentifiers = rpc.params.function_names;
for (const f of rpc.params.files) {
const keys = extractKeysFromFile(f, callExpressionIdentifiers);
files[f] = keys;
}
write(rpc.id, files);
break;
case 'compile':
break;
default:
throw new Error(`Unknown method '${rpc.method}'`);
}

function write(id: number, result: any) {
client.write(JSON.stringify({
id,
jsonrpc: '2.0',
result,
} as RPCResponse));
}
});
function write(id: number, result: any) {
res.write(JSON.stringify({
id,
jsonrpc: '2.0',
result,
} as RPCResponse));
res.end();
}
});
}).listen(8888);

process.on('SIGTERM', () => {
server.close();
process.exit(0);
});

server.listen('/tmp/l10ns.sock', () => {
sendFinishStatus();
});
process.on('SIGTERM', () => {
server.close();
process.exit(0);
});
}
main();
7 changes: 3 additions & 4 deletions src/Program/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ class Extension {
Session* session;
JsonRpcClient* client;

int start_server(int (&fd)[2]) {
int start_server() {
pid_t cpid = fork();
if (cpid == 0) {
close(fd[0]);
execl("/bin/bash", "/bin/bash", "-c", command.c_str(), (char *) 0);
}
return cpid;
Expand All @@ -123,8 +122,8 @@ class Extension {
for (auto const& f : function_names) {
function_names_json.append(f);
}
UnixDomainSocketClient unix_domain_socket_client("/tmp/l10ns.sock");
JsonRpcClient rpc_client(unix_domain_socket_client);
HttpClient http_client("http://localhost:8888");
JsonRpcClient rpc_client(http_client);
auto file_to_keys_json = rpc_client.sync(files_json, function_names_json);
FileToKeys file_to_keys;
for (Json::ValueIterator file_to_keys_it = file_to_keys_json.begin(); file_to_keys_it != file_to_keys_json.end(); file_to_keys_it++) {
Expand Down
6 changes: 1 addition & 5 deletions src/Program/ExtensionTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ void run_extension_tests(Session* session) {

auto start_extension_server = [&]() -> void {
extension = Extension::create(session, extension_file);
int fd[2];
pipe(fd);
child = extension->start_server(fd);
child = extension->start_server();
signal(SIGINT, kill_all_processes);
char buf[1];
read(fd[0], buf, 1);
};

auto for_each_compilation_test_file = [&](std::function<void (const string&)> callback) -> void {
Expand Down
1 change: 0 additions & 1 deletion src/Program/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ bool copy_folder(fs::path const & source, fs::path const & destination) {
<< "' already exists." << '\n';
return false;
}

if (!fs::create_directory(destination)) {
std::cerr << "Unable to create destination directory '" << destination.string() << "'.\n";
return false;
Expand Down

0 comments on commit 9736729

Please sign in to comment.