NO_THREADS mode for tests

This commit is contained in:
Shoghi Cervantes 2013-08-28 16:00:30 +02:00
parent a07ae731e3
commit f9c405d46a
3 changed files with 13 additions and 5 deletions

View File

@ -31,7 +31,9 @@ class ConsoleAPI{
public function init(){
$this->server->schedule(2, array($this, "handle"), array(), true);
$this->loop = new ConsoleLoop();
if(!defined("NO_THREADS")){
$this->loop = new ConsoleLoop();
}
$this->register("help", "[page|command name]", array($this, "defaultCommands"));
$this->register("status", "", array($this, "defaultCommands"));
$this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands"));
@ -42,9 +44,11 @@ class ConsoleAPI{
function __destruct(){
$this->server->deleteEvent($this->event);
$this->loop->stop();
$this->loop->notify();
//$this->loop->join();
if(!defined("NO_THREADS")){
$this->loop->stop();
$this->loop->notify();
//$this->loop->join();
}
}
public function defaultCommands($cmd, $params, $issuer, $alias){
@ -248,6 +252,9 @@ class ConsoleAPI{
}
public function handle($time){
if(defined("NO_THREADS")){
return;
}
if($this->loop->line !== false){
$line = trim($this->loop->line);
$this->loop->line = false;

View File

@ -281,7 +281,7 @@ class ServerAPI{
if($this->getProperty("auto-save") === true){
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
}
if($this->getProperty("enable-rcon") === true){
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
}

View File

@ -12,6 +12,7 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{
}
public function testRead(){
define("NO_THREADS", true);
require_once(dirname(__FILE__)."/../dependencies.php");
require_once(FILE_PATH."/src/functions.php");
require_once(FILE_PATH."/src/dependencies.php");