summaryrefslogtreecommitdiff
path: root/src/testdir/test_channel.py
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-18 22:23:34 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-18 22:23:34 +0100
commit81661fb86801e6d6e5194b43dfd27d73fcc016ec (patch)
tree7aa3fcc1a790e4b97c17a2515950ac4fdd1e436d /src/testdir/test_channel.py
parentec70bdd68a531762a62728747ab529d7a6dfc842 (diff)
downloadvim-git-81661fb86801e6d6e5194b43dfd27d73fcc016ec.tar.gz
patch 7.4.1351v7.4.1351
Problem: When the port isn't opened yet when ch_open() is called it may fail instead of waiting for the specified time. Solution: Loop when select() succeeds but when connect() failed. Also use channel logging for jobs. Add ch_log().
Diffstat (limited to 'src/testdir/test_channel.py')
-rw-r--r--src/testdir/test_channel.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/testdir/test_channel.py b/src/testdir/test_channel.py
index ce6d5c16d..ec231e8c8 100644
--- a/src/testdir/test_channel.py
+++ b/src/testdir/test_channel.py
@@ -9,6 +9,7 @@ from __future__ import print_function
import json
import socket
import sys
+import time
import threading
try:
@@ -158,9 +159,25 @@ class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
+def writePortInFile(port):
+ # Write the port number in Xportnr, so that the test knows it.
+ f = open("Xportnr", "w")
+ f.write("{}".format(port))
+ f.close()
+
if __name__ == "__main__":
HOST, PORT = "localhost", 0
+ # Wait half a second before opening the port to test waittime in ch_open().
+ # We do want to get the port number, get that first. We cannot open the
+ # socket, guess a port is free.
+ if len(sys.argv) >= 2 and sys.argv[1] == 'delay':
+ PORT = 13684
+ writePortInFile(PORT)
+
+ print("Wait for it...")
+ time.sleep(0.5)
+
server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
ip, port = server.server_address
@@ -169,10 +186,7 @@ if __name__ == "__main__":
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
- # Write the port number in Xportnr, so that the test knows it.
- f = open("Xportnr", "w")
- f.write("{}".format(port))
- f.close()
+ writePortInFile(port)
print("Listening on port {}".format(port))