def test_nosigclean(self):
        # check that we can deactivate sigterm/sigint hooks
        pings = []

        def end():
            pings.append('app ends')

        subscribe(APP_ENDS, end)
        try:
            config = {
                'global.heartbeat_page': '__heartbeat__',
                'global.debug_page': '__debug__',
                'auth.backend': 'services.auth.dummy.DummyAuth',
                'global.clean_shutdown': False
            }

            urls = []
            controllers = {}
            app = SyncServerApp(urls,
                                controllers,
                                config,
                                auth_class=self.auth_class)

            # heartbeat should work
            request = make_request("/__heartbeat__")
            app(request)

        finally:
            unsubscribe(APP_ENDS, end)

        # and we should have had no ping
        self.assertEquals(pings, [])
    def test_events(self):

        pings = []

        def starts(request):
            pings.append('starts')

        def ends(response):
            pings.append('ends')

        subscribe(REQUEST_STARTS, starts)
        subscribe(REQUEST_ENDS, ends)
        try:
            config = {
                'global.heartbeat_page': '__heartbeat__',
                'global.debug_page': '__debug__',
                'auth.backend': 'services.auth.dummy.DummyAuth'
            }
            urls = []
            controllers = {}
            app = SyncServerApp(urls,
                                controllers,
                                config,
                                auth_class=self.auth_class)
            request = make_request("/user/__hearbeat__")
            app(request)
        finally:
            unsubscribe(REQUEST_STARTS, starts)
            unsubscribe(REQUEST_ENDS, ends)

        self.assertEquals(pings, ['starts', 'ends'])
Пример #3
0
    def test_nosigclean(self):
        # check that we can deactivate sigterm/sigint hooks
        pings = []

        def end():
            pings.append('app ends')

        subscribe(APP_ENDS, end)
        try:
            config = {'global.heartbeat_page': '__heartbeat__',
                      'global.debug_page': '__debug__',
                      'auth.backend': 'services.auth.dummy.DummyAuth',
                      'global.clean_shutdown': False}

            urls = []
            controllers = {}
            app = SyncServerApp(urls, controllers, config,
                                auth_class=self.auth_class)

            # heartbeat should work
            request = make_request("/__heartbeat__")
            app(request)

        finally:
            unsubscribe(APP_ENDS, end)

        # and we should have had no ping
        self.assertEquals(pings, [])
Пример #4
0
    def test_events(self):

        pings = []

        def starts(request):
            pings.append('starts')

        def ends(response):
            pings.append('ends')

        subscribe(REQUEST_STARTS, starts)
        subscribe(REQUEST_ENDS, ends)
        try:
            config = {'global.heartbeat_page': '__heartbeat__',
                      'global.debug_page': '__debug__',
                      'auth.backend': 'services.auth.dummy.DummyAuth'}
            urls = []
            controllers = {}
            app = SyncServerApp(urls, controllers, config,
                                auth_class=self.auth_class)
            request = make_request("/user/__hearbeat__")
            app(request)
        finally:
            unsubscribe(REQUEST_STARTS, starts)
            unsubscribe(REQUEST_ENDS, ends)

        self.assertEquals(pings, ['starts', 'ends'])
Пример #5
0
    def test_graceful_shutdown(self):

        pings = []

        def end():
            pings.append('app ends')

        subscribe(APP_ENDS, end)
        try:
            config = {'global.heartbeat_page': '__heartbeat__',
                      'global.debug_page': '__debug__',
                      'auth.backend': 'services.auth.dummy.DummyAuth',
                      'global.graceful_shutdown_interval': 1,
                      'global.hard_shutdown_interval': 1}

            urls = []
            controllers = {}
            app = SyncServerApp(urls, controllers, config,
                                auth_class=self.auth_class)

            # heartbeat should work
            request = make_request("/__heartbeat__")
            app(request)

            # let's "kill it" in a thread
            class Killer(threading.Thread):
                def __init__(self, app):
                    threading.Thread.__init__(self)
                    self.app = app

                def run(self):
                    self.app._sigterm(None, None)

            killer = Killer(app)
            killer.start()
            sleep(0.2)

            # in the meantime, /heartbeat should return a 503
            request = make_request("/__heartbeat__")
            self.assertRaises(HTTPServiceUnavailable, app, request)

            # but regular requests should still work
            request = make_request("/")
            app(request)

            # sleeping
            sleep(1.)

            # now / should 503 too
            request = make_request("/")
            self.assertRaises(HTTPServiceUnavailable, app, request)

            killer.join()

        finally:
            unsubscribe(APP_ENDS, end)

        # and we should have had a event ping
        self.assertEquals(pings, ['app ends'])
Пример #6
0
    def test_host_config(self):
        def alice(data):
            data.append('alice')

        def bob(data):
            data.append('bob')

        subscribe('yo', alice)
        subscribe('yo', bob)
        subscribe('yo', bob)  # will be ignored
        stuff = []

        notify('yo', stuff)
        self.assertEquals(stuff, ['alice', 'bob'])

        unsubscribe('yo', alice)
        notify('yo', stuff)
        self.assertEquals(stuff, ['alice', 'bob', 'bob'])
Пример #7
0
    def test_host_config(self):

        def alice(data):
            data.append('alice')

        def bob(data):
            data.append('bob')

        subscribe('yo', alice)
        subscribe('yo', bob)
        subscribe('yo', bob)   # will be ignored
        stuff = []

        notify('yo', stuff)
        self.assertEquals(stuff, ['alice', 'bob'])

        unsubscribe('yo', alice)
        notify('yo', stuff)
        self.assertEquals(stuff, ['alice', 'bob', 'bob'])
    def test_graceful_shutdown(self):

        pings = []

        def end():
            pings.append('app ends')

        subscribe(APP_ENDS, end)
        try:
            config = {
                'global.heartbeat_page': '__heartbeat__',
                'global.debug_page': '__debug__',
                'auth.backend': 'services.auth.dummy.DummyAuth',
                'global.graceful_shutdown_interval': 1,
                'global.hard_shutdown_interval': 1
            }

            urls = []
            controllers = {}
            app = SyncServerApp(urls,
                                controllers,
                                config,
                                auth_class=self.auth_class)

            # heartbeat should work
            request = make_request("/__heartbeat__")
            app(request)

            # let's "kill it" in a thread
            class Killer(threading.Thread):
                def __init__(self, app):
                    threading.Thread.__init__(self)
                    self.app = app

                def run(self):
                    self.app._sigterm(None, None)

            killer = Killer(app)
            killer.start()
            sleep(0.2)

            # in the meantime, /heartbeat should return a 503
            request = make_request("/__heartbeat__")
            self.assertRaises(HTTPServiceUnavailable, app, request)

            # but regular requests should still work
            request = make_request("/")
            app(request)

            # sleeping
            sleep(1.)

            # now / should 503 too
            request = make_request("/")
            self.assertRaises(HTTPServiceUnavailable, app, request)

            killer.join()

        finally:
            unsubscribe(APP_ENDS, end)

        # and we should have had a event ping
        self.assertEquals(pings, ['app ends'])