py-amqp icon indicating copy to clipboard operation
py-amqp copied to clipboard

Added hypothesis property based testing

Open thedrow opened this issue 6 years ago • 6 comments

This PR uses hypothesis to check if arrays & dictionaries are serialized and deserialized correctly.

I also fixed our integer serialization and deserialization code, bytes string serialization and small string serialization on tables and arrays.

thedrow avatar Mar 09 '19 09:03 thedrow

Yes, the examples directory should be ignored when reviewing this.

thedrow avatar Mar 10 '19 07:03 thedrow

Seems like we have a genuine problem with strings inside dictionaries on Python 2. Even without any adjustments that were made in this branch I can reproduce this:

Falsifying example: test_table(self=<t.unit.test_serialization.test_serialization instance at 0x7fdf17cde518>, table={u'': u'\x80'})
Traceback (most recent call last):
  File "/home/omer/Documents/Projects/py-amqp/t/unit/test_serialization.py", line 126, in test_table
    assert loads(b'F', dumps(b'F', [table]))[0][0] == table
AssertionError: assert {'': '\xc2\x80'} == {'': '\x80'}
  Differing items:
  {'': '\xc2\x80'} != {'': '\x80'}
  Full diff:
  - {'': '\xc2\x80'}
  ?       ----
  + {u'': u'\x80'}
  ?  +    +

thedrow avatar Mar 12 '19 16:03 thedrow

Since '\x80' is a unicode string when you encode it to bytes, you get \xc2\x80 but we aren't decoding back. We're encoding again.

Not sure how to resolve this issue.

thedrow avatar Mar 12 '19 16:03 thedrow

Authentication fails with the addition of support for small strings in tables and arrays. I'm not sure why though.

Also, tox-docker doesn't seem to work anymore which is super strange.

thedrow avatar Mar 13 '19 14:03 thedrow

Seems like there's a bug in RabbitMQ with short strings in tables. It is allowed in the spec.

thedrow avatar Mar 13 '19 15:03 thedrow

I found the source of the problem: When RabbitMQ authenticates using the AMQPLAIN method it expects a longstr instead of a shortstr. See issue https://github.com/rabbitmq/rabbitmq-server/issues/1914.

thedrow avatar Mar 14 '19 09:03 thedrow