Skip to content
Snippets Groups Projects
Commit 7c9f9e15 authored by Chris Pastl's avatar Chris Pastl
Browse files

refactor: add nil-checks for scheduler (testcase adaption)

parent a2940a16
No related branches found
No related tags found
1 merge request!27Fix redundant logging #136
Pipeline #7097 failed
...@@ -218,7 +218,8 @@ class EngineEventDispatcher: ...@@ -218,7 +218,8 @@ class EngineEventDispatcher:
self.logger.debug("on_play(..)") self.logger.debug("on_play(..)")
# Assign timestamp indicating start play time. Use the actual playtime when possible. # Assign timestamp indicating start play time. Use the actual playtime when possible.
entry.entry_start_actual = datetime.datetime.now() entry.entry_start_actual = datetime.datetime.now()
self.scheduler.on_play(entry) if self.scheduler is not None:
self.scheduler.on_play(entry)
self.call_event("on_play", entry) self.call_event("on_play", entry)
thread = Thread(target=func, args=(self, entry)) thread = Thread(target=func, args=(self, entry))
......
...@@ -106,11 +106,14 @@ class ClockInfoHandler: ...@@ -106,11 +106,14 @@ class ClockInfoHandler:
entry (PlaylistEntry): entry (PlaylistEntry):
""" """
active_playlist_type, active_playlist = self.engine.scheduler.get_active_playlist() if self.engine.scheduler is not None:
active_type_id = active_playlist_type.get("id") active_playlist_type, active_playlist = self.engine.scheduler.get_active_playlist()
active_timeslot = self.engine.scheduler.timetable.get_current_timeslot() active_type_id = active_playlist_type.get("id")
upcoming_timeslots = self.engine.scheduler.timetable.get_next_timeslots() active_timeslot = self.engine.scheduler.timetable.get_current_timeslot()
self.post_clock_info(active_type_id, active_playlist, active_timeslot, upcoming_timeslots) upcoming_timeslots = self.engine.scheduler.timetable.get_next_timeslots()
self.post_clock_info(
active_type_id, active_playlist, active_timeslot, upcoming_timeslots
)
def post_clock_info(self, active_type, active_playlist, active_timeslot, upcoming_timeslots): def post_clock_info(self, active_type, active_playlist, active_timeslot, upcoming_timeslots):
""" """
......
...@@ -574,4 +574,5 @@ class PlayCommand(EngineExecutor): ...@@ -574,4 +574,5 @@ class PlayCommand(EngineExecutor):
time.sleep(2) time.sleep(2)
self.engine.player.play(entries[0], Player.TransitionType.FADE) self.engine.player.play(entries[0], Player.TransitionType.FADE)
self.logger.info(self.engine.scheduler.timetable_renderer.get_ascii_timeslots()) if self.engine.scheduler is not None:
self.logger.info(self.engine.scheduler.timetable_renderer.get_ascii_timeslots())
...@@ -24,6 +24,7 @@ from time import sleep ...@@ -24,6 +24,7 @@ from time import sleep
from flask import Flask from flask import Flask
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from aura_engine.base.logger import AuraLogger
from aura_engine.base.utils import SimpleUtil as SU from aura_engine.base.utils import SimpleUtil as SU
from aura_engine.core.channels import ChannelName from aura_engine.core.channels import ChannelName
from aura_engine.core.client import CoreClient, PlayoutClient from aura_engine.core.client import CoreClient, PlayoutClient
...@@ -71,7 +72,7 @@ from aura_engine.events import EngineEventDispatcher ...@@ -71,7 +72,7 @@ from aura_engine.events import EngineEventDispatcher
class CoreClientMock(CoreClient): class CoreClientMock(CoreClient):
""" """
Client managing communication with Engine Core (Liquidsoap). Suppress unwanted behavior by subclassing and overriding.
""" """
instance = None instance = None
...@@ -99,15 +100,11 @@ class CoreClientMock(CoreClient): ...@@ -99,15 +100,11 @@ class CoreClientMock(CoreClient):
@synchronized @synchronized
def connect(self): def connect(self):
""" pass
Open connection.
"""
@synchronized @synchronized
def disconnect(self): def disconnect(self):
""" pass
Close connection.
"""
@synchronized @synchronized
def exec(self, namespace: str, action: str, args: str = "") -> str: def exec(self, namespace: str, action: str, args: str = "") -> str:
...@@ -127,31 +124,22 @@ class CoreClientMock(CoreClient): ...@@ -127,31 +124,22 @@ class CoreClientMock(CoreClient):
class PlayoutClientMock(CoreClientMock): class PlayoutClientMock(CoreClientMock):
""" """
Client managing communication with Engine Core (Liquidsoap). Mock PlayoutClient by subclssing and skipping unwanted.
""" """
mixer = None mixer: Mixer = None
def __init__(self, event_dispatcher: EngineEventDispatcher): def __init__(self, event_dispatcher: EngineEventDispatcher):
"""
Initialize the client.
"""
super().__init__(event_dispatcher) super().__init__(event_dispatcher)
self.mixer = Mixer("mixer", self) self.mixer = Mixer("mixer", self)
@staticmethod @staticmethod
def get_instance(event_dispatcher: EngineEventDispatcher) -> CoreClientMock: def get_instance(event_dispatcher: EngineEventDispatcher) -> CoreClientMock:
"""
Get an instance of the client singleton.
"""
if not PlayoutClientMock.instance: if not PlayoutClientMock.instance:
PlayoutClientMock.instance = PlayoutClientMock(event_dispatcher) PlayoutClientMock.instance = PlayoutClientMock(event_dispatcher)
return PlayoutClientMock.instance return PlayoutClientMock.instance
def get_mixer(self): def get_mixer(self):
"""
Get the mixer instance.
"""
return self.mixer return self.mixer
...@@ -160,23 +148,25 @@ class TestPlayCommand(unittest.TestCase): ...@@ -160,23 +148,25 @@ class TestPlayCommand(unittest.TestCase):
Testing the PlayCommand. Testing the PlayCommand.
""" """
engine: Engine = None
def setUp(self): def setUp(self):
config = AuraConfig.instance.config
AuraLogger(config)
self.logger = logging.getLogger("engine-tests")
app = Flask(__name__) app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
app.config["BABEL_DEFAULT_LOCALE"] = "de"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
DB.set_flask_db(SQLAlchemy(app)) DB.set_flask_db(SQLAlchemy(app))
AuraDatabaseModel.recreate_db() AuraDatabaseModel.recreate_db()
self.engine = Engine() engine = Engine()
self.dispatcher = EngineEventDispatcher(engine=self.engine) dispatcher = EngineEventDispatcher(engine=engine)
self.playout = PlayoutClientMock(event_dispatcher=self.dispatcher) playout = PlayoutClientMock(event_dispatcher=dispatcher)
self.player = Player(playout=self.playout, event_dispatcher=self.dispatcher) engine.player = Player(playout=playout, event_dispatcher=dispatcher)
self.engine.player = self.player # engine.scheduler = AuraScheduler(engine)
# engine.start()
# scheduler = AuraScheduler(self.engine) self.engine = engine
# self.engine.scheduler = scheduler
# self.engine.start()
def test_play(self): def test_play(self):
print(self._testMethodName) print(self._testMethodName)
...@@ -203,7 +193,7 @@ class TestPlayCommand(unittest.TestCase): ...@@ -203,7 +193,7 @@ class TestPlayCommand(unittest.TestCase):
command.do_preload(entries) command.do_preload(entries)
command.do_play(entries) command.do_play(entries)
assert entries[-1].status == Player.EntryPlayState.READY self.assertEqual(entries[-1].status, Player.EntryPlayState.READY)
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment