def test_gunicorn_clears_context(): app = __name__ + ':counter_app' pr = GunicornProcess(app, args=['--worker-class=sync']) with pr: r1 = requests.get(pr.url('/')).json() r2 = requests.get(pr.url('/')).json() r3 = requests.get(pr.url('/')).json() assert r1['1'] == '1' assert r2['2'] == '2' assert '1' not in r2 assert r3['3'] == '3' assert '2' not in r3
def test_gunicorn_timeout(tmpdir): def test_app(): import time def app(environ, start_response): start_response('200 OK', [('content-type', 'text/plain')]) time.sleep(100) return [] app_module = str(tmpdir / 'app.py') with open(app_module, 'w') as f: f.write(get_function_body(test_app)) # ensure devel mode env = os.environ.copy() env['DEVEL'] = '1' p = GunicornProcess('app:app', args=['-t1'], cwd=str(tmpdir), env=env) with p: response = requests.get( p.url('/'), headers={ 'Accept': 'application/json' }, ).json() assert response['title'].startswith( 'RequestTimeout: gunicorn worker timeout (pid:')