Skip to content
Snippets Groups Projects
Commit fbfaace4 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Print how fast sunet and funet are to respond. Handle timeout errors,

since they are sometimes very slow.
parent ad027b8e
No related branches found
No related tags found
No related merge requests found
...@@ -6,10 +6,14 @@ ...@@ -6,10 +6,14 @@
# #
# This also tests the expect_after functionality. # This also tests the expect_after functionality.
import sys
import time
import pcl_expect import pcl_expect
pcl_expect.stty_init = "-onlcr -ocrnl -echo" pcl_expect.stty_init = "-onlcr -ocrnl -echo"
time0 = time.time()
funet = pcl_expect.spawn("ftp ftp.funet.fi") funet = pcl_expect.spawn("ftp ftp.funet.fi")
sunet = pcl_expect.spawn("ftp ftp.sunet.se") sunet = pcl_expect.spawn("ftp ftp.sunet.se")
...@@ -25,6 +29,8 @@ cmds = {} ...@@ -25,6 +29,8 @@ cmds = {}
cmds[funet] = ["cd pub\n", "passive\n", "dir\n"] cmds[funet] = ["cd pub\n", "passive\n", "dir\n"]
cmds[sunet] = ["cd pub\n", "passive\n", "dir\n"] cmds[sunet] = ["cd pub\n", "passive\n", "dir\n"]
speed = {}
printed = 0 printed = 0
def prompt_cb(ftp): def prompt_cb(ftp):
global printed global printed
...@@ -35,6 +41,7 @@ def prompt_cb(ftp): ...@@ -35,6 +41,7 @@ def prompt_cb(ftp):
else: else:
print ftp.match.group() print ftp.match.group()
printed += 1 printed += 1
speed[ftp] = time.time() - time0
pcl_expect.debug("STATE: cmds[sunet] = %s\n" % cmds[sunet]) pcl_expect.debug("STATE: cmds[sunet] = %s\n" % cmds[sunet])
pcl_expect.debug("STATE: cmds[funet] = %s\n" % cmds[funet]) pcl_expect.debug("STATE: cmds[funet] = %s\n" % cmds[funet])
...@@ -51,7 +58,11 @@ pcl_expect.expect_after([(pcl_expect.RE, funet, "Name.*:", name_cb), ...@@ -51,7 +58,11 @@ pcl_expect.expect_after([(pcl_expect.RE, funet, "Name.*:", name_cb),
x = pcl_expect.impl() x = pcl_expect.impl()
while x.loop(): while x.loop():
pass if x.timeout():
sys.stdout.write(".")
sys.stdout.flush()
x.cont()
continue
sunet.send("bye\n") sunet.send("bye\n")
funet.send("bye\n") funet.send("bye\n")
...@@ -63,9 +74,22 @@ while x.loop(): ...@@ -63,9 +74,22 @@ while x.loop():
if x.eof(sunet): if x.eof(sunet):
print "SUNET final output:", sunet.match print "SUNET final output:", sunet.match
sunet.close() sunet.close()
elif x.timeout():
sys.stdout.write(".")
sys.stdout.flush()
x.cont()
continue
x = pcl_expect.impl() x = pcl_expect.impl()
while x.loop(): while x.loop():
if x.eof(funet): if x.eof(funet):
print "FUNET final output:", funet.match print "FUNET final output:", funet.match
funet.close() funet.close()
elif x.timeout():
sys.stdout.write(".")
sys.stdout.flush()
x.cont()
continue
print "SUNET time:", speed[sunet], "seconds"
print "FUNET time:", speed[funet], "seconds"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment