Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
add tests for checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
jc-fireball committed Oct 12, 2015
1 parent cf581fe commit 4f4f1e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
3 changes: 1 addition & 2 deletions CHANGES.rst
Expand Up @@ -4,15 +4,14 @@ Changes by Version
0.17.5 (unreleased)
-------------------

- Nothing changed yet.
- Set default checksum to ``CRC32C``.


0.17.4 (2015-10-12)
-------------------

- Updated ``vcr`` to use ``thriftrw``-generated code. This should resolve some
unicode errors during testing with ``vcr``.
- Set default checksum to ``CRC32C``.


0.17.3 (2015-10-09)
Expand Down
36 changes: 31 additions & 5 deletions tests/test_checksum.py
Expand Up @@ -19,28 +19,54 @@
# THE SOFTWARE.

from __future__ import absolute_import
import mock

import pytest

from tchannel import messages
from tchannel import TChannel
from tchannel import thrift
from tchannel.errors import FatalProtocolError
from tchannel.io import BytesIO
from tchannel.messages import CallRequestMessage
from tchannel.messages import ChecksumType
from tchannel.messages.common import generate_checksum
from tchannel.messages.common import verify_checksum


@pytest.mark.parametrize('checksum_type, seed', [
(ChecksumType.none, 0),
(ChecksumType.crc32, 0x0812fa3f),
@pytest.mark.parametrize('checksum_type', [
(ChecksumType.none),
(ChecksumType.crc32),
(ChecksumType.crc32c),
])
def test_checksum(checksum_type, seed):
def test_checksum(checksum_type):
message = CallRequestMessage()
message.checksum = (checksum_type, seed)
message.checksum = (checksum_type, None)
generate_checksum(message)
payload = messages.RW[message.message_type].write(
message, BytesIO()
).getvalue()

msg = messages.RW[message.message_type].read(BytesIO(payload))
assert verify_checksum(msg)


@pytest.mark.gen_test
def test_default_checksum_type():
server = TChannel("server")
server.listen()
with mock.patch(
'tchannel.messages.common.compute_checksum', autospec=True,
) as mock_compute_checksum:
client = TChannel("client")
service = thrift.load(
path='tchannel/health/meta.thrift',
service='health_test_server',
hostport=server.hostport,
)
with pytest.raises(FatalProtocolError):
yield client.thrift(service.Meta.health())

mock_compute_checksum.assert_called_with(
ChecksumType.crc32c, mock.ANY, mock.ANY,
)

0 comments on commit 4f4f1e1

Please sign in to comment.