~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/timeline/tests/test_timeline.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-04-20 04:22:29 UTC
  • mfrom: (12873.1.1 bug-766786)
  • Revision ID: launchpad@pqm.canonical.com-20110420042229-ibe4zdve9l43xdmy
[r=stevenk][bug=766786] Enhance the request timeline to permit
        explicit nesting of actions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        self.assertRaises(OverlappingActionError, timeline.start,
38
38
            "Sending mail", "Noone")
39
39
 
 
40
    def test_nested_start_permitted(self):
 
41
        # When explicitly requested a nested start can be done
 
42
        timeline = Timeline()
 
43
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
44
        child = timeline.start("SQL Callback", "SELECT...")
 
45
 
 
46
    def test_nested_start_is_not_transitive(self):
 
47
        # nesting is explicit at each level - not inherited.
 
48
        timeline = Timeline()
 
49
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
50
        child = timeline.start("SQL Callback", "SELECT...")
 
51
        self.assertRaises(OverlappingActionError, timeline.start,
 
52
            "Sending mail", "Noone")
 
53
 
 
54
    def test_multiple_nested_children_permitted(self):
 
55
        # nesting is not reset by each action that is added.
 
56
        timeline = Timeline()
 
57
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
58
        child = timeline.start("SQL Callback", "SELECT...")
 
59
        child.finish()
 
60
        child = timeline.start("SQL Callback", "SELECT...")
 
61
 
 
62
    def test_multiple_starts_after_nested_group_prevented(self):
 
63
        # nesting stops being permitted when the nesting action is finished.
 
64
        timeline = Timeline()
 
65
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
66
        action.finish()
 
67
        child = timeline.start("SQL Callback", "SELECT...")
 
68
        self.assertRaises(OverlappingActionError, timeline.start,
 
69
            "Sending mail", "Noone")
 
70
 
 
71
    def test_nesting_within_nesting_permitted(self):
 
72
        timeline = Timeline()
 
73
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
74
        middle = timeline.start("Calling otherlibrary", "", allow_nested=True)
 
75
        child = timeline.start("SQL Callback", "SELECT...")
 
76
 
 
77
    def test_finishing_nested_within_nested_leaves_outer_nested_nesting(self):
 
78
        timeline = Timeline()
 
79
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
80
        middle = timeline.start("Calling otherlibrary", "", allow_nested=True)
 
81
        middle.finish()
 
82
        child = timeline.start("SQL Callback", "SELECT...")
 
83
 
 
84
    def test_nested_actions_recorded_as_two_zero_length_actions(self):
 
85
        timeline = Timeline()
 
86
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
87
        child = timeline.start("SQL Callback", "SELECT...")
 
88
        child.finish()
 
89
        action.finish()
 
90
        self.assertEqual(3, len(timeline.actions))
 
91
        self.assertEqual(datetime.timedelta(), timeline.actions[0].duration)
 
92
        self.assertEqual(datetime.timedelta(), timeline.actions[2].duration)
 
93
 
 
94
    def test_nested_category_labels(self):
 
95
        # To identify start/stop pairs '-start' and '-stop' are put onto the
 
96
        # category of nested actions:
 
97
        timeline = Timeline()
 
98
        action = timeline.start("Calling openid", "hostname", allow_nested=True)
 
99
        action.finish()
 
100
        self.assertEqual('Calling openid-start', timeline.actions[0].category)
 
101
        self.assertEqual('Calling openid-stop', timeline.actions[1].category)
 
102
 
40
103
    def test_start_after_finish_works(self):
41
104
        timeline = Timeline()
42
105
        action = timeline.start("Sending mail", "Noone")