Skip to content

Commit

Permalink
ensure that client 'if not self.sock: self._connect()' behavior is te…
Browse files Browse the repository at this point in the history
…sted
  • Loading branch information
shargan committed Aug 30, 2018
1 parent 9a34f2c commit abe233f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 4 additions & 5 deletions pymemcache/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,11 @@ def _store_cmd(self, name, values, expire, noreply, cas=None):
extra += b' noreply'

cmds.append(name + b' ' + key + b' ' +
six.text_type(flags).encode('ascii') +
b' ' + six.text_type(expire).encode('ascii') +
b' ' + six.text_type(len(data)).encode('ascii') + extra +
b'\r\n' + data + b'\r\n')
six.text_type(flags).encode('ascii') +
b' ' + six.text_type(expire).encode('ascii') +
b' ' + six.text_type(len(data)).encode('ascii') +
extra + b'\r\n' + data + b'\r\n')

# TODO: behavior appears untested
if not self.sock:
self._connect()

Expand Down
9 changes: 8 additions & 1 deletion pymemcache/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

import collections
import errno
import functools
import json
import mock
import socket
import unittest
import pytest
Expand Down Expand Up @@ -85,7 +87,12 @@ def __getattr__(self, name):
class ClientTestMixin(object):
def make_client(self, mock_socket_values, **kwargs):
client = Client(None, **kwargs)
client.sock = MockSocket(list(mock_socket_values))
# mock out client._connect() rather than hard-settting client.sock to
# ensure methods are checking whether self.sock is None before
# attempting to use it
sock = MockSocket(list(mock_socket_values))
client._connect = mock.Mock(side_effect=functools.partial(
setattr, client, "sock", sock))
return client

def test_set_success(self):
Expand Down

0 comments on commit abe233f

Please sign in to comment.