mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
test: Remove nc.py
The nc.py script is only used in a single test, and for waiting for a TCP port to be opened for listening. This patch replaces it entirely, by using chamuyero for the test, and bash for waiting on a TCP port.
This commit is contained in:
@@ -61,10 +61,6 @@ function smtpc.py() {
|
||||
${UTILDIR}/smtpc.py "$@"
|
||||
}
|
||||
|
||||
function nc.py() {
|
||||
${UTILDIR}/nc.py "$@"
|
||||
}
|
||||
|
||||
function mail_diff() {
|
||||
${UTILDIR}/mail_diff "$@"
|
||||
}
|
||||
@@ -91,7 +87,7 @@ function fail() {
|
||||
function wait_until_ready() {
|
||||
PORT=$1
|
||||
|
||||
while ! nc.py -z localhost $PORT; do
|
||||
while ! bash -c "true < /dev/tcp/localhost/$PORT" 2>/dev/null ; do
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Simple "netcat" implementation.
|
||||
# Unfortunately netcat/nc is not that portable, so this contains a simple
|
||||
# implementation which fits our needs.
|
||||
|
||||
import argparse
|
||||
import threading
|
||||
import smtplib
|
||||
import socket
|
||||
import sys
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("-z", action='store_true', help="scan for listening daemons")
|
||||
ap.add_argument("host", help="host to connect to")
|
||||
ap.add_argument("port", type=int, help="port to connect to")
|
||||
args = ap.parse_args()
|
||||
|
||||
address = (args.host, args.port)
|
||||
|
||||
try:
|
||||
sock = socket.create_connection(address)
|
||||
fd = sock.makefile('rw', buffering=1, encoding="utf-8")
|
||||
except OSError:
|
||||
# Exit quietly, like nc does.
|
||||
sys.exit(1)
|
||||
|
||||
if args.z:
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
# stdin -> socket in the background. Do a partial shutdown when done.
|
||||
def stdin_to_sock():
|
||||
for line in sys.stdin:
|
||||
fd.write(line)
|
||||
fd.flush()
|
||||
|
||||
try:
|
||||
sock.shutdown(socket.SHUT_WR)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
t1 = threading.Thread(target=stdin_to_sock, daemon=True)
|
||||
t1.start()
|
||||
|
||||
# socket -> stdout in the foreground; if the socket closes, exit.
|
||||
for line in fd:
|
||||
sys.stdout.write(line)
|
||||
sys.stdout.flush()
|
||||
|
||||
Reference in New Issue
Block a user