Files
nginx-unit/test/test_python_atexit.py
Max Romanov 9cd4fdbdb7 Introducing extended app process management.
- Pre-fork 'processes.spare' application processes;
- fork more processes to keep 'processes.spare' idle processes;
- fork on-demand up to 'processes.max' count;
- scale down idle application processes above 'processes.spare' after
  'processes.idle_timeout';
- number of concurrently started application processes also limited by
  'processes.spare' (or 1, if spare is 0).
2018-01-29 16:17:36 +03:00

62 lines
1.3 KiB
Python

import os
import time
import unittest
import unit
class TestUnitApplication(unit.TestUnitControl):
def setUpClass():
u = unit.TestUnit()
u.check_modules('python')
u.check_version('0.3')
def test_python_application(self):
code, name = """
import atexit
def create_file():
open('%s', 'w')
atexit.register(create_file)
def application(env, start_response):
start_response('200', [('Content-Length', '0')])
return []
""" % (self.testdir + '/atexit'), 'py_app'
self.python_application(name, code)
self.conf({
"listeners": {
"*:7080": {
"application": "app"
}
},
"applications": {
"app": {
"type": "python",
"processes": { "spare": 0 },
"path": self.testdir + '/' + name,
"module": "wsgi"
}
}
})
self.get()
self.conf({
"listeners": {},
"applications": {}
})
time.sleep(0.2) # wait for 'atexit' file
self.assertEqual(os.path.exists(self.testdir + '/atexit'), True,
'python atexit')
if __name__ == '__main__':
unittest.main()