File: testworkers.py

package info (click to toggle)
uwsgi 2.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,564 kB
  • sloc: ansic: 87,066; python: 7,004; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 148; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (29 lines) | stat: -rw-r--r-- 881 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Regression test for #2056 - uwsgi.workers() leaking objects.
"""
import uwsgi
import gc


def application(env, start_response):
    gc.collect()
    start_objs = len(gc.get_objects())

    for i in range(200):
        workers = uwsgi.workers()
        assert workers, "none/empty uwsgi.workers() - " + repr(workers)
        for w in workers:
            assert w["apps"], "none/empty apps in worker dict: " + repr(w)

    gc.collect()
    end_objs = len(gc.get_objects())
    diff_objs = end_objs - start_objs

    # Sometimes there is a spurious diff of 4 objects or so.
    if diff_objs > 10:
        start_response('500 Leaking', [('Content-Type', 'text/plain')])
        yield "Leaking objects...\n".encode("utf-8")
    else:
        start_response('200 OK', [('Content-Type', 'text/plain')])

    yield "{} {} {}\n".format(start_objs, end_objs, diff_objs).encode("utf-8")