Mercurial > vim
comparison src/testdir/test_channel.py @ 8114:4aea0b0aa714 v7.4.1351
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 18 22:23:34 2016 +0100
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().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 18 Feb 2016 22:30:08 +0100 |
parents | c6443e78cf2d |
children | 240deebfadde |
comparison
equal
deleted
inserted
replaced
8113:fd690d084aaf | 8114:4aea0b0aa714 |
---|---|
7 | 7 |
8 from __future__ import print_function | 8 from __future__ import print_function |
9 import json | 9 import json |
10 import socket | 10 import socket |
11 import sys | 11 import sys |
12 import time | |
12 import threading | 13 import threading |
13 | 14 |
14 try: | 15 try: |
15 # Python 3 | 16 # Python 3 |
16 import socketserver | 17 import socketserver |
156 last_eval = decoded | 157 last_eval = decoded |
157 | 158 |
158 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): | 159 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): |
159 pass | 160 pass |
160 | 161 |
162 def writePortInFile(port): | |
163 # Write the port number in Xportnr, so that the test knows it. | |
164 f = open("Xportnr", "w") | |
165 f.write("{}".format(port)) | |
166 f.close() | |
167 | |
161 if __name__ == "__main__": | 168 if __name__ == "__main__": |
162 HOST, PORT = "localhost", 0 | 169 HOST, PORT = "localhost", 0 |
170 | |
171 # Wait half a second before opening the port to test waittime in ch_open(). | |
172 # We do want to get the port number, get that first. We cannot open the | |
173 # socket, guess a port is free. | |
174 if len(sys.argv) >= 2 and sys.argv[1] == 'delay': | |
175 PORT = 13684 | |
176 writePortInFile(PORT) | |
177 | |
178 print("Wait for it...") | |
179 time.sleep(0.5) | |
163 | 180 |
164 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) | 181 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) |
165 ip, port = server.server_address | 182 ip, port = server.server_address |
166 | 183 |
167 # Start a thread with the server. That thread will then start a new thread | 184 # Start a thread with the server. That thread will then start a new thread |
168 # for each connection. | 185 # for each connection. |
169 server_thread = threading.Thread(target=server.serve_forever) | 186 server_thread = threading.Thread(target=server.serve_forever) |
170 server_thread.start() | 187 server_thread.start() |
171 | 188 |
172 # Write the port number in Xportnr, so that the test knows it. | 189 writePortInFile(port) |
173 f = open("Xportnr", "w") | |
174 f.write("{}".format(port)) | |
175 f.close() | |
176 | 190 |
177 print("Listening on port {}".format(port)) | 191 print("Listening on port {}".format(port)) |
178 | 192 |
179 # Main thread terminates, but the server continues running | 193 # Main thread terminates, but the server continues running |
180 # until server.shutdown() is called. | 194 # until server.shutdown() is called. |