Preserve live reconnect endpoints and execute QA commands between frames
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""Reopening the legacy login board must not replace the explicit live endpoint."""
|
||||
import unittest,types,sys
|
||||
from pathlib import Path
|
||||
class LiveEndpointTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.previous={};self.mods={n:types.ModuleType(n) for n in ('game','introLogin','networkModule','mt_channel')};m=self.mods
|
||||
class Stream:
|
||||
def SetConnectInfo(self,h,p,a=0,ap=0):self.addr,self.port,self.account_addr,self.account_port=h,p,a,ap
|
||||
class Login:
|
||||
def Open(self):self.stream.SetConnectInfo('legacy.invalid',13000,'legacy.invalid',11000)
|
||||
m['networkModule'].MainStream=Stream;m['introLogin'].LoginWindow=Login
|
||||
m['game'].GameWindow=type('GameWindow',(),{'Open':lambda self:7})
|
||||
self.busy=False;m['mt_channel'].g_switcher=types.SimpleNamespace(Busy=lambda:self.busy)
|
||||
for n,mod in m.items():self.previous[n]=sys.modules.get(n);sys.modules[n]=mod
|
||||
self.ns={};source=(Path(__file__).resolve().parents[2]/'src/platform/ScriptLib/LiveEndpointScript.inc').read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0];exec(source,self.ns)
|
||||
self.stream=Stream();self.login=Login();self.login.stream=self.stream
|
||||
def tearDown(self):
|
||||
for n,old in self.previous.items():
|
||||
if old is None:sys.modules.pop(n,None)
|
||||
else:sys.modules[n]=old
|
||||
def test_explicit_endpoint_survives_login_open(self):
|
||||
self.ns['Configure'](self.stream,'192.0.2.1',13040,'192.0.2.2',11040);self.login.Open()
|
||||
self.assertEqual((self.stream.addr,self.stream.port,self.stream.account_addr,self.stream.account_port),('192.0.2.1',13040,'192.0.2.2',11040))
|
||||
self.assertFalse(self.stream._portRestoreLiveEndpoint)
|
||||
def test_manual_selection_and_explicit_channel_change_remain_allowed(self):
|
||||
self.ns['Configure'](self.stream,'192.0.2.1',13040,'192.0.2.1',11040)
|
||||
self.stream.SetConnectInfo('192.0.2.3',13050,'192.0.2.3',11050)
|
||||
game=self.mods['game'].GameWindow();game.stream=self.stream;self.assertEqual(game.Open(),7)
|
||||
self.login.Open();self.assertEqual(self.stream.port,13050)
|
||||
self.busy=True;self.login.Open();self.assertEqual(self.stream.addr,'legacy.invalid')
|
||||
def test_original_default_when_no_endpoint_selected(self):
|
||||
self.login.Open();self.assertEqual(self.stream.addr,'legacy.invalid')
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Commands are consumed once, outside the UI callback which caused the reconnect crash."""
|
||||
from pathlib import Path
|
||||
import tempfile,subprocess,unittest
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
class CommandFileTest(unittest.TestCase):
|
||||
def test_consumption_and_failure(self):
|
||||
code=r'''
|
||||
#include "python_command_file.h"
|
||||
#include <cassert>
|
||||
int main(){
|
||||
std::string err;int calls=0;
|
||||
auto run=[&](const std::string& c){++calls;assert(c=="test()");return true;};
|
||||
assert(mt_host::consume_python_command_file("",run,err) && calls==0);
|
||||
assert(mt_host::consume_python_command_file("command.py",run,err) && calls==0);
|
||||
{std::ofstream f("command.py");f<<"test()";}
|
||||
assert(mt_host::consume_python_command_file("command.py",run,err) && calls==1);
|
||||
assert(mt_host::consume_python_command_file("command.py",run,err) && calls==1);
|
||||
{std::ofstream f("command.py");f<<"fail()";}
|
||||
assert(!mt_host::consume_python_command_file("command.py",[&](const std::string&){++calls;return false;},err));
|
||||
assert(!std::filesystem::exists("command.py") && calls==2);
|
||||
{std::ofstream f("command.py");f<<std::string(1024*1024+1,'x');}
|
||||
assert(!mt_host::consume_python_command_file("command.py",run,err) && calls==2 && !err.empty());
|
||||
assert(!std::filesystem::exists("command.py"));
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p=Path(d);(p/'test.cpp').write_text(code)
|
||||
subprocess.run(['c++','-std=c++17','-I'+str(ROOT/'src/host'),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
|
||||
subprocess.run([str(p/'test')],cwd=d,check=True)
|
||||
Reference in New Issue
Block a user