Esempio n. 1
0
def setup_module(module):
    global async_server
    async_server = WheatServer(
        "", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--timeout-seconds 3", "--stat-refresh-time 1", "--protocol Http")
    time.sleep(0.5)
Esempio n. 2
0
def test_document_root_and_static_file_dir():
    async = WheatServer(
        "", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--document-root %s" % PROJECT_PATH + "/example/",
        "--static-file-dir %s" % "/static", "--allowed-extension bmp,gif,jpg",
        "--protocol Http")
    time.sleep(0.1)
    r = requests.get("http://127.0.0.1:10828/static/example.jpg", timeout=1)
    assert 200 == r.status_code
Esempio n. 3
0
def test_allowed_extension():
    async_server = WheatServer(
        "", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--document-root %s" % os.path.join(PROJECT_PATH, "example/"),
        "--allowed-extension bmp,gif", "--protocol Http")
    time.sleep(0.5)
    conn = httplib.HTTPConnection("127.0.0.1", 10828, timeout=10)
    conn.request("GET", "/static/example.jpg")
    r1 = conn.getresponse()
    assert r1.status == 404
Esempio n. 4
0
def test_reload():
    async_server = WheatServer(
        "reload.conf", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--protocol Http")
    time.sleep(1)
    os.kill(async_server.exec_pid, signal.SIGHUP)
    s = server_socket(10829)

    s.send(construct_command("stat", "master"))
    assert "Total spawn workers: 8" in s.recv(1000)
Esempio n. 5
0
def test_get_two():
    async = WheatServer(
        "", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--document-root %s" % os.path.join(PROJECT_PATH, "example/"),
        "--allowed-extension bmp,gif", "--protocol Http")
    time.sleep(0.1)
    s = server_socket(10828)
    s.send("GET / HTTP/1.1\r\nHOST: 127.0.0.1:10828\r\nConnec")
    time.sleep(0.2)
    s.send("tion: close\r\n\r\n")
    a = s.recv(100)
    assert "200" in a
Esempio n. 6
0
def test_redis():
    async = WheatServer(
        "", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--document-root %s" % PROJECT_PATH + "/example/",
        "--static-file-dir %s" % "/static", "--protocol Redis")
    time.sleep(0.1)
    r = redis.StrictRedis(port=10828)
    for i in range(100):
        time.sleep(0.001)
        assert r.set(str(i), i)
    for i in range(100):
        time.sleep(0.001)
        assert r.get(str(i)) == str(i)

    assert r.get('z') == None
Esempio n. 7
0
def test_post_file():
    async = WheatServer(
        "", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--document-root %s" % os.path.join(PROJECT_PATH, "example/"),
        "--allowed-extension bmp,gif", "--protocol Http")
    time.sleep(0.1)
    s = server_socket(10828)
    s.settimeout(0.5)
    s.send(POST_DATA[:302])
    time.sleep(0.1)
    try:
        a = s.recv(100)
    except:
        pass
    else:
        assert "" == a
    s.send(POST_DATA[302:])
    a = s.recv(1000)
    assert "200" in a and "1234" in a
Esempio n. 8
0
def test_redis_conf():
    redis1 = RedisServer("", "--port 18000")
    redis2 = RedisServer("", "--port 18001")
    async = WheatServer(
        "redis.conf", "--worker-type %s" % "AsyncWorker",
        "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
        "--document-root %s" % PROJECT_PATH + "/example/",
        "--static-file-dir %s" % "/static", "--protocol Redis",
        "--config-source RedisThenFile", "--config-server 127.0.0.1:18000",
        "--logfile test_redis_conf.log")
    time.sleep(0.1)
    r = redis.StrictRedis(port=10828)
    assert r.set(1, 1)
    assert r.get(1) == '1'
    f = open("test_redis_conf.log")
    content = f.read(10000)
    f.close()
    assert "get config from redis failed" in content
    assert "get config from file successful" in content
    assert "Save config to redis success" in content
    del async
Esempio n. 9
0
 time.sleep(0.1)
 r = redis.StrictRedis(port=10828)
 assert r.set(1, 1)
 assert r.get(1) == '1'
 f = open("test_redis_conf.log")
 content = f.read(10000)
 f.close()
 assert "get config from redis failed" in content
 assert "get config from file successful" in content
 assert "Save config to redis success" in content
 del async
 os.unlink("test_redis_conf.log")
 async = WheatServer(
     "redis.conf", "--worker-type %s" % "AsyncWorker",
     "--app-project-path %s" % os.path.join(PROJECT_PATH, "example"),
     "--document-root %s" % PROJECT_PATH + "/example/",
     "--static-file-dir %s" % "/static", "--protocol Redis",
     "--config-source RedisThenFile", "--config-server 127.0.0.1:18000",
     "--logfile test_redis_conf1.log", "--port 10826", "--stat-port 10827")
 time.sleep(0.1)
 r = redis.StrictRedis(port=10826)
 assert r.get(1) == '1'
 f = open("test_redis_conf1.log")
 content = f.read(10000)
 f.close()
 assert "get config from redis server sucessful" in content
 assert "Save config to redis success" not in content
 os.unlink("test_redis_conf1.log")
 del async
 async = WheatServer(
     "redis.conf", "--worker-type %s" % "AsyncWorker",