Skip to content

Instantly share code, notes, and snippets.

@dkuebric
Created July 10, 2012 18:46
Show Gist options
  • Save dkuebric/3085467 to your computer and use it in GitHub Desktop.
Save dkuebric/3085467 to your computer and use it in GitHub Desktop.
tests
""" Tests for rails.
Setup and start information in rails3-stack/run.py.
"""
from test import TestWebInstrumentation
from udplisten import get_events, get_trace
class TestRails(TestWebInstrumentation):
def test_index(self):
root = get_trace('http://localhost:3000/main/index', 5)
events = root.all_events()
self.assertEquals(len(events), 5)
self.assertEquals(len(root.all_extents()), 2)
self.assertTrue(self.some_have(lambda ev: 'Controller' in ev, events))
self.assertTrue(self.some_have(lambda ev: 'Action' in ev, events))
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'rails', events))
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'render', events))
self.assertTrue(self.none_have(lambda ev: ev['Label'] == 'error', events))
self.assertTrue(root.has_key('Controller'))
self.assertTrue(root.has_key('Action'))
self.assertTrue(root.get('Layer') == 'rails')
self.assertFalse(root.all_events(lambda ev: ev.get('Label') == 'error'))
def test_breaks(self):
root = get_trace('http://localhost:3000/main/breaks', 4)
events = root.all_events()
self.assertEquals(len(events), 4)
self.assertEquals(len(root.all_extents()), 1)
self.assertTrue(self.some_have(lambda ev: ev.get('Label') == 'error', events))
def test_memcache(self):
events = get_events('http://localhost:3000/main/memcache', 16)
self.assertEquals(len(events), 16)
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'memcache', events))
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'rails', events))
def test_mysql(self):
root = get_trace('http://localhost:3000/main/mysql', 17)
events = root.all_events()
self.assertEquals(len(events), 17)
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'ActiveRecord', events))
def test_net(self):
root = get_trace('http://localhost:3000/main/net', 8)
events = root.all_events()
self.assertEquals(len(events), 8)
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'net-http', events))
self.assertTrue(self.some_have(lambda ev: ev['Layer'] == 'rails', events))
self.assertTrue(self.none_have(lambda ev: ev['Label'] == 'error', events))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment