~hudson-openstack/burrow/trunk

« back to all changes in this revision

Viewing changes to test/backend/test_http.py

  • Committer: Tarmac
  • Author(s): Eric Day
  • Date: 2011-08-24 20:23:03 UTC
  • mfrom: (33.1.7 doc-updates)
  • Revision ID: tarmac-20110824202303-fc09r0aendi1tn6m
Added client API unit tests, moved exceptions to main burrow module, and added more WSGI frontend tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
'''Unittests for the HTTP backend. This starts the WSGI server so
16
16
tests the WSGI frontend as well.'''
17
17
 
18
 
import atexit
19
18
import ConfigParser
20
 
import os
21
 
import signal
22
 
import sys
23
 
import time
24
19
 
25
20
import burrow.backend.http
26
21
import test.backend
53
48
class TestHTTPMessage(HTTPBase, test.backend.TestMessage):
54
49
    '''Test case for message with http backend.'''
55
50
    pass
56
 
 
57
 
 
58
 
def start_server():
59
 
    '''Fork and start the server, saving the pid in a file.'''
60
 
    kill_server()
61
 
    pid = os.fork()
62
 
    if pid == 0:
63
 
        try:
64
 
            import coverage
65
 
            cov = coverage.coverage(data_suffix=True)
66
 
            cov.start()
67
 
 
68
 
            def save_coverage(_signum, _frame):
69
 
                '''Callback for signal to save coverage info to file.'''
70
 
                cov.save()
71
 
 
72
 
            signal.signal(signal.SIGUSR1, save_coverage)
73
 
        except ImportError:
74
 
            pass
75
 
        server = burrow.Server(add_default_log_handler=False)
76
 
        server.frontends[0].default_ttl = 0
77
 
        server.run()
78
 
        sys.exit(0)
79
 
    pid_file = open('TestHTTP.pid', 'w')
80
 
    pid_file.write(str(pid))
81
 
    pid_file.close()
82
 
    atexit.register(kill_server)
83
 
    time.sleep(1)
84
 
 
85
 
 
86
 
def kill_server():
87
 
    '''Try killing the server if the pid file exists.'''
88
 
    try:
89
 
        pid_file = open('TestHTTP.pid', 'r')
90
 
        pid = pid_file.read()
91
 
        pid_file.close()
92
 
        try:
93
 
            os.kill(int(pid), signal.SIGUSR1)
94
 
            time.sleep(1)
95
 
            os.kill(int(pid), signal.SIGTERM)
96
 
        except OSError:
97
 
            pass
98
 
        os.unlink('TestHTTP.pid')
99
 
    except IOError:
100
 
        pass
101
 
 
102
 
 
103
 
start_server()