Files
WoW-Hybrid-gateway/tests/native_startup_shutdown_wait_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

32 lines
2.1 KiB
Python

"""Server save readiness must precede relaunch; no online-flag writes."""
import sys,unittest
from pathlib import Path
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import start_native_client as m
class ShutdownReadinessTest(unittest.TestCase):
def test_delayed_save_waits_for_real_zero(self):
with patch.object(m,'db',side_effect=['1','1','0'])as query,patch.object(m.time,'monotonic',side_effect=[0,0,.25]),patch.object(m.time,'sleep')as sleep:
m.wait_local_character_shutdown()
self.assertEqual(query.call_count,3);self.assertEqual(sleep.call_count,2)
self.assertTrue(all(call.args==('SELECT COUNT(*) FROM tw_char.characters WHERE online<>0;',)for call in query.call_args_list))
def test_still_online_fails_without_faking_offline(self):
with patch.object(m,'db',return_value='1'),patch.object(m.time,'monotonic',side_effect=[0,15]),patch.object(m.time,'sleep')as sleep:
with self.assertRaisesRegex(RuntimeError,'still pending'):m.wait_local_character_shutdown()
sleep.assert_not_called()
def test_bad_or_unavailable_server_state_is_not_readiness(self):
for value in ('',None,'secret','-1'):
with patch.object(m,'db',return_value=value),self.assertRaises(RuntimeError):m.wait_local_character_shutdown()
with patch.object(m,'db',side_effect=RuntimeError('server unavailable')),self.assertRaises(RuntimeError):m.wait_local_character_shutdown()
def test_explicit_peer_session_waits_only_for_its_character(self):
with patch.object(m,'db',return_value='0')as query:
m.wait_local_character_shutdown(character_guid=4519)
query.assert_called_once_with('SELECT COUNT(*) FROM tw_char.characters WHERE online<>0 AND guid=4519;')
def test_bad_character_scope_is_rejected_before_query(self):
for guid in (0,-1,True,'4519',2**32):
with patch.object(m,'db')as query,self.assertRaises(ValueError):m.wait_local_character_shutdown(character_guid=guid)
query.assert_not_called()
if __name__=='__main__':unittest.main()