33import libtmux
44import lib .util .exception
55import os .path
6- import time
7- import sys
6+ from lib .networking import server , clientInterface
87import hyperion .lib .util .exception as exceptions
9- import hyperion .lib .util .config as config
108from hyperion .lib .monitoring .threads import *
119
1210is_py2 = sys .version [0 ] == '2'
@@ -28,8 +26,8 @@ def tearDown(self):
2826 pass
2927
3028 def test_construction (self ):
31- self .assertEqual (self .cc .config ['name' ], 'Unit test config' )
32- self .assertTrue (self .cc .server .has_session ('Unit test config' ))
29+ self .assertEqual (self .cc .config ['name' ], 'Unit- test- config' )
30+ self .assertTrue (self .cc .server .has_session ('Unit- test- config' ))
3331
3432 def test_host_resolution (self ):
3533 host_test_comp = self .cc .get_component_by_id ('host_depends_test@localhost' )
@@ -52,7 +50,7 @@ def test_component_fetch(self):
5250 self .cc .get_component_by_id ('do fail' )
5351
5452 lst = self .cc .get_start_all_list ()
55- self .assertEqual (lst [0 ].comp_id , 'tail@localhost ' )
53+ self .assertEqual (lst [0 ].comp_id , 'host_test@resolved-host ' )
5654
5755 wait = manager .get_component_wait (tail )
5856 self .assertEqual (wait , 0.2 )
@@ -206,5 +204,49 @@ def test_stop(self):
206204 )
207205
208206
207+ class ServerClientsTests (unittest .TestCase ):
208+ def setUp (self ):
209+ sms = server .SlaveManagementServer ()
210+ self .cc = manager .ControlCenter ('%s/data/test-config.yaml' % manager .BASE_DIR , slave_server = sms )
211+ self .cc .init ()
212+
213+ self .cc ._establish_master_connection ('localhost' )
214+ self .cc ._copy_config_to_remote ('localhost' )
215+
216+ config_path = "%s/%s.yaml" % (config .TMP_SLAVE_DIR , self .cc .config ['name' ])
217+ port = self .cc .slave_server .port
218+
219+ self .server = server .Server (config .DEFAULT_TCP_PORT , self .cc , loop_in_thread = True )
220+
221+ print ("Starting slave manager" )
222+ self .slc = slc = manager .SlaveManager (config_path )
223+ print ("Starting slave interface" )
224+ self .si = clientInterface .RemoteSlaveInterface ('localhost' , port , slc , loop_in_thread = True )
225+ print ("Starting client interface" )
226+ self .ci_queue = queue .Queue ()
227+ self .ci = clientInterface .RemoteControllerInterface ('localhost' , config .DEFAULT_TCP_PORT )
228+ self .ci .add_subscriber (self .ci_queue )
229+ print ("SETUP DONE" )
230+
231+ def tearDown (self ):
232+ try :
233+ self .ci .cleanup (True )
234+ self .server .worker .join ()
235+
236+ while self .cc .server .has_session (self .cc .session_name ):
237+ time .sleep (.5 )
238+
239+ except SystemExit :
240+ pass
241+
242+ def test_connection (self ):
243+ test_ev = events .CheckEvent ('tail@localhost' , config .CheckState .STOPPED )
244+ self .si .event_queue .put (test_ev )
245+ ci_msg = self .ci_queue .get (timeout = 5 )
246+
247+ self .assertEqual (ci_msg .comp_id , test_ev .comp_id )
248+ self .assertEqual (ci_msg .check_state , test_ev .check_state )
249+
250+
209251if __name__ == '__main__' :
210252 unittest .main ()
0 commit comments