Skip to content

Commit

Permalink
STOMP: modernize Python test suite
Browse files Browse the repository at this point in the history
 * Upgrade to stomp.py 4.1.24 to gain Python 3.9 compatibility
 * Adjust to modern client/plugin disconnection delay
 * Remove tests that are not really possible to test with
   a regular well-behaved client (missed heartbeats)

(cherry picked from commit 3c38b42)

Conflicts:
	deps/rabbitmq_stomp/test/python_SUITE_data/src/test_util.py
  • Loading branch information
michaelklishin committed Mar 10, 2021
1 parent 7ddcc30 commit ddf663e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 54 deletions.
27 changes: 0 additions & 27 deletions deps/rabbitmq_stomp/test/python_SUITE_data/deps/stomppy/Makefile

This file was deleted.

7 changes: 4 additions & 3 deletions deps/rabbitmq_stomp/test/python_SUITE_data/src/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def create_connection_obj(self, version='1.0', vhost='/', heartbeats=(0, 0)):

def create_connection(self, user='guest', passcode='guest', wait=True, **kwargs):
conn = self.create_connection_obj(**kwargs)
conn.start()
conn.connect(user, passcode, wait=wait)
return conn

Expand Down Expand Up @@ -105,8 +104,10 @@ def setUp(self):

def tearDown(self):
if self.conn.is_connected():
self.conn.disconnect()
self.conn.stop()
try:
self.conn.disconnect()
except:
pass

def simple_test_send_rec(self, dest, headers={}):
self.listener.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def test_implicit_connect(self):
new_conn = stomp.Connection(host_and_ports=[('localhost', int(os.environ["STOMP_PORT"]))])
new_conn.set_listener('', listener)

new_conn.start() # not going to issue connect
new_conn.transport.start()

self.subscribe_dest(new_conn, "/topic/implicit", 'sub_implicit',
receipt='implicit')

Expand All @@ -34,7 +35,6 @@ def test_default_user(self):
listener = base.WaitableListener()
new_conn = stomp.Connection(host_and_ports=[('localhost', int(os.environ["STOMP_PORT"]))])
new_conn.set_listener('', listener)
new_conn.start()
new_conn.connect()
try:
self.assertFalse(listener.wait(3)) # no error back
Expand Down
21 changes: 4 additions & 17 deletions deps/rabbitmq_stomp/test/python_SUITE_data/src/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def test_connect_version_1_0(self):
self.assertTrue(new_conn.is_connected())
finally:
new_conn.disconnect()
self.assertFalse(new_conn.is_connected())

def test_connect_version_1_1(self):
''' Test CONNECT with version 1.1'''
Expand All @@ -63,7 +62,6 @@ def test_connect_version_1_1(self):
self.assertTrue(new_conn.is_connected())
finally:
new_conn.disconnect()
self.assertFalse(new_conn.is_connected())

def test_connect_version_1_2(self):
''' Test CONNECT with version 1.2'''
Expand All @@ -73,22 +71,10 @@ def test_connect_version_1_2(self):
self.assertTrue(new_conn.is_connected())
finally:
new_conn.disconnect()
# connections are closed asynchronously, e.g. a few seconds later
time.sleep(6)
self.assertFalse(new_conn.is_connected())

def test_heartbeat_disconnects_client(self):
''' Test heart-beat disconnection'''
self.conn.disconnect()
new_conn = self.create_connection(version='1.1', heartbeats=(1500, 0))
try:
self.assertTrue(new_conn.is_connected())
time.sleep(1)
self.assertTrue(new_conn.is_connected())
time.sleep(3)
self.assertFalse(new_conn.is_connected())
finally:
if new_conn.is_connected():
new_conn.disconnect()

def test_unsupported_version(self):
''' Test unsupported version on CONNECT command'''
self.bad_connect("Supported versions are 1.0,1.1,1.2\n", version='100.1')
Expand All @@ -111,7 +97,6 @@ def bad_connect(self, expected, user='guest', passcode='guest', **kwargs):
listener = base.WaitableListener()
new_conn.set_listener('', listener)
try:
new_conn.start()
new_conn.connect(user, passcode)
self.assertTrue(listener.wait())
self.assertEquals(expected, listener.errors[0]['message'])
Expand Down Expand Up @@ -144,6 +129,8 @@ def test_send_recv_header(self):
def test_disconnect(self):
''' Test DISCONNECT command'''
self.conn.disconnect()
# connections are closed asynchronously, e.g. a few seconds later
time.sleep(7)
self.assertFalse(self.conn.is_connected())

def test_disconnect_with_receipt(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __ssl_connect(self):
ssl_cert_file = ssl_cert_file,
ssl_ca_certs = ssl_ca_certs)
print("FILE: ".format(ssl_cert_file))
conn.start()
conn.connect("guest", "guest")
return conn

Expand All @@ -30,7 +29,6 @@ def __ssl_auth_connect(self):
use_ssl = True, ssl_key_file = ssl_key_file,
ssl_cert_file = ssl_cert_file,
ssl_ca_certs = ssl_ca_certs)
conn.start()
conn.connect()
return conn

Expand Down
10 changes: 7 additions & 3 deletions deps/rabbitmq_stomp/test/python_SUITE_data/src/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ def disable_default_user():
switch_config(default_user='[]')

def switch_config(implicit_connect='', default_user=''):
cmd = 'application:stop(rabbitmq_stomp),'
cmd = ''
cmd += 'ok = io:format("~n===== Ranch listeners (before stop) =====~n~n~p~n", [ranch:info()]),'
cmd += '_ = application:stop(rabbitmq_stomp),'
cmd += 'io:format("~n===== Ranch listeners (after stop) =====~n~n~p~n", [ranch:info()]),'
if implicit_connect:
cmd += 'application:set_env(rabbitmq_stomp,implicit_connect,{}),'.format(implicit_connect)
if default_user:
cmd += 'application:set_env(rabbitmq_stomp,default_user,{}),'.format(default_user)
cmd += 'application:start(rabbitmq_stomp).'
cmd += 'ok = application:set_env(rabbitmq_stomp,default_user,{}),'.format(default_user)
cmd += '_ = application:start(rabbitmq_stomp),'
cmd += 'io:format("~n===== Ranch listeners (after start) =====~n~n~p~n", [ranch:info()]).'
rabbitmqctl(['eval', cmd])

def rabbitmqctl(args):
Expand Down

0 comments on commit ddf663e

Please sign in to comment.