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_4_actual_httpd():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8081"]\ndef index(r):\n print 1')

    app = App(fn)
    assert urllib.urlopen('http://127.0.0.1:8081/').read().strip() == '1'
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8081/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError:
        pass

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8083"]\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8083/').read().strip() == '1'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8082"]\ndef index(r):\n print 2')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8082/').read().strip() == '2'

    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8082/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError:
        pass
Exemplo n.º 4
0
def run_tests_7_syntax_errors():
    fn = 'tests/generated.py'

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    helpers.set_file(fn,
                     'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1..')
    txt = urllib.urlopen('http://127.0.0.1:8090/').read()
    assert 'SyntaxError' in txt

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    assert urllib.urlopen('http://127.0.0.1:8090/').read().strip() == '1'

    app.stop()

    helpers.set_file(fn,
                     'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1..')
    app = App(fn)
    app.set_reload_intervals(-1)
    try:
        txt = urllib.urlopen('http://127.0.0.1:8091/').read()
        raise Exception('Server started when it shouldn\'t have been.')
    except IOError:
        pass

    helpers.set_file(fn, 'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8091/').read().strip() == '1'

    app.stop()
Exemplo n.º 5
0
def run_tests_7_syntax_errors():
    fn = 'tests/generated.py'

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1..')
    txt = urllib.urlopen('http://127.0.0.1:8090/').read()
    assert 'SyntaxError' in txt

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    assert urllib.urlopen('http://127.0.0.1:8090/').read().strip() == '1'

    app.stop()

    helpers.set_file(fn, 'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1..')
    app = App(fn)
    app.set_reload_intervals(-1)
    try:
        txt = urllib.urlopen('http://127.0.0.1:8091/').read()
        raise Exception('Server started when it shouldn\'t have been.')
    except IOError:
        pass

    helpers.set_file(fn, 'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8091/').read().strip() == '1'

    app.stop()
Exemplo n.º 6
0
def run_tests_4_actual_httpd():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8081"]\ndef index(r):\n print 1')

    app = App(fn)
    assert urllib.urlopen('http://127.0.0.1:8081/').read().strip() == '1'
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8081/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError: 
        pass

   
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8083"]\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8083/').read().strip() == '1'
    
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8082"]\ndef index(r):\n print 2')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8082/').read().strip() == '2'
    
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8082/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError: 
        pass
Exemplo n.º 7
0
def pipe_reset(data):
	log.info('MAIN: Reset requested')
	# stop mesh network and application
	try:
		app.stop()
		mesh.stop()
	except Exception, e:
		log.warning('MAIN: ' + str(e))
Exemplo n.º 8
0
def run_tests_2_reloading():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'def index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    assert run_wsgi_test(app) == '1\n'
    helpers.set_file(fn, 'def index(r):\n print 2')
    assert run_wsgi_test(app) == '2\n'
    app.stop()
Exemplo n.º 9
0
def run_tests_2_reloading():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'def index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    assert run_wsgi_test(app) == '1\n'
    helpers.set_file(fn, 'def index(r):\n print 2')
    assert run_wsgi_test(app) == '2\n'
    app.stop()
Exemplo n.º 10
0
def run_tests_1():
    app = App('tests/test_1_app.py')
    assert app.procs[0].hosts == ['127.0.0.1:8081']
    assert not app.syntax_error()
    assert run_wsgi_test(app) == 'RAN INDEX\n'
    app.stop()
    try:
        run_wsgi_test(app)
        raise Exception('Should have raised Exception about no processes')
    except:
        pass

    app = App('tests/test_syntax_error.py')
    assert app.syntax_error()
    app.stop()
Exemplo n.º 11
0
def run_tests_1():
    app = App('tests/test_1_app.py')
    assert app.procs[0].hosts == ['127.0.0.1:8081']
    assert not app.syntax_error()
    assert run_wsgi_test(app) == 'RAN INDEX\n'
    app.stop()
    try:
        run_wsgi_test(app)
        raise Exception('Should have raised Exception about no processes')
    except:
        pass

    app = App('tests/test_syntax_error.py')
    assert app.syntax_error()
    app.stop()
Exemplo n.º 12
0
def run_tests_6_back_to_same_host():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8113"]\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    #app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8113/').read().strip() == '1'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8112"]\ndef index(r):\n print 2')
    time.sleep(2)  #app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8112/').read().strip() == '2'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8113"]\ndef index(r):\n print 3')
    time.sleep(2)  #app.force_hosts_check()
    try:
        assert urllib.urlopen('http://127.0.0.1:8113/').read().strip() == '3'
    finally:
        app.stop()
Exemplo n.º 13
0
def run_tests_6_back_to_same_host():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8113"]\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    #app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8113/').read().strip() == '1'
   
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8112"]\ndef index(r):\n print 2')
    time.sleep(2) #app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8112/').read().strip() == '2'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8113"]\ndef index(r):\n print 3')
    time.sleep(2) #app.force_hosts_check()
    try:
        assert urllib.urlopen('http://127.0.0.1:8113/').read().strip() == '3'
    finally:
        app.stop()
