diff --git a/stomp/test/utils_test.py b/stomp/test/utils_test.py index 61145a19..7746d89c 100644 --- a/stomp/test/utils_test.py +++ b/stomp/test/utils_test.py @@ -29,3 +29,16 @@ def test_parse_headers(self): ] self.assertEquals( {'h1': r'foo:\bar ', 'h:2': 'baz\r\nquux'}, parse_headers(lines)) + + def test_calculate_heartbeats(self): + chb = (3000, 5000) + shb = map(str, reversed(chb)) + self.assertEquals((3000, 5000), calculate_heartbeats(shb, chb)) + shb = ('6000', '2000') + self.assertEquals((3000, 6000), calculate_heartbeats(shb, chb)) + shb = ('0', '0') + self.assertEquals((0, 0), calculate_heartbeats(shb, chb)) + shb = ('10000', '0') + self.assertEquals((0, 10000), calculate_heartbeats(shb, chb)) + chb = (0, 0) + self.assertEquals((0, 0), calculate_heartbeats(shb, chb)) diff --git a/stomp/utils.py b/stomp/utils.py index c205907f..75e12291 100755 --- a/stomp/utils.py +++ b/stomp/utils.py @@ -157,9 +157,9 @@ def calculate_heartbeats(shb, chb): x = 0 y = 0 if cx != 0 and sy != '0': - x = max(cx, int(sx)) + x = max(cx, int(sy)) if cy != 0 and sx != '0': - y = max(cy, int(sy)) + y = max(cy, int(sx)) return (x, y)