Adds test run mode. Fails travis if it fails (#34198)

* Adds test run

* Add OVERRIDE_LOG_DIRECTORY_PARAMETER

* Fails travis if a test run fails

* Fix travis looping

* Move the unit tests behind a define

* Fix various test run things

* Remove the DEBUG check because that's just you shooting yourself in the foot

* Adds readability spacing. Makes RunUnitTests a generic proc

* Remove unit tests
This commit is contained in:
Jordan Brown
2018-01-19 11:53:26 -05:00
committed by Emmett Gaines
parent b960c75f52
commit bf7938cfdf
6 changed files with 56 additions and 10 deletions

View File

@@ -500,3 +500,10 @@ GLOBAL_LIST_INIT(ghost_others_options, list(GHOST_OTHERS_SIMPLE, GHOST_OTHERS_DE
#define SUMMON_GUNS "guns"
#define SUMMON_MAGIC "magic"
//Run the world with this parameter to enable a single run though of the game setup and tear down process with unit tests in between
#define TEST_RUN_PARAMETER "test-run"
//Force the log directory to be something specific in the data/logs folder
#define OVERRIDE_LOG_DIRECTORY_PARAMETER "log-directory"
//Prevent the master controller from starting automatically, overrides TEST_RUN_PARAMETER
#define NO_INIT_PARAMETER "no-init"

View File

@@ -49,6 +49,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
var/map_loading = FALSE //Are we loading in a new map?
var/current_runlevel //for scheduling different subsystems for different stages of the round
var/sleep_offline_after_initializations = TRUE
var/static/restart_clear = 0
var/static/restart_timeout = 0
@@ -196,11 +197,12 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
// Sort subsystems by display setting for easy access.
sortTim(subsystems, /proc/cmp_subsystem_display)
// Set world options.
if(sleep_offline_after_initializations)
world.sleep_offline = TRUE
world.fps = CONFIG_GET(number/fps)
var/initialized_tod = REALTIMEOFDAY
sleep(1)
if(CONFIG_GET(flag/resume_after_initializations))
if(sleep_offline_after_initializations && CONFIG_GET(flag/resume_after_initializations))
world.sleep_offline = FALSE
initializations_finished_with_no_players_logged_in = initialized_tod < REALTIMEOFDAY - 10
// Loop.

View File

@@ -39,11 +39,21 @@ GLOBAL_PROTECT(security_mode)
GLOB.restart_counter = text2num(trim(file2text(RESTART_COUNTER_PATH)))
fdel(RESTART_COUNTER_PATH)
if("no-init" in params)
if(NO_INIT_PARAMETER in params)
return
Master.Initialize(10, FALSE)
if(TEST_RUN_PARAMETER in params)
HandleTestRun()
/world/proc/HandleTestRun()
//trigger things to run the whole process
Master.sleep_offline_after_initializations = FALSE
SSticker.start_immediately = TRUE
CONFIG_SET(number/round_end_countdown, 0)
SSticker.force_ending = TRUE
/world/proc/SetupExternalRSC()
#if (PRELOAD_RSC == 0)
GLOB.external_rsc_urls = world.file2list("config/external_rsc_urls.txt","\n")
@@ -56,11 +66,15 @@ GLOBAL_PROTECT(security_mode)
#endif
/world/proc/SetupLogs()
var/override_dir = params[OVERRIDE_LOG_DIRECTORY_PARAMETER]
if(!override_dir)
GLOB.log_directory = "data/logs/[time2text(world.realtime, "YYYY/MM/DD")]/round-"
if(GLOB.round_id)
GLOB.log_directory += "[GLOB.round_id]"
else
GLOB.log_directory += "[replacetext(time_stamp(), ":", ".")]"
else
GLOB.log_directory = "data/logs/[override_dir]"
GLOB.world_game_log = file("[GLOB.log_directory]/game.log")
GLOB.world_attack_log = file("[GLOB.log_directory]/attack.log")
GLOB.world_runtime_log = file("[GLOB.log_directory]/runtime.log")
@@ -132,6 +146,23 @@ GLOBAL_PROTECT(security_mode)
for(var/client/C in GLOB.clients)
C.AnnouncePR(final_composed)
/world/proc/FinishTestRun()
set waitfor = FALSE
var/list/fail_reasons
if(GLOB)
if(GLOB.total_runtimes != 0)
fail_reasons = list("Total runtimes: [GLOB.total_runtimes]")
if(!GLOB.log_directory)
LAZYADD(fail_reasons, "Missing GLOB.log_directory!")
else
fail_reasons = list("Missing GLOB!")
if(!fail_reasons)
text2file("Success!", "[GLOB.log_directory]/clean_run.lk")
else
log_world("Test run failed!\n[fail_reasons.Join("\n")]")
sleep(0) //yes, 0, this'll let Reboot finish and prevent byond memes
qdel(src) //shut it down
/world/Reboot(reason = 0, fast_track = FALSE)
SERVER_TOOLS_ON_REBOOT
if (reason || fast_track) //special reboot, do none of the normal stuff
@@ -143,6 +174,10 @@ GLOBAL_PROTECT(security_mode)
to_chat(world, "<span class='boldannounce'>Rebooting world...</span>")
Master.Shutdown() //run SS shutdowns
if(TEST_RUN_PARAMETER in params)
FinishTestRun()
return
if(SERVER_TOOLS_PRESENT)
var/do_hard_reboot
// check the hard reboot counter

View File

@@ -116,7 +116,8 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
if(GLOB.error_cache)
GLOB.error_cache.log_error(E, desclines)
SEND_TEXT(world.log, "\[[time_stamp()]] Runtime in [E.file],[E.line]: [E]")
var/main_line = "\[[time_stamp()]] Runtime in [E.file],[E.line]: [E]"
SEND_TEXT(world.log, main_line)
for(var/line in desclines)
SEND_TEXT(world.log, line)

View File

@@ -48,6 +48,7 @@ if [ "$BUILD_TOOLS" = false ]; then
if [ "$BUILD_TESTING" = true ]; then
tools/travis/dm.sh -DTRAVISBUILDING -DTRAVISTESTING -DALL_MAPS tgstation.dme
else
tools/travis/dm.sh -DTRAVISBUILDING tgstation.dme
tools/travis/dm.sh -DTRAVISBUILDING tgstation.dme && DreamDaemon tgstation.dmb -close -trusted -params "test-run&log-directory=travis"
cat data/logs/travis/clean_run.lk
fi;
fi;