Exemplo n.º 1
0
def run_tests_3_procs():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'import os\ndef index(r):\n print os.getpid()')
    app = App(fn)

    app.add_proc()
    pids = set([])
    for _ in range(20):
        pids.add(run_wsgi_test(app))
    assert len(pids) == 2

    app.del_proc()
    pids = set([])
    for _ in range(20):
        pids.add(run_wsgi_test(app))
    assert len(pids) == 1

    app.del_proc()
    try:
        run_wsgi_test(app)
        raise Exception('Should have raised Exception about no processes')
    except:
        pass

    app.stop()

    # crash process and auto-recover

    fn = 'tests/generated.py'
    helpers.set_file(fn, 'import sys\ndef index(r):\n print "crash-recovered"')
    app = App(fn)
    app.procs[0].chan.send_cmd('crash')
    assert 'crash-recovered' in run_wsgi_test(app)
    app.stop()
Exemplo n.º 2
0
def run_tests_3_procs():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'import os\ndef index(r):\n print os.getpid()')
    app = App(fn)

    app.add_proc()
    pids = set([])
    for _ in range(20):
        pids.add(run_wsgi_test(app))
    assert len(pids) == 2
    
    app.del_proc()
    pids = set([])
    for _ in range(20):
        pids.add(run_wsgi_test(app))
    assert len(pids) == 1

    app.del_proc()
    try:
        run_wsgi_test(app)
        raise Exception('Should have raised Exception about no processes')
    except:
        pass
    
    app.stop()

    # crash process and auto-recover
    
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'import sys\ndef index(r):\n print "crash-recovered"')
    app = App(fn)
    app.procs[0].chan.send_cmd('crash')
    assert 'crash-recovered' in run_wsgi_test(app)
    app.stop()
Exemplo n.º 3
0
def run_tests_5_actual_httpd_multiprocess():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 1')
    app = App(fn)
    app.add_proc()
    app.add_proc()
    app.add_proc()
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '1'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 2')
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '2'

    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8085/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError:
        pass
Exemplo n.º 4
0
def run_tests_5_actual_httpd_multiprocess():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 1')
    app = App(fn)
    app.add_proc()
    app.add_proc()
    app.add_proc()
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '1'
    
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 2')
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '2'
    
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8085/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError: 
        pass