Browse Source

test update

wangweimin 3 years ago
parent
commit
fe6254c55c
2 changed files with 9 additions and 28 deletions
  1. 9 22
      test/12.cors.py
  2. 0 6
      test/util.py

+ 9 - 22
test/12.cors.py

@@ -32,7 +32,6 @@ def test(server_proc: subprocess.Popen, browser: Chrome):
     raw_html = test_once(browser, '12.tornado_cors.html',
                          process_func=lambda i: i.replace('http://localhost:5000', 'http://localhost:8080'))
     assert 'http://localhost:5000' in raw_html  # origin
-    server_proc.send_signal(signal.SIGINT)
 
     time.sleep(4)
     browser.get('http://localhost:5000/?pywebio_api=http://localhost:8081/')
@@ -40,41 +39,29 @@ def test(server_proc: subprocess.Popen, browser: Chrome):
                          process_func=lambda i: i.replace('http://localhost:5000', 'http://localhost:8080').replace(
                              'localhost:8081', 'localhost:8080'))
     assert 'http://localhost:5000' in raw_html and 'localhost:8081' in raw_html  # origin
-    server_proc.send_signal(signal.SIGINT)
 
     time.sleep(4)
-    browser.get('http://localhost:5000/?pywebio_api=http://localhost:8082/')
+    browser.get('http://localhost:5001/?pywebio_api=http://localhost:8082/')
     raw_html = test_once(browser, '12.flask_cors.html',
-                         process_func=lambda i: i.replace('http://localhost:5000', 'http://localhost:8080').replace(
+                         process_func=lambda i: i.replace('http://localhost:5001', 'http://localhost:8080').replace(
                              'localhost:8082', 'localhost:8080'))
-    assert 'http://localhost:5000' in raw_html and 'localhost:8082' in raw_html  # origin
+    assert 'http://localhost:5001' in raw_html and 'localhost:8082' in raw_html  # origin
 
 
 def start_test_server():
     from pywebio import start_server as tornado_server
     from pywebio.platform.flask import start_server as flask_server
     from pywebio.platform.aiohttp import start_server as aiohttp_server
-    import asyncio
-
-    util.start_static_server()
 
-    try:
-        tornado_server(target, port=8080, host='127.0.0.1', allowed_origins=['http://localhost:5000'], cdn=False)
-    except:
-        print('tornado_server exit')
+    import multiprocessing
 
-    loop = asyncio.new_event_loop()
-    asyncio.set_event_loop(loop)
+    multiprocessing.Process(target=lambda: tornado_server(lambda: None, port=5000, cdn=False), daemon=True).start()
+    multiprocessing.Process(target=lambda: flask_server(lambda: None, port=5001, cdn=False), daemon=True).start()
 
-    try:
-        aiohttp_server(target, port=8081, host='127.0.0.1', allowed_origins=['http://localhost:5000'], cdn=False)
-    except:
-        print('aiohttp_server exit')
+    multiprocessing.Process(target=lambda: tornado_server(target, port=8080, host='127.0.0.1', allowed_origins=['http://localhost:5000'], cdn=False), daemon=True).start()
+    multiprocessing.Process(target=lambda: aiohttp_server(target, port=8081, host='127.0.0.1', allowed_origins=['http://localhost:5000'], cdn=False), daemon=True).start()
+    flask_server(target, port=8082, host='127.0.0.1', allowed_origins=['http://localhost:5001'], cdn=False)
 
-    try:
-        flask_server(target, port=8082, host='127.0.0.1', allowed_origins=['http://localhost:5000'], cdn=False)
-    except:
-        print('flask_server exit')
 
 
 if __name__ == '__main__':

+ 0 - 6
test/util.py

@@ -76,9 +76,3 @@ def run_test(server_func, test_func, address='http://localhost:8080?_pywebio_deb
         proc.send_signal(signal.SIGINT)
         print("Closed browser and PyWebIO server")
 
-
-def start_static_server(port=5000):
-    from http.server import SimpleHTTPRequestHandler, test
-
-    handler_class = partial(SimpleHTTPRequestHandler, directory=STATIC_PATH)
-    threading.Thread(target=test, kwargs=dict(HandlerClass=handler_class, port=port, bind='localhost'), daemon=True).start()