Keep movement physics ticking while idle
This commit is contained in:
1 parent
8d2374346e
commit
e8b1913e97
2 files changed
+67
-6
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.bot import start_automation
|
||||
|
||||
|
||||
class IdleJob:
|
||||
def idle(self):
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
self.state = self.idle
|
||||
|
||||
|
||||
class IdlePhysicsTests(unittest.TestCase):
|
||||
def test_movement_worker_ticks_physics_without_active_work(self):
|
||||
connection = Munch(connected=True)
|
||||
job = IdleJob()
|
||||
monitor = Munch(tick=lambda: None, suppress_job=False)
|
||||
game = Munch(_advance_world_time=lambda: None)
|
||||
state = Munch(
|
||||
running=True,
|
||||
connection=connection,
|
||||
pos=(0, 64, 0),
|
||||
game=game,
|
||||
job=job,
|
||||
path=[],
|
||||
breaking=None,
|
||||
threat_monitor=monitor,
|
||||
movement_status='idle',
|
||||
)
|
||||
ticks = []
|
||||
|
||||
def tick_when_idle(global_state):
|
||||
ticks.append(True)
|
||||
global_state.running = False
|
||||
|
||||
worker = None
|
||||
try:
|
||||
with patch('mosfet.bot.missing_movement_chunks', return_value=[]), \
|
||||
patch('mosfet.bot.tick', side_effect=tick_when_idle):
|
||||
worker = start_automation(state, initialize=False)
|
||||
worker.join(timeout=2.0)
|
||||
finally:
|
||||
state.running = False
|
||||
if state.get('movement_stop_event'):
|
||||
state.movement_stop_event.set()
|
||||
if worker is not None:
|
||||
worker.join(timeout=1.0)
|
||||
|
||||
self.assertFalse(worker.is_alive())
|
||||
self.assertTrue(ticks)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user