Beispiel #1
0
    def start_test_server(self, host='localhost', port=None):
        """Creates a live test server object (instance of WSGIServer)."""
        if not port:
            for port in xrange(8001, 8050):
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                try:
                    s.bind((host, port))
                except socket.error:
                    port = None
                    continue
                else:
                    break
                finally:
                    s.close()
        if not port:
            raise socket.error('Unable to find an open port to bind server')

        self._orig_remote_url = settings.REMOTE_URL
        settings.REMOTE_URL = ['http://%s:%s/store/' % (host, port)]
        self.server_thread = TestServerThread(self, host, port)
        self.server_thread.start()
        self.server_thread.started.wait()
        if self.server_thread.error:
            raise self.server_thread.error
Beispiel #2
0
    def start_test_server(self, host='localhost', port=None):
        """Creates a live test server object (instance of WSGIServer)."""
        if not port:
            for port in xrange(8001, 8050):
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                try:
                    s.bind((host, port))
                except socket.error:
                    port = None
                    continue
                else:
                    break
                finally:
                    s.close()
        if not port:
            raise socket.error('Unable to find an open port to bind server')

        self._orig_remote_url = settings.REMOTE_URL
        settings.REMOTE_URL = ['http://%s:%s/store/' % (host, port)]
        self.server_thread = TestServerThread(self, host, port)
        self.server_thread.start()
        self.server_thread.started.wait()
        if self.server_thread.error:
            raise self.server_thread.error
Beispiel #3
0
class SentryRemoteServerTest(TransactionTestCase):
    urls = 'tests.urls'
    
    def setUp(self):
        self.server_thread = None
        logger = logging.getLogger('sentry')
        for h in logger.handlers:
            logger.removeHandler(h)
        logger.addHandler(logging.StreamHandler())

    def tearDown(self):
        self.stop_test_server()
        settings.REMOTE_URL = None
    
    def start_test_server(self, host='localhost', port=None):
        """Creates a live test server object (instance of WSGIServer)."""
        if not port:
            for port in xrange(8001, 8050):
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                try:
                    s.bind((host, port))
                except socket.error:
                    port = None
                    continue
                else:
                    break
                finally:
                    s.close()
        if not port:
            raise socket.error('Unable to find an open port to bind server')

        self._orig_remote_url = settings.REMOTE_URL
        settings.REMOTE_URL = ['http://%s:%s/store/' % (host, port)]
        self.server_thread = TestServerThread(self, host, port)
        self.server_thread.start()
        self.server_thread.started.wait()
        if self.server_thread.error:
            raise self.server_thread.error

    def stop_test_server(self):
        if self.server_thread:
            settings.REMOTE_URL = self._orig_remote_url
            self.server_thread.join()

    def test_process(self):
        self.start_test_server()
        message_id = SentryClient().process(message='hello')
        self.stop_test_server()

        self.assertTrue(message_id)
        instance = Message.objects.all().order_by('-id')[0]
        self.assertEquals(instance.message, 'hello')

    def test_external(self):
        self.start_test_server()
        path = reverse('sentry-raise-exc')
        self.stop_test_server()

        self.assertRaises(Exception, self.client.get, path)
        instance = Message.objects.all().order_by('-id')[0]
        self.assertEquals(instance.message, 'view exception')
        self.assertEquals(instance.url, 'http://testserver' + path)

    def test_timestamp(self):
        timestamp = datetime.datetime.now() - datetime.timedelta(hours=1)

        self.start_test_server()
        message_id = SentryClient().process(message='hello', timestamp=timestamp)
        self.stop_test_server()

        self.assertTrue(message_id)
        instance = Message.objects.all().order_by('-id')[0]
        self.assertEquals(instance.message, 'hello')
        self.assertEquals(instance.datetime, timestamp)
        group = instance.group
        self.assertEquals(group.first_seen, timestamp)
        self.assertEquals(group.last_seen, timestamp)
Beispiel #4
0
class SentryRemoteServerTest(TransactionTestCase):
    urls = 'tests.urls'
    
    def setUp(self):
        self.server_thread = None
        logger = logging.getLogger('sentry')
        for h in logger.handlers:
            logger.removeHandler(h)
        logger.addHandler(logging.StreamHandler())

    def tearDown(self):
        self.stop_test_server()
        settings.REMOTE_URL = None
    
    def start_test_server(self, host='localhost', port=None):
        """Creates a live test server object (instance of WSGIServer)."""
        if not port:
            for port in xrange(8001, 8050):
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                try:
                    s.bind((host, port))
                except socket.error:
                    port = None
                    continue
                else:
                    break
                finally:
                    s.close()
        if not port:
            raise socket.error('Unable to find an open port to bind server')

        self._orig_remote_url = settings.REMOTE_URL
        settings.REMOTE_URL = ['http://%s:%s/store/' % (host, port)]
        self.server_thread = TestServerThread(self, host, port)
        self.server_thread.start()
        self.server_thread.started.wait()
        if self.server_thread.error:
            raise self.server_thread.error

    def stop_test_server(self):
        if self.server_thread:
            settings.REMOTE_URL = self._orig_remote_url
            self.server_thread.join()

    def testProcess(self):
        self.start_test_server()
        message_id = SentryClient().process(message='hello')
        self.stop_test_server()

        self.assertTrue(message_id)
        instance = Message.objects.all().order_by('-id')[0]
        self.assertEquals(instance.message, 'hello')

    def testExternal(self):
        self.start_test_server()
        path = reverse('sentry-raise-exc')
        self.stop_test_server()

        self.assertRaises(Exception, self.client.get, path)
        instance = Message.objects.all().order_by('-id')[0]
        self.assertEquals(instance.message, 'view exception')
        self.assertEquals(instance.url, 'http://testserver' + path)

    def testTimestamp(self):
        timestamp = datetime.datetime.now() - datetime.timedelta(hours=1)

        self.start_test_server()
        message_id = SentryClient().process(message='hello', timestamp=timestamp)
        self.stop_test_server()

        self.assertTrue(message_id)
        instance = Message.objects.all().order_by('-id')[0]
        self.assertEquals(instance.message, 'hello')
        self.assertEquals(instance.datetime, timestamp)
        group = instance.group
        self.assertEquals(group.first_seen, timestamp)
        self.assertEquals(group.last_seen, timestamp)