mirror of
https://github.com/mirror/wget.git
synced 2024-12-28 05:40:08 +08:00
Extend Functionality to support spawning multiple servers
This commit is contained in:
parent
e84192a8d3
commit
8b1a9b6de7
@ -1,3 +1,20 @@
|
||||
2013-09-11 Darshit Shah <darnir@gmail.com>
|
||||
|
||||
* WgetTest.py (CommonMethods.exec_wget): Expect domain_list instead of
|
||||
domain.
|
||||
(CommonMethods.get_cmd_line): Same. Generate command line by
|
||||
prepending to each file it's respective domain string
|
||||
(CommonMethods.ServerFiles): Generate file_list and server_rules for
|
||||
each Server and set the config details
|
||||
(HTTPTest): New named parameter, servers which signifies number of
|
||||
servers to spawn
|
||||
(HTTPTest.HTTP_setup): This method now takes servers as a new
|
||||
parameter. Instead of storing server and domain, we now store
|
||||
server_list and domain_list. Each server must be initialized through a
|
||||
loop.
|
||||
(HTTPTest.stop_HTTP_server): Stop all servers in a loop.
|
||||
* Test-Parallel-Proto.py: Prototype test file for multiple servers.
|
||||
|
||||
2013-09-10 Darshit Shah <darnir@gmail.com>
|
||||
|
||||
* WgetTest.py (HTTPTest.stop_HTTP_server): With the threaded servers,
|
||||
|
52
testenv/Test-Parallel-Proto.py
Executable file
52
testenv/Test-Parallel-Proto.py
Executable file
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
from sys import exit
|
||||
from WgetTest import HTTPTest, WgetFile
|
||||
|
||||
"""
|
||||
This is a Prototype Test File for multiple servers.
|
||||
Ideally this File should be copied and edited to write new tests.
|
||||
"""
|
||||
TEST_NAME = "Parallel Prototype"
|
||||
############# File Definitions ###############################################
|
||||
File1 = "Would you like some Tea?"
|
||||
File2 = "With lemon or cream?"
|
||||
File3 = "Sure you're joking Mr. Feynman"
|
||||
|
||||
A_File = WgetFile ("File1", File1)
|
||||
B_File = WgetFile ("File2", File2)
|
||||
C_File = WgetFile ("File3", File3)
|
||||
|
||||
WGET_OPTIONS = "-d"
|
||||
WGET_URLS = [["File1"], ["File2"]]
|
||||
|
||||
Files = [[A_File], [B_File]]
|
||||
Existing_Files = [C_File]
|
||||
|
||||
no_of_servers = 2
|
||||
|
||||
ExpectedReturnCode = 0
|
||||
ExpectedDownloadedFiles = [A_File, B_File, C_File]
|
||||
|
||||
################ Pre and Post Test Hooks #####################################
|
||||
pre_test = {
|
||||
"ServerFiles" : Files,
|
||||
"LocalFiles" : Existing_Files
|
||||
}
|
||||
test_options = {
|
||||
"WgetCommands" : WGET_OPTIONS,
|
||||
"Urls" : WGET_URLS
|
||||
}
|
||||
post_test = {
|
||||
"ExpectedFiles" : ExpectedDownloadedFiles,
|
||||
"ExpectedRetcode" : ExpectedReturnCode
|
||||
}
|
||||
|
||||
err = HTTPTest (
|
||||
name=TEST_NAME,
|
||||
pre_hook=pre_test,
|
||||
test_params=test_options,
|
||||
post_hook=post_test,
|
||||
servers=no_of_servers
|
||||
).begin ()
|
||||
|
||||
exit (err)
|
@ -36,19 +36,23 @@ class CommonMethods:
|
||||
self.port = str (addr[1])
|
||||
return addr[0] + ":" + str(addr[1]) + "/"
|
||||
|
||||
def exec_wget (self, options, urls, domain):
|
||||
cmd_line = self.get_cmd_line (options, urls, domain)
|
||||
def exec_wget (self, options, urls, domain_list):
|
||||
cmd_line = self.get_cmd_line (options, urls, domain_list)
|
||||
params = shlex.split (cmd_line)
|
||||
print (params)
|
||||
retcode = call (params)
|
||||
return retcode
|
||||
|
||||
def get_cmd_line (self, options, urls, domain):
|
||||
def get_cmd_line (self, options, urls, domain_list):
|
||||
TEST_PATH = os.path.abspath (".")
|
||||
WGET_PATH = os.path.join (TEST_PATH, "..", "..", "src", "wget")
|
||||
WGET_PATH = os.path.abspath (WGET_PATH)
|
||||
cmd_line = WGET_PATH + " " + options + " "
|
||||
for url in urls:
|
||||
cmd_line += domain + url + " "
|
||||
for i in range (0, self.servers):
|
||||
for url in urls[i]:
|
||||
cmd_line += domain_list[i] + url + " "
|
||||
# for url in urls:
|
||||
# cmd_line += domain_list[0] + url + " "
|
||||
print (cmd_line)
|
||||
return cmd_line
|
||||
|
||||
@ -144,13 +148,14 @@ class CommonMethods:
|
||||
""" Pre-Test Hook Function Calls """
|
||||
|
||||
def ServerFiles (self, server_files):
|
||||
file_list = dict ()
|
||||
server_rules = dict ()
|
||||
for file_obj in server_files:
|
||||
file_list[file_obj.name] = file_obj.content
|
||||
rule_obj = self.get_server_rules (file_obj)
|
||||
server_rules[file_obj.name] = rule_obj
|
||||
self.server.server_conf (file_list, server_rules)
|
||||
for i in range (0, self.servers):
|
||||
file_list = dict ()
|
||||
server_rules = dict ()
|
||||
for file_obj in server_files[i]:
|
||||
file_list[file_obj.name] = file_obj.content
|
||||
rule_obj = self.get_server_rules (file_obj)
|
||||
server_rules[file_obj.name] = rule_obj
|
||||
self.server_list[i].server_conf (file_list, server_rules)
|
||||
|
||||
|
||||
def LocalFiles (self, local_files):
|
||||
@ -197,10 +202,11 @@ class HTTPTest (CommonMethods):
|
||||
name="Unnamed Test",
|
||||
pre_hook=dict(),
|
||||
test_params=dict(),
|
||||
post_hook=dict()
|
||||
post_hook=dict(),
|
||||
servers=1
|
||||
):
|
||||
try:
|
||||
self.HTTP_setup (name, pre_hook, test_params, post_hook)
|
||||
self.HTTP_setup (name, pre_hook, test_params, post_hook, servers)
|
||||
except TestFailed as tf:
|
||||
printer ("RED", "Error: " + tf.error)
|
||||
self.tests_passed = False
|
||||
@ -213,12 +219,20 @@ class HTTPTest (CommonMethods):
|
||||
printer ("GREEN", "Test Passed")
|
||||
finally:
|
||||
self._exit_test ()
|
||||
def HTTP_setup (self, name, pre_hook, test_params, post_hook):
|
||||
def HTTP_setup (self, name, pre_hook, test_params, post_hook, servers):
|
||||
self.name = name
|
||||
self.servers = servers
|
||||
printer ("BLUE", "Running Test " + self.name)
|
||||
self.init_test_env (name)
|
||||
self.server = self.init_HTTP_Server ()
|
||||
self.domain = self.get_domain_addr (self.server.server_address)
|
||||
self.server_list = list()
|
||||
self.domain_list = list()
|
||||
for server_number in range (0, servers):
|
||||
server_inst = self.init_HTTP_Server ()
|
||||
self.server_list.append (server_inst)
|
||||
domain = self.get_domain_addr (server_inst.server_address)
|
||||
self.domain_list.append (domain)
|
||||
#self.server = self.init_HTTP_Server ()
|
||||
#self.domain = self.get_domain_addr (self.server.server_address)
|
||||
|
||||
for pre_hook_func in pre_hook:
|
||||
try:
|
||||
@ -236,8 +250,7 @@ class HTTPTest (CommonMethods):
|
||||
raise TestFailed ("Test Option " + test_func + " unknown.")
|
||||
getattr (self, test_func) (test_params[test_func])
|
||||
|
||||
|
||||
self.act_retcode = self.exec_wget (self.options, self.urls, self.domain)
|
||||
self.act_retcode = self.exec_wget (self.options, self.urls, self.domain_list)
|
||||
self.stop_HTTP_Server ()
|
||||
|
||||
for post_hook_func in post_hook:
|
||||
@ -253,7 +266,8 @@ class HTTPTest (CommonMethods):
|
||||
return server
|
||||
|
||||
def stop_HTTP_Server (self):
|
||||
self.server.server_inst.shutdown ()
|
||||
for server in self.server_list:
|
||||
server.server_inst.shutdown ()
|
||||
|
||||
""" WgetFile is a File Data Container object """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user