Exemplo n.º 14
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.º 15
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.º 16
0
def get_readings_history():
    return jsonify({ 'history': strategy.history })

@web.route("/settings", methods=['GET'])
def get_settings():
    return jsonify(on=strategy.on,
        threshold_humidity=strategy.conf['threshold_humidity'],
        threshold_temperature=strategy.conf['threshold_temperature'],
        max_temperature=strategy.conf['max_temperature'],
        history_length=strategy.conf['history_length'])

@web.route("/settings", methods=['PATCH'])
def set_settings():
    if request.json['threshold_humidity']:
        strategy.conf['threshold_humidity'] = request.json['threshold_humidity']
    if request.json['threshold_temperature']:
        strategy.conf['threshold_temperature'] = request.json['threshold_temperature']
    if request.json['max_temperature']:
        strategy.conf['max_temperature'] = request.json['max_temperature']
    if request.json['history_length']:
        strategy.conf['history_length'] = request.json['history_length']
    update()
    return '', 204

if __name__ == "__main__":
    threading.Thread(target=run).start()
    try:
        web.run(host='0.0.0.0', port=80)
    finally:
        stop()
Exemplo n.º 17
0
def pipe_stopapp(data):
	log.info('MAIN: Application stop requested')
	try:
		app.stop()
	except Exception, e:
		log.warning('APP: ' + str(e))
Exemplo n.º 18
0
    return jsonify(
        on=strategy.on,
        threshold_humidity=strategy.conf['threshold_humidity'],
        threshold_temperature=strategy.conf['threshold_temperature'],
        max_temperature=strategy.conf['max_temperature'],
        history_length=strategy.conf['history_length'])


@web.route("/settings", methods=['PATCH'])
def set_settings():
    if request.json['threshold_humidity']:
        strategy.conf['threshold_humidity'] = request.json[
            'threshold_humidity']
    if request.json['threshold_temperature']:
        strategy.conf['threshold_temperature'] = request.json[
            'threshold_temperature']
    if request.json['max_temperature']:
        strategy.conf['max_temperature'] = request.json['max_temperature']
    if request.json['history_length']:
        strategy.conf['history_length'] = request.json['history_length']
    update()
    return '', 204


if __name__ == "__main__":
    threading.Thread(target=run).start()
    try:
        web.run(host='0.0.0.0', port=80)
    finally:
        stop()
Exemplo n.º 19
0
	# start mesh network
	mesh.start()

	# register pipes
	mesh.net_add_pipe('update', pipe_update)
	mesh.net_add_pipe('startapp', pipe_startapp)
	mesh.net_add_pipe('stopapp', pipe_stopapp)
	mesh.net_add_pipe('reset', pipe_reset)

	# execute application
	try:
		app.start()
	except Exception, e:
		log.warning('APP: ' + str(e))

	# infinite loop
	try:
		while True:
			pass
	except KeyboardInterrupt:
		pass

	# stop everything
	try:
		app.stop()
		mesh.stop()
	except Exception, e:
		log.warning('MAIN: ' + str(e))

if __name__ == '__main__':
	main()
Exemplo n.º 20
0
 'longclick':
 lambda dev, observer, env, attr: longclick(dev, attr['x'], attr['y']),
 'back':
 lambda dev, observer, env, attr: back(dev),
 'enter':
 lambda dev, observer, env, attr: enter(dev),
 'home':
 lambda dev, observer, env, attr: home(dev),
 'swipe':
 lambda dev, observer, env, attr: swipe(dev, attr['x1'], attr['y1'], attr[
     'x2'], attr['y2']),
 # app
 'start':
 lambda dev, observer, env, attr: app.start(dev, attr['name']),
 'stop':
 lambda dev, observer, env, attr: app.stop(dev, attr['name']),
 'clear':
 lambda dev, observer, env, attr: app.clear(dev, attr['name']),
 'waitact':
 lambda dev, observer, env, attr: app.waitact(dev, attr['name']),
 'wait':
 lambda dev, observer, env, attr: wait(dev, attr['time']),
 'waitfor':
 lambda dev, observer, env, attr: waitfor(dev, attr['method'], attr[
     'value'], observer, env),
 'waitready':
 lambda dev, observer, env, attr: waitready(dev, observer),
 'waitidle':
 lambda dev, observer, env, attr: waitidle(dev),
 'seetext':
 lambda dev, observer, env, attr: seetext(dev, attr['str'], observer),
Exemplo n.º 21
0
    for threadId, stack in sys._current_frames().items():
        code.append("\n# ThreadName: %s ThreadID: %s" %
                    (threadNames[threadId], threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' %
                        (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))

    for line in code:
        print >> sys.stderr, line
    print >> sys.stderr, "\n*** STACKTRACE - END ***\n"


app.run(host="0.0.0.0",
        port=4999,
        debug=True,
        use_reloader=False,
        threaded=True)

appmodule.stop()

# wait for everything to shut down
time.sleep(1)

# as long as more than one thread is running
while threading.activeCount() > 1:
    # display stack trace every 10 seconds
    strackTrace()
    time.sleep(10)