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

Commit

Permalink
Merge pull request #460 from cloudant/intermittent-read-timeout
Browse files Browse the repository at this point in the history
Intermittent read timeout
  • Loading branch information
ricellis authored Feb 19, 2020
2 parents 1237453 + 8331efa commit 084f575
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ sudo: required
language: python

python:
- "2.7"
- "3.6"
- "3.8"

env:
- ADMIN_PARTY=true COUCHDB_VERSION=2.1.1
- ADMIN_PARTY=false COUCHDB_VERSION=2.1.1
- ADMIN_PARTY=true COUCHDB_VERSION=1.7.1
- ADMIN_PARTY=false COUCHDB_VERSION=1.7.1
- ADMIN_PARTY=true COUCHDB_VERSION=2.3.1
- ADMIN_PARTY=false COUCHDB_VERSION=2.3.1
- ADMIN_PARTY=true COUCHDB_VERSION=1.7.2
- ADMIN_PARTY=false COUCHDB_VERSION=1.7.2

services:
- docker
Expand All @@ -30,7 +29,7 @@ before_script:
# command to run tests
script:
- pylint ./src/cloudant
- nosetests -A 'not db or ((db is "couch" or "couch" in db) and (not couchapi or couchapi <='${COUCHDB_VERSION:0:1}'))' -w ./tests/unit
- nosetests -A 'not db or ((db == "couch" or "couch" in db) and (not couchapi or couchapi <='${COUCHDB_VERSION:0:1}'))' -w ./tests/unit

notifications:
email: false
5 changes: 2 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setupPythonAndTest(pythonVersion, testSuite) {
pip install -r test-requirements.txt
${'simplejson'.equals(testSuite) ? 'pip install simplejson' : ''}
pylint ./src/cloudant
nosetests -A 'not db or (db is "cloudant" or "cloudant" in db)' -w ./tests/unit --with-xunit
nosetests -A 'not db or (db == "cloudant" or "cloudant" in db)' -w ./tests/unit --with-xunit
"""
} finally {
// Load the test results
Expand All @@ -61,10 +61,9 @@ stage('Checkout'){
}

stage('Test'){
def py2 = '2'
def py3 = '3'
def axes = [:]
[py2, py3].each { version ->
[py3].each { version ->
['basic','cookie','iam'].each { auth ->
axes.put("Python${version}-${auth}", {setupPythonAndTest(version, auth)})
}
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/client_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (C) 2015, 2019 IBM Corp. All rights reserved.
# Copyright (C) 2015, 2020 IBM Corp. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -405,9 +405,10 @@ def test_create_invalid_database_name(self):
"""
dbname = 'invalidDbName_'
self.client.connect()
with self.assertRaises(CloudantDatabaseException) as cm:
with self.assertRaises((CloudantDatabaseException, HTTPError)) as cm:
self.client.create_database(dbname)
self.assertEqual(cm.exception.status_code, 400)
code = cm.exception.status_code if hasattr(cm.exception, 'status_code') else cm.exception.response.status_code
self.assertEqual(code, 400)
self.client.disconnect()

@skip_if_not_cookie_auth
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/replicator_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (C) 2015, 2018 IBM Corp. All rights reserved.
# Copyright (C) 2015, 2020 IBM Corp. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -220,10 +220,13 @@ def test_create_replication(self):
def test_timeout_in_create_replication(self):
"""
Test that a read timeout exception is thrown when creating a
replicator with a timeout value of 500 ms.
replicator with a read timeout value of 5 s.
"""
# Setup client with a timeout
self.set_up_client(auto_connect=True, timeout=.5)
# Setup client with a read timeout (but the standard connect timeout)
# Note that this timeout applies to all connections from this client
# setting it too short can cause intermittent failures when responses
# are not quick enough. Setting it too long makes the test take longer.
self.set_up_client(auto_connect=True, timeout=(30,5))
self.db = self.client[self.test_target_dbname]
self.target_db = self.client[self.test_dbname]
# Construct a replicator with the updated client
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/unit_t_db_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (C) 2015, 2019 IBM Corp. All rights reserved.
# Copyright (C) 2015, 2020 IBM Corp. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -109,15 +109,15 @@ def setUpClass(cls):

if os.environ.get('DB_USER') is None:
# Get couchdb docker node name
if os.environ.get('COUCHDB_VERSION') == '2.1.1':
if os.environ.get('COUCHDB_VERSION') == '2.3.1':
os.environ['NODENAME'] = requests.get(
'{0}/_membership'.format(os.environ['DB_URL'])).json()['all_nodes'][0]
os.environ['DB_USER_CREATED'] = '1'
os.environ['DB_USER'] = 'user-{0}'.format(
unicode_(uuid.uuid4())
)
os.environ['DB_PASSWORD'] = 'password'
if os.environ.get('COUCHDB_VERSION') == '2.1.1':
if os.environ.get('COUCHDB_VERSION') == '2.3.1':
resp = requests.put(
'{0}/_node/{1}/_config/admins/{2}'.format(
os.environ['DB_URL'],
Expand All @@ -143,7 +143,7 @@ def tearDownClass(cls):
"""
if (os.environ.get('RUN_CLOUDANT_TESTS') is None and
os.environ.get('DB_USER_CREATED') is not None):
if os.environ.get('COUCHDB_VERSION') == '2.1.1':
if os.environ.get('COUCHDB_VERSION') == '2.3.1':
resp = requests.delete(
'{0}://{1}:{2}@{3}/_node/{4}/_config/admins/{5}'.format(
os.environ['DB_URL'].split('://', 1)[0],
Expand Down

0 comments on commit 084f575

Please sign in to comment.