Skip to content

Commit 6ea05fd

Browse files
d-w-moorealanking
authored andcommitted
[#418] raise error in test for IRODS_VERSION mismatch
We now probe the server_version in each test and quit if the server is too recent, a strong reminder to update the IRODS_VERSION in the StartupPack. That probing initially caused test_failed_connection not to pass, due to its implicit assumption of an empty idle pool - also fixed in this commit.
1 parent 1c1463c commit 6ea05fd

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

irods/test/connection_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def test_connection_destructor(self):
3030
conn.release(destroy=True)
3131

3232
def test_failed_connection(self):
33+
# Make sure no connections are cached in self.sess.pool.idle to be grabbed by get_connection().
34+
# (Necessary after #418 fix; make_session() can probe server_version, which then leaves an idle conn.)
35+
self.sess.cleanup()
3336
# mess with the account's port
3437
saved_port = self.sess.port
3538
self.sess.pool.account.port = 6666

irods/test/helpers.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
from __future__ import print_function
23
import os
34
import io
45
import tempfile
@@ -13,12 +14,26 @@
1314
import random
1415
import datetime
1516
import json
17+
import sys
1618
from irods.session import iRODSSession
17-
from irods.message import iRODSMessage
19+
from irods.message import (iRODSMessage, IRODS_VERSION)
1820
from irods.password_obfuscation import encode
1921
from six.moves import range
2022

2123

24+
class StopTestsException(Exception):
25+
26+
def __init__(self,*args,**kwargs):
27+
super(StopTestsException,self).__init__(*args,**kwargs)
28+
if 'unittest' in sys.modules.keys():
29+
print("Aborting tests [ Got : %r ]" % self, file = sys.stderr)
30+
os.abort()
31+
32+
33+
class iRODS_Server_Too_Recent(StopTestsException):
34+
pass
35+
36+
2237
def my_function_name():
2338
"""Returns the name of the calling function or method"""
2439
return inspect.getframeinfo(inspect.currentframe().f_back).function
@@ -87,15 +102,27 @@ def recast(k):
87102
return (config, auth)
88103

89104

90-
def make_session(**kwargs):
105+
# Create a connection for test, based on ~/.irods environment by default.
106+
107+
def make_session(test_server_version = True, **kwargs):
91108
try:
92109
env_file = kwargs.pop('irods_env_file')
93110
except KeyError:
94111
try:
95112
env_file = os.environ['IRODS_ENVIRONMENT_FILE']
96113
except KeyError:
97114
env_file = os.path.expanduser('~/.irods/irods_environment.json')
98-
return iRODSSession( irods_env_file = env_file, **kwargs )
115+
session = iRODSSession( irods_env_file = env_file, **kwargs )
116+
117+
if test_server_version:
118+
connected_version = session.server_version[:3]
119+
advertised_version = IRODS_VERSION[:3]
120+
if connected_version > advertised_version:
121+
msg = ("Connected server is {connected_version}, "
122+
"but this python-irodsclient advertises compatibility up to {advertised_version}.").format(**locals())
123+
raise iRODS_Server_Too_Recent(msg)
124+
125+
return session
99126

100127

101128
def home_collection(session):

0 commit comments

Comments
 (0)