mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00

* Tests: massively improve the memory leak test performance With the growing number of worlds, GC becomes the bottleneck and slows down the test. * Tests: fix typing in general/test_memory
22 lines
878 B
Python
22 lines
878 B
Python
import unittest
|
|
|
|
from BaseClasses import MultiWorld
|
|
from worlds.AutoWorld import AutoWorldRegister
|
|
from . import setup_solo_multiworld
|
|
|
|
|
|
class TestWorldMemory(unittest.TestCase):
|
|
def test_leak(self) -> None:
|
|
"""Tests that worlds don't leak references to MultiWorld or themselves with default options."""
|
|
import gc
|
|
import weakref
|
|
refs: dict[str, weakref.ReferenceType[MultiWorld]] = {}
|
|
for game_name, world_type in AutoWorldRegister.world_types.items():
|
|
with self.subTest("Game creation", game_name=game_name):
|
|
weak = weakref.ref(setup_solo_multiworld(world_type))
|
|
refs[game_name] = weak
|
|
gc.collect()
|
|
for game_name, weak in refs.items():
|
|
with self.subTest("Game cleanup", game_name=game_name):
|
|
self.assertFalse(weak(), "World leaked a reference")
|