summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Åstrand (astrand) <astrand@cendio.se>2013-11-28 09:32:30 +0100
committerPeter Åstrand (astrand) <astrand@cendio.se>2013-11-28 09:32:30 +0100
commitb92528aebad3f8d0eca9dab0f9a4b792ac1505a6 (patch)
tree1b3ad2a47bee6675c5302ed79768abbd32fcca4b /tests
parent81e2a53692dd83f13c98c988bad19fe2f2bc52d8 (diff)
parentc3acdc2e38f871e28ffda1847b4338c4b02296b8 (diff)
downloadwebsockify-b92528aebad3f8d0eca9dab0f9a4b792ac1505a6.tar.gz
Merge commit 'c3acdc2e38f871e28ffda1847b4338c4b02296b8'
* commit 'c3acdc2e38f871e28ffda1847b4338c4b02296b8': Adds optional TCP_KEEPALIVE to WebSocketServer
Diffstat (limited to 'tests')
-rw-r--r--tests/test_websocket.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/test_websocket.py b/tests/test_websocket.py
new file mode 100644
index 0000000..c603189
--- /dev/null
+++ b/tests/test_websocket.py
@@ -0,0 +1,69 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright(c)2013 NTT 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. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""Unit tests for websockify."""
+
+import socket
+import unittest
+from websockify import websocket as websocket
+
+
+class WebSocketTestCase(unittest.TestCase):
+
+ def setUp(self):
+ """Called automatically before each test."""
+ super(WebSocketTestCase, self).setUp()
+
+ def tearDown(self):
+ """Called automatically after each test."""
+ super(WebSocketTestCase, self).tearDown()
+
+ def testsocket_set_keepalive_options(self):
+ server = websocket.WebSocketServer(listen_host='localhost',
+ listen_port=80,
+ key='./',
+ web='./',
+ record='./',
+ daemon=True,
+ ssl_only=1)
+ keepcnt = 12
+ keepidle = 34
+ keepintvl = 56
+
+ sock = server.socket('localhost',
+ tcp_keepcnt=keepcnt,
+ tcp_keepidle=keepidle,
+ tcp_keepintvl=keepintvl)
+
+ self.assertEqual(sock.getsockopt(socket.SOL_TCP,
+ socket.TCP_KEEPCNT), keepcnt)
+ self.assertEqual(sock.getsockopt(socket.SOL_TCP,
+ socket.TCP_KEEPIDLE), keepidle)
+ self.assertEqual(sock.getsockopt(socket.SOL_TCP,
+ socket.TCP_KEEPINTVL), keepintvl)
+
+ sock = server.socket('localhost',
+ tcp_keepalive=False,
+ tcp_keepcnt=keepcnt,
+ tcp_keepidle=keepidle,
+ tcp_keepintvl=keepintvl)
+
+ self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
+ socket.TCP_KEEPCNT), keepcnt)
+ self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
+ socket.TCP_KEEPIDLE), keepidle)
+ self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
+ socket.TCP_KEEPINTVL), keepintvl)