Skip to content

Commit 9bf8352

Browse files
committed
feature(test_claster): add test for stale connections
1 parent 366048d commit 9bf8352

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/integration/standard/test_cluster.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import asyncore
15+
import subprocess
1416

1517
try:
1618
import unittest2 as unittest
@@ -1111,6 +1113,34 @@ def test_add_profile_timeout(self):
11111113
else:
11121114
raise Exception("add_execution_profile didn't timeout after {0} retries".format(max_retry_count))
11131115

1116+
def test_stale_connections_after_shutdown(self):
1117+
"""
1118+
Check if any connection/socket left unclosed after cluster.shutdown
1119+
Originates from https://github.com/scylladb/python-driver/issues/120
1120+
"""
1121+
for _ in range(10):
1122+
with TestCluster(protocol_version=3) as cluster:
1123+
cluster.connect().execute("SELECT * FROM system_schema.keyspaces")
1124+
time.sleep(1)
1125+
1126+
with TestCluster(protocol_version=3) as cluster:
1127+
session = cluster.connect()
1128+
for _ in range(5):
1129+
session.execute("SELECT * FROM system_schema.keyspaces")
1130+
1131+
for _ in range(10):
1132+
with TestCluster(protocol_version=3) as cluster:
1133+
cluster.connect().execute("SELECT * FROM system_schema.keyspaces")
1134+
1135+
for _ in range(10):
1136+
with TestCluster(protocol_version=3) as cluster:
1137+
cluster.connect()
1138+
1139+
result = subprocess.run(["lsof -nP | awk '$3 ~ \":9042\" {print $0}' | grep ''"], shell=True, capture_output=True)
1140+
if result.returncode:
1141+
continue
1142+
assert False, f'Found stale connections: {result.stdout}'
1143+
11141144
@notwindows
11151145
def test_execute_query_timeout(self):
11161146
with TestCluster() as cluster:

0 commit comments

Comments
 (0)