Files
san7890 265ceb3eb2 Fixes Flakey Ashwalker Lung Unit Test Failures on gateway_test (#94821)
## About The Pull Request

Closes #94794

Both of these unit tests were using the outdated way of changing the gas
mix on a turf, probably because they were more than a few years old
apiece. The modern way is using the `/datum/gas_mixture` and
`parse_gas_string()` to either retrieve the gas mix from cache or
generate it on-demand. Neither of these tests were doing that, and they
worked well enough until they got mutated in #94771
(01c7ef7de1).

I am uncertain of the specifics that are behind either one
spontaneously/always failing but I do know that they weren't doing it
the "right way". I suspect the flakiness in the Breath Ashwalker Sanity
(that loads a full ashwalker carbon instead of just the lungs) is
because it was initiating a gas mix with no volume within it, and that
volume would get filled up as the other turfs in the loc would update it
somewhere in the atmos chain? We only checked for the "low oxygen"
status effect on the mob and that could easily have been filled up to
normal depending on how much happened. Regardless the best way to fix
this is to just have all the turfs in the unit test room get changed to
prevent any schenanigans with that.

Another explanation for the flakiness is that the ashwalker lungs
themselves use the same "old" way of getting the gas mix instead of the
modern way (such that the lung breath values can adapt to changes)... I
think...
## Why It's Good For The Game

Less developer frustration at spontaneously failing unit tests through
no fault of their own.
## Changelog
Irrelevant
2026-01-11 15:02:01 -05:00

108 lines
6.3 KiB
Plaintext

/// Tests to ensure humans, plasmamen, and ashwalkers can breath in normal situations.
/// Ensures algorithmic correctness of the "breathe()" and "toggle_internals()" procs.
/// Built to prevent regression on an issue surrounding QUANTIZE() and BREATH_VOLUME.
/// See the comment on BREATH_VOLUME for more details.
/datum/unit_test/breath
abstract_type = /datum/unit_test/breath
/// Equips the given Human with a new instance of the given tank type and a breathing mask.
/// Returns the new equipped tank.
/datum/unit_test/breath/proc/equip_labrat_internals(mob/living/carbon/human/lab_rat, tank_type)
var/obj/item/clothing/mask/breath/mask = allocate(/obj/item/clothing/mask/breath)
var/obj/item/tank/internals/source = allocate(tank_type)
lab_rat.equip_to_slot_if_possible(mask, ITEM_SLOT_MASK)
lab_rat.equip_to_slot_if_possible(source, ITEM_SLOT_HANDS)
return source
/datum/unit_test/breath/breath_sanity/Run()
// Breathing from turf.
var/mob/living/carbon/human/lab_rat = allocate(/mob/living/carbon/human/consistent)
lab_rat.forceMove(run_loc_floor_bottom_left)
var/turf/open/to_fill = run_loc_floor_bottom_left
to_fill.initial_gas_mix = OPENTURF_DEFAULT_ATMOS
to_fill.air = to_fill.create_gas_mixture()
lab_rat.breathe()
TEST_ASSERT(!lab_rat.failed_last_breath && !lab_rat.has_alert(ALERT_NOT_ENOUGH_OXYGEN), "Humans can't get a full breath from the standard initial_gas_mix on a turf")
// Breathing from standard internals tank.
lab_rat = allocate(/mob/living/carbon/human/consistent)
var/obj/item/tank/internals/source = equip_labrat_internals(lab_rat, /obj/item/tank/internals/emergency_oxygen)
lab_rat.breathe()
TEST_ASSERT(!lab_rat.failed_last_breath && !lab_rat.has_alert(ALERT_NOT_ENOUGH_OXYGEN), "Humans can't get a full breath from standard o2 tanks")
if(!isnull(lab_rat.internal))
TEST_ASSERT(source.toggle_internals(lab_rat) && isnull(lab_rat.internal), "toggle_internals() failed to close internals")
// Empty internals suffocation.
lab_rat = allocate(/mob/living/carbon/human/consistent)
source = equip_labrat_internals(lab_rat, /obj/item/tank/internals/emergency_oxygen/empty)
TEST_ASSERT(source.toggle_internals(lab_rat) && !isnull(lab_rat.internal), "Plasmaman toggle_internals() failed to toggle internals")
lab_rat.breathe()
TEST_ASSERT(lab_rat.failed_last_breath && lab_rat.has_alert(ALERT_NOT_ENOUGH_OXYGEN), "Humans should suffocate from empty o2 tanks")
// Nitrogen internals suffocation.
lab_rat = allocate(/mob/living/carbon/human/consistent)
source = equip_labrat_internals(lab_rat, /obj/item/tank/internals/emergency_oxygen/empty)
source.air_contents.assert_gas(/datum/gas/nitrogen)
source.air_contents.gases[/datum/gas/nitrogen][MOLES] = (10 * ONE_ATMOSPHERE) * source.volume / (R_IDEAL_GAS_EQUATION * T20C)
TEST_ASSERT(source.toggle_internals(lab_rat) && !isnull(lab_rat.internal), "Plasmaman toggle_internals() failed to toggle internals")
lab_rat.breathe()
TEST_ASSERT(lab_rat.failed_last_breath && lab_rat.has_alert(ALERT_NOT_ENOUGH_OXYGEN), "Humans should suffocate from pure n2 tanks")
/datum/unit_test/breath/breath_sanity/Destroy()
//Reset initial_gas_mix to avoid future issues on other tests
var/turf/open/to_fill = run_loc_floor_bottom_left
to_fill.initial_gas_mix = OPENTURF_DEFAULT_ATMOS
return ..()
/// Tests to make sure plasmaman can breath from their internal tanks
/datum/unit_test/breath/breath_sanity_plasmamen
/datum/unit_test/breath/breath_sanity_plasmamen/Run()
// Breathing from pure Plasma internals.
var/mob/living/carbon/human/species/plasma/lab_rat = allocate(/mob/living/carbon/human/species/plasma)
var/obj/item/tank/internals/plasmaman/source = equip_labrat_internals(lab_rat, /obj/item/tank/internals/plasmaman)
TEST_ASSERT(source.toggle_internals(lab_rat) && !isnull(lab_rat.internal), "Plasmaman toggle_internals() failed to toggle internals")
lab_rat.breathe()
TEST_ASSERT(!lab_rat.failed_last_breath && !lab_rat.has_alert(ALERT_NOT_ENOUGH_PLASMA), "Plasmamen can't get a full breath from a standard plasma tank")
TEST_ASSERT(source.toggle_internals(lab_rat) && !lab_rat.internal, "Plasmaman toggle_internals() failed to toggle internals")
// Empty internals suffocation.
lab_rat = allocate(/mob/living/carbon/human/species/plasma)
source = equip_labrat_internals(lab_rat, /obj/item/tank/internals/emergency_oxygen/empty)
TEST_ASSERT(source.toggle_internals(lab_rat) && !isnull(lab_rat.internal), "Plasmaman toggle_internals() failed to toggle internals")
lab_rat.breathe()
TEST_ASSERT(lab_rat.failed_last_breath && lab_rat.has_alert(ALERT_NOT_ENOUGH_PLASMA), "Plasmamen should suffocate from empty o2 tanks")
// Nitrogen internals suffocation.
lab_rat = allocate(/mob/living/carbon/human/species/plasma)
source = equip_labrat_internals(lab_rat, /obj/item/tank/internals/emergency_oxygen/empty)
source.air_contents.assert_gas(/datum/gas/nitrogen)
source.air_contents.gases[/datum/gas/nitrogen][MOLES] = (10 * ONE_ATMOSPHERE) * source.volume / (R_IDEAL_GAS_EQUATION * T20C)
TEST_ASSERT(source.toggle_internals(lab_rat) && !isnull(lab_rat.internal), "Plasmaman toggle_internals() failed to toggle internals")
lab_rat.breathe()
TEST_ASSERT(lab_rat.failed_last_breath && lab_rat.has_alert(ALERT_NOT_ENOUGH_PLASMA), "Humans should suffocate from pure n2 tanks")
/// Tests to make sure ashwalkers can breathe from the lavaland air.
/datum/unit_test/breath/breath_sanity_ashwalker
/datum/unit_test/breath/breath_sanity_ashwalker/Run()
var/mob/living/carbon/human/species/lizard/ashwalker/lab_rat = allocate(/mob/living/carbon/human/species/lizard/ashwalker)
turn_room_into_lavaland()
lab_rat.breathe()
TEST_ASSERT(!lab_rat.has_alert(ALERT_NOT_ENOUGH_OXYGEN), "Ashwalkers can't get a full breath from the Lavaland's initial_gas_mix on a turf")
/// Replaces the air mix in the entire room with lavaland air mix
/datum/unit_test/breath/breath_sanity_ashwalker/proc/turn_room_into_lavaland()
var/area/unit_test_area = get_area(run_loc_floor_bottom_left)
var/list/turf/lavalandable_turfs = unit_test_area.get_turfs_from_all_zlevels()
var/datum/gas_mixture/lavaland_mix = SSair.parse_gas_string(LAVALAND_DEFAULT_ATMOS, /datum/gas_mixture/immutable/planetary)
var/datum/gas_mixture/volumetric_mix = allocate(/datum/gas_mixture, 2500)
volumetric_mix.copy_from(lavaland_mix)
for(var/turf/open/tile in lavalandable_turfs)
tile.copy_air(volumetric_mix)
tile.air_update_turf(update = FALSE, remove = FALSE)