Skip to content

Commit

Permalink
Merge pull request #32 from benmerckx/neko_tests
Browse files Browse the repository at this point in the history
Neko tests
  • Loading branch information
back2dos committed Jun 11, 2016
2 parents a176883 + d9bf79f commit 51857f7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bin
/testphp
/testneko
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ install:

script:
#- haxelib run travix interp
- haxelib run travix php
#- haxelib run travix php
- haxelib run travix node
- haxelib run travix neko -lib tink_tcp -lib tink_runloop -D concurrent
- haxelib run travix neko -lib tink_tcp -lib tink_runloop
- haxelib run travix neko -D nekotools
- haxelib run travix neko -D mod_neko

#- haxelib run travix python
#- haxelib run travix flash
#- haxelib run travix java -lib tink_tcp -lib tink_runloop
#- haxelib run travix cpp -lib tink_tcp -lib tink_runloop
#- haxelib run travix cs
#- haxelib run travix cs
96 changes: 61 additions & 35 deletions tests/RunTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RunTests {
res.body.all().handle(function (o) {
var raw = o.sure().toString();
trace(raw);
var data:Data = haxe.Json.parse(raw);
var data:Data = haxe.Json.parse(raw);
assertEquals((method:String), data.method);
assertEquals(uri, data.uri);
assertEquals(body, data.body);
Expand Down Expand Up @@ -79,23 +79,13 @@ class RunTests {

static function onServer(f:Host->Future<Noise>) {
var ret = [];

#if php

if (new Process('haxe', ['build-php.hxml']).exitCode() != 0)
throw 'failed to build PHP';
var server = new Process('php', ['-S', '127.0.0.1:8000', 'testphp/index.php']);
var i = 0;
while (i < 20) {
try {
var socket = new sys.net.Socket();
socket.connect(new sys.net.Host('127.0.0.1'), 8000);
socket.close();
break;
} catch(e: Dynamic) {
Sys.sleep(.1);
i++;
continue;
}
}
waitForConnection('127.0.0.1', 8000);
var done = f(new Host('127.0.0.1', 8000));
var h = new haxe.Http('http://127.0.0.1:8000/multipart');
var s = 'hello world';
Expand All @@ -117,48 +107,84 @@ class RunTests {
done.handle(function () {
server.kill();
});
#end

#if neko
//TODO: test actual mod_neko too

#elseif (neko && (nekotools || mod_neko))

Sys.command('haxe', ['build-neko.hxml']);
var cwd = Sys.getCwd();
Sys.setCwd('testneko');
#if nekotools
var server = new Process('nekotools', ['server', '-p', '8000', '-rewrite']);
waitForConnection('0.0.0.0', 8000);
#elseif mod_neko
sys.io.File.saveContent('.htaccess', ['RewriteEngine On','RewriteBase /','RewriteRule ^(.*)$ index.n [QSA,L]'].join('\n'));
Sys.command('docker', ['run', '-d', '-v', sys.FileSystem.fullPath(Sys.getCwd())+':/var/www/html', '-p', '8000:80', '--name', 'tink_http_mod_neko', 'codeurs/mod-neko']);
waitForConnection('0.0.0.0', 8000);
Sys.sleep(2);
#end
Sys.setCwd(cwd);

var done = f(new Host('localhost', 8000));
ret.push(done);
done.handle(function () {
function kill() {
#if mod_neko
Sys.command('docker', ['stop', 'tink_http_mod_neko']);
Sys.command('docker', ['rm', 'tink_http_mod_neko']);
#else
server.kill();
});
#end
}

try {
var done = f(new Host('0.0.0.0', 8000));
ret.push(done);
done.handle(kill);
} catch (e: Dynamic) {
Sys.println('Failed: '+e);
kill();
}

#end
#if (neko || java || cpp)
#elseif (neko || java || cpp)
ret.push(onContainer(new TcpContainer(2000), f.bind(new Host('localhost', 2000))));
#end

#if nodejs
#elseif nodejs
ret.push(onContainer(new NodeContainer(3000), f.bind(new Host('localhost', 3000))));

#end

return Future.ofMany(ret);
}

#if sys
static function waitForConnection(host, port) {
var i = 0;
while (i < 100) {
try {
var socket = new sys.net.Socket();
socket.connect(new sys.net.Host(host), port);
socket.close();
break;
} catch(e: Dynamic) {
Sys.sleep(.1);
i++;
}
}
}
#end

static function getClients() {
var clients:Array<Client> = [];

#if php
#if (php || (neko && (nekotools || mod_neko)))
clients.push(new StdClient());
#end

#if (neko || java || cpp)
#elseif (neko || java || cpp)
clients.push(new TcpClient());
#end

#if nodejs
#elseif nodejs
clients.push(new NodeClient());
#end

return clients;
}

static function main() {
onServer(performTest.bind(_, getClients())).handle(function () {
Sys.exit(0);//Just in case
Expand Down

0 comments on commit 51857f7

Please sign in to comment.