Skip to content

Commit 8ccba34

Browse files
d-w-moorealanking
authored andcommitted
[#3][#345] Allow tests to pass and accommodate older Python
- don't use f"" style strings - getblocking socket method doesn't exist before Python3.7 - skip test that makes logging explode in client dot - in test, do not assert that a connection throws an exception on a second call to disconnect().
1 parent 71c7fcd commit 8ccba34

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

irods/message/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from . import quasixml as ET_quasi_xml
1313
from collections import namedtuple
1414
import os
15+
import fcntl
1516
import ast
1617
import threading
1718
from irods.message.message import Message
@@ -150,19 +151,23 @@ def ET(xml_type = 0, server_version = None):
150151
UNICODE = str
151152

152153

154+
155+
# Necessary for older python (<3.7):
156+
_socket_is_blocking = (lambda self: 0 == fcntl.fcntl(self.fileno(), fcntl.F_GETFL) & os.O_NONBLOCK)
157+
153158
def _recv_message_in_len(sock, size):
154159
size_left = size
155160
retbuf = None
156161

157162
# Get socket properties for debug and exception messages.
158163
host, port = sock.getpeername()
159-
is_blocking = sock.getblocking()
164+
is_blocking = _socket_is_blocking(sock)
160165
timeout = sock.gettimeout()
161166

162-
logger.debug(f'host: {host}')
163-
logger.debug(f'port: {port}')
164-
logger.debug(f'is_blocking: {is_blocking}')
165-
logger.debug(f'timeout: {timeout}')
167+
logger.debug('host: %s',host)
168+
logger.debug('port: %d',port)
169+
logger.debug('is_blocking: %s',is_blocking)
170+
logger.debug('timeout: %s',timeout)
166171

167172
while size_left > 0:
168173
try:

irods/test/connection_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ def test_failed_connection(self):
4141
# set port back
4242
self.sess.pool.account.port = saved_port
4343

44-
def test_send_failure(self):
44+
def test_1_multiple_disconnect(self):
4545
with self.sess.pool.get_connection() as conn:
46-
# try to close connection twice, 2nd one should fail
46+
# disconnect() may now be called multiple times without error.
47+
# (Note, here it is called implicitly upon exiting the with-block.)
4748
conn.disconnect()
48-
with self.assertRaises(NetworkException):
49-
conn.disconnect()
49+
50+
def test_2_multiple_disconnect(self):
51+
conn = self.sess.pool.get_connection()
52+
# disconnect() may now be called multiple times without error.
53+
conn.disconnect()
54+
conn.disconnect()
5055

5156
def test_reply_failure(self):
5257
with self.sess.pool.get_connection() as conn:

irods/test/pool_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111
import json
1212
import unittest
13+
import socket
1314
import irods.test.helpers as helpers
1415
from irods.connection import DESTRUCTOR_MSG
1516

@@ -244,6 +245,10 @@ def test_no_refresh_connection(self):
244245
# Test to confirm the connection destructor log message is actually
245246
# logged to file, to confirm the destructor is called
246247
def test_connection_destructor_called(self):
248+
249+
if self.sess.host != socket.gethostname() and not LOCALHOST_REGEX.match (self.sess.host):
250+
self.skipTest('local test only - client dot does not like the extra logging')
251+
247252
# Set 'irods_connection_refresh_time' to '3' (in seconds) in
248253
# ~/.irods/irods_environment.json file. This means any connection
249254
# that was created more than 3 seconds ago will be dropped and

0 commit comments

Comments
 (0)