Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
chore(tests): Test timeout when reading response from router.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjw committed Sep 15, 2020
1 parent 53659f7 commit 82e6d93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/mock_sshclient.py
Expand Up @@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time

from paramiko.ssh_exception import AuthenticationException, \
NoValidConnectionsError

Expand Down Expand Up @@ -85,6 +87,18 @@ def read(self, count):
return data


class MockHungSSHSession:
def __init__(self):
self.channel = MockChannel()

def write(self, cmd):
pass

def read(self, count):
time.sleep(6)
return "".encode("utf8")


class MockChannel:
def __init__(self):
self.eof_received = False
Expand Down
15 changes: 14 additions & 1 deletion tests/test_scrape.py
Expand Up @@ -19,7 +19,7 @@

from zyxelprometheus import login, scrape_ifconfig, scrape_xdsl

from .mock_sshclient import MockSSHClient, MockSSHSession
from .mock_sshclient import MockSSHClient, MockSSHSession, MockHungSSHSession

IFCONFIG = open("example_ifconfig.txt", "rb").read().decode("utf8")
XDSL = open("example_xdsl.txt", "rb").read().decode("utf8")
Expand Down Expand Up @@ -54,3 +54,16 @@ def test_scrape_xdsl(self):
xdsl = scrape_xdsl(session)

self.assertTrue("Status: Showtime" in xdsl)

def test_timeout(self):
session = MockHungSSHSession()
MockSSHClient.add_session("192.168.1.1",
"admin",
"testpassword",
session)

session = login("192.168.1.1",
"admin",
"testpassword")

xdsl = scrape_xdsl(session)

0 comments on commit 82e6d93

Please sign in to comment.