[FIX] align sleep times, now all commands arrives after the before one has been processed.[TST][FIX] destructor and constructor testcases

This commit is contained in:
Benedek Racz 2020-01-22 13:33:09 +01:00
parent 9709eb82e9
commit eda36aa1a1
5 changed files with 33 additions and 31 deletions

View File

@ -41,9 +41,12 @@ class TestCaseConstructor(PexpectTestCase.PexpectTestCase):
def test_named_parameters (self): def test_named_parameters (self):
'''This tests that named parameters work. '''This tests that named parameters work.
''' '''
p = wexpect.spawn ('ls',timeout=10) p = wexpect.spawn('ls',timeout=10)
p = wexpect.spawn (timeout=10, command='ls') p.wait()
p = wexpect.spawn (args=[], command='ls') p = wexpect.spawn(timeout=10, command='ls')
p.wait()
p = wexpect.spawn(args=[], command='ls')
p.wait()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -32,19 +32,18 @@ class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
return 'SKIP' return 'SKIP'
gc.collect() gc.collect()
time.sleep(2) time.sleep(2)
p1 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p1 = wexpect.spawn('ls', port=4321)
p2 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p2 = wexpect.spawn('ls', port=4322)
p3 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p3 = wexpect.spawn('ls', port=4323)
p4 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p4 = wexpect.spawn('ls', port=4324)
fd_t1 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
p1.expect(wexpect.EOF) p1.expect(wexpect.EOF)
p2.expect(wexpect.EOF) p2.expect(wexpect.EOF)
p3.expect(wexpect.EOF) p3.expect(wexpect.EOF)
p4.expect(wexpect.EOF) p4.expect(wexpect.EOF)
p1.kill(9) p1.kill()
p2.kill(9) p2.kill()
p3.kill(9) p3.kill()
p4.kill(9) p4.kill()
p1 = None p1 = None
p2 = None p2 = None
p3 = None p3 = None
@ -52,15 +51,15 @@ class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
gc.collect() gc.collect()
time.sleep(2) # Some platforms are slow at gc... Solaris! time.sleep(2) # Some platforms are slow at gc... Solaris!
p1 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
p2 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p1 = wexpect.spawn('ls', port=4321)
p3 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p2 = wexpect.spawn('ls', port=4322)
p4 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p3 = wexpect.spawn('ls', port=4323)
fd_t2 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd) p4 = wexpect.spawn('ls', port=4324)
p1.kill(9) p1.kill()
p2.kill(9) p2.kill()
p3.kill(9) p3.kill()
p4.kill(9) p4.kill()
del (p1) del (p1)
del (p2) del (p2)
del (p3) del (p3)
@ -68,13 +67,10 @@ class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
gc.collect() gc.collect()
time.sleep(2) time.sleep(2)
p1 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p1 = wexpect.spawn('ls', port=4321)
p2 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p2 = wexpect.spawn('ls', port=4322)
p3 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p3 = wexpect.spawn('ls', port=4323)
p4 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN) p4 = wexpect.spawn('ls', port=4324)
fd_t3 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
assert (fd_t1 == fd_t2 == fd_t3), "pty file descriptors not properly garbage collected (fd_t1,fd_t2,fd_t3)=(%s,%s,%s)" % (str(fd_t1),str(fd_t2),str(fd_t3))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -175,7 +175,7 @@ class ConsoleReaderBase:
self.resumeThread() self.resumeThread()
paused = False paused = False
time.sleep(.1) time.sleep(.02)
def terminate_child(self): def terminate_child(self):
try: try:
@ -437,7 +437,7 @@ class ConsoleReaderSocket(ConsoleReaderBase):
self.sock.settimeout(5) self.sock.settimeout(5)
self.sock.listen(1) self.sock.listen(1)
self.connection, client_address = self.sock.accept() self.connection, client_address = self.sock.accept()
self.connection.settimeout(.2) self.connection.settimeout(.01)
logger.info(f'Client connected: {client_address}') logger.info(f'Client connected: {client_address}')
except: except:
logger.error(f"Port: {self.port}") logger.error(f"Port: {self.port}")

View File

@ -990,6 +990,10 @@ class SpawnSocket(SpawnBase):
except EOF: except EOF:
self.flag_eof = True self.flag_eof = True
raise raise
except ConnectionResetError:
self.flag_eof = True
logger.info("EOF('ConnectionResetError')")
raise EOF('ConnectionResetError')
except socket.timeout: except socket.timeout:
return '' return ''

View File

@ -44,7 +44,6 @@ import os
import logging import logging
def init_logger(logger): def init_logger(logger):
os.environ['WEXPECT_LOGGER_LEVEL'] = 'DEBUG'
try: try:
logger_level = os.environ['WEXPECT_LOGGER_LEVEL'] logger_level = os.environ['WEXPECT_LOGGER_LEVEL']
try: try: