From 81661fb86801e6d6e5194b43dfd27d73fcc016ec Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 18 Feb 2016 22:23:34 +0100 Subject: patch 7.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(). --- src/testdir/test_channel.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/testdir/test_channel.py') 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)) -- cgit v1.2.1