Skip to content

Commit

Permalink
fix fake TriggerableScheduler. Add coverage. Fix Trigger step.
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Aug 15, 2013
1 parent d3503ea commit a343732
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 45 deletions.
5 changes: 4 additions & 1 deletion master/buildbot/steps/trigger.py
Expand Up @@ -148,7 +148,10 @@ def start(self):
dl = []
triggered_names = []
for sch in triggered_schedulers:
dl.append(sch.trigger(ss_for_trigger, set_props=props_to_set))
dl.append(sch.trigger(
waited_for=self.waitForFinish, sourcestamps=ss_for_trigger,
set_props=props_to_set
))
triggered_names.append(sch.name)
self.step_status.setText(['triggered'] + triggered_names)

Expand Down
103 changes: 59 additions & 44 deletions master/buildbot/test/unit/test_steps_trigger.py
Expand Up @@ -24,6 +24,7 @@
from buildbot.status.results import SUCCESS, FAILURE, EXCEPTION
from buildbot.steps import trigger
from buildbot.test.util import steps, compat
from buildbot.test.util.interfaces import InterfaceTests
from buildbot.test.fake import fakemaster, fakedb

class FakeTriggerable(object):
Expand All @@ -37,15 +38,19 @@ class FakeTriggerable(object):
def __init__(self, name):
self.name = name

def trigger(self, sourcestamps = None, set_props=None):
self.triggered_with = (sourcestamps, set_props.properties)
def trigger(self, waited_for, sourcestamps = None, set_props=None):
self.triggered_with = (waited_for, sourcestamps, set_props.properties)
d = defer.Deferred()
if self.exception:
reactor.callLater(0, d.errback, RuntimeError('oh noes'))
else:
reactor.callLater(0, d.callback, (self.result, self.brids))
return d

class TriggerableInterface(unittest.TestCase, InterfaceTests):
def test_interface(self):
self.assertInterfacesImplemented(FakeTriggerable)


class FakeSourceStamp(object):

Expand Down Expand Up @@ -119,16 +124,20 @@ def getAllGotRevisions():
self.exp_b_trigger = None
self.exp_added_urls = []

def runStep(self, expect_waitForFinish=False):
def runStep(self):
d = steps.BuildStepMixin.runStep(self)

if expect_waitForFinish:
# the build doesn't finish until after a callLater, so this has the
# effect of checking whether the deferred has been fired already;
# the build doesn't finish until after a callLater, so this has the
# effect of checking whether the deferred has been fired already;
early = []
d.addCallback(early.append)
if self.step.waitForFinish:
# it should not have been!
early = []
d.addCallback(early.append)
self.assertEqual(early, [])
expected_early = []
else:
expected_early = [None]

self.assertEqual(early, expected_early)

def check(_):
self.assertEqual(self.scheduler_a.triggered_with,
Expand Down Expand Up @@ -212,7 +221,7 @@ def test_sourceStamps_and_alwaysUseLatest(self):
def test_simple(self):
self.setupStep(trigger.Trigger(schedulerNames=['a'], sourceStamps = {}))
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([], {}))
self.expectTriggeredWith(a=(False, [], {}))
return self.runStep()

def test_simple_failure(self):
Expand All @@ -221,15 +230,15 @@ def test_simple_failure(self):
# not waitForFinish, so trigger step succeeds even though the build
# didn't fail
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([], {}))
self.expectTriggeredWith(a=(False, [], {}))
return self.runStep()

@compat.usesFlushLoggedErrors
def test_simple_exception(self):
self.setupStep(trigger.Trigger(schedulerNames=['a']))
self.scheduler_a.exception = True
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([], {}))
self.expectTriggeredWith(a=(False, [], {}))
d = self.runStep()
def flush(_):
self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
Expand All @@ -253,7 +262,7 @@ def test_updateSourceStamp(self):
)
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(
a=([{'codebase':'', 'repository': 'x', 'revision': 23456}], {}))
a=(False, [{'codebase':'', 'repository': 'x', 'revision': 23456}], {}))
return self.runStep()

def test_updateSourceStamp_no_got_revision(self):
Expand All @@ -265,8 +274,9 @@ def test_updateSourceStamp_no_got_revision(self):
])
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(
a=([{'codebase':'', 'repository': 'x', 'revision': 11111}], # uses old revision
{}))
a=(False,
[{'codebase':'', 'repository': 'x', 'revision': 11111}], # uses old revision
{}))
return self.runStep()

def test_not_updateSourceStamp(self):
Expand All @@ -280,8 +290,9 @@ def test_not_updateSourceStamp(self):
)
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(
a=([{'codebase':'', 'repository': 'x', 'revision': 11111}],
{}))
a=(False,
[{'codebase':'', 'repository': 'x', 'revision': 11111}],
{}))
return self.runStep()

def test_updateSourceStamp_multiple_repositories(self):
Expand All @@ -297,10 +308,10 @@ def test_updateSourceStamp_multiple_repositories(self):
)
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(
a=([
{'codebase':'cb2', 'revision':34567},
{'codebase':'cb1', 'revision':23456},
], {}))
a=(False,
[{'codebase':'cb2', 'revision':34567},
{'codebase':'cb1', 'revision':23456}],
{}))
return self.runStep()

def test_updateSourceStamp_prop_false(self):
Expand All @@ -316,7 +327,9 @@ def test_updateSourceStamp_prop_false(self):
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
# didn't use got_revision
self.expectTriggeredWith(
a=([{ 'codebase':'', 'repository': 'x', 'revision': 11111}], {}))
a=(False,
[{ 'codebase':'', 'repository': 'x', 'revision': 11111}],
{}))
return self.runStep()

def test_updateSourceStamp_prop_true(self):
Expand All @@ -332,7 +345,9 @@ def test_updateSourceStamp_prop_true(self):
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
# didn't use got_revision
self.expectTriggeredWith(
a=([{ 'codebase':'', 'repository': 'x', 'revision': 23456}], {}))
a=(False,
[{ 'codebase':'', 'repository': 'x', 'revision': 23456}],
{}))
return self.runStep()

def test_alwaysUseLatest(self):
Expand All @@ -344,7 +359,7 @@ def test_alwaysUseLatest(self):
])
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
# Do not pass setid
self.expectTriggeredWith(b=([], {}))
self.expectTriggeredWith(b=(False, [], {}))
return self.runStep()

def test_alwaysUseLatest_prop_false(self):
Expand All @@ -358,7 +373,7 @@ def test_alwaysUseLatest_prop_false(self):
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
# didn't use latest
self.expectTriggeredWith(
b=([{ 'codebase':'', 'repository': 'x', 'revision': 11111}], {}))
b=(False, [{ 'codebase':'', 'repository': 'x', 'revision': 11111}], {}))
return self.runStep()

def test_alwaysUseLatest_prop_true(self):
Expand All @@ -371,15 +386,15 @@ def test_alwaysUseLatest_prop_true(self):
self.properties.setProperty('aul', True, 'me')
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
# didn't use latest
self.expectTriggeredWith(b=([], {}))
self.expectTriggeredWith(b=(False, [], {}))
return self.runStep()

def test_sourceStamp(self):
ss = dict(revision=9876, branch='dev')
self.setupStep(trigger.Trigger(schedulerNames=['b'],
sourceStamp=ss))
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
self.expectTriggeredWith(b=([ss], {}))
self.expectTriggeredWith(b=(False, [ss], {}))
return self.runStep()

def test_set_of_sourceStamps(self):
Expand All @@ -388,7 +403,7 @@ def test_set_of_sourceStamps(self):
self.setupStep(trigger.Trigger(schedulerNames=['b'],
sourceStamps=[ss1,ss2]))
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
self.expectTriggeredWith(b=([ss2, ss1], {}))
self.expectTriggeredWith(b=(False, [ss2, ss1], {}))
return self.runStep()

def test_set_of_sourceStamps_override_build(self):
Expand All @@ -399,7 +414,7 @@ def test_set_of_sourceStamps_override_build(self):
self.setupStep(trigger.Trigger(schedulerNames=['b'],
sourceStamps=[ss1,ss2]), sourcestampsInBuild=[ss3, ss4])
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
self.expectTriggeredWith(b=([ss2, ss1], {}))
self.expectTriggeredWith(b=(False, [ss2, ss1], {}))
return self.runStep()


Expand All @@ -410,27 +425,27 @@ def test_sourceStamp_prop(self):
self.properties.setProperty('rev', 602, 'me')
expected_ss = dict(revision=602, branch='dev')
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'b'])
self.expectTriggeredWith(b=([expected_ss], {}))
self.expectTriggeredWith(b=(False, [expected_ss], {}))
return self.runStep()

def test_waitForFinish(self):
self.setupStep(trigger.Trigger(schedulerNames=['a', 'b'],
waitForFinish=True))
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a', 'b'])
self.expectTriggeredWith(
a=([], {}),
b=([], {}))
a=(True, [], {}),
b=(True, [], {}))
self.expectTriggeredLinks('a','b')
return self.runStep(expect_waitForFinish=True)
return self.runStep()

def test_waitForFinish_failure(self):
self.setupStep(trigger.Trigger(schedulerNames=['a'],
waitForFinish=True))
self.scheduler_a.result = FAILURE
self.expectOutcome(result=FAILURE, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([], {}))
self.expectTriggeredWith(a=(True, [], {}))
self.expectTriggeredLinks('a')
return self.runStep(expect_waitForFinish=True)
return self.runStep()

@compat.usesFlushLoggedErrors
def test_waitForFinish_exception(self):
Expand All @@ -440,10 +455,10 @@ def test_waitForFinish_exception(self):
self.expectOutcome(result=EXCEPTION,
status_text=['triggered', 'a', 'b'])
self.expectTriggeredWith(
a=([], {}),
b=([], {}))
a=(True, [], {}),
b=(True, [], {}))
self.expectTriggeredLinks('a') # b doesn't return a brid
d = self.runStep(expect_waitForFinish=True)
d = self.runStep()
def flush(_):
self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
d.addCallback(flush)
Expand All @@ -453,7 +468,7 @@ def test_set_properties(self):
self.setupStep(trigger.Trigger(schedulerNames=['a'],
set_properties=dict(x=1, y=2)))
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([],
self.expectTriggeredWith(a=(False, [],
dict(x=(1, 'Trigger'), y=(2, 'Trigger'))))
return self.runStep()

Expand All @@ -462,7 +477,7 @@ def test_set_properties_prop(self):
set_properties=dict(x=properties.Property('X'), y=2)))
self.properties.setProperty('X', 'xxx', 'here')
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([],
self.expectTriggeredWith(a=(False, [],
dict(x=('xxx', 'Trigger'), y=(2, 'Trigger'))))
return self.runStep()

Expand All @@ -473,17 +488,17 @@ def test_copy_properties(self):
self.properties.setProperty('b', 'B', 'BB')
self.properties.setProperty('c', 'C', 'CC')
self.expectOutcome(result=SUCCESS, status_text=['triggered', 'a'])
self.expectTriggeredWith(a=([],
self.expectTriggeredWith(a=(False, [],
dict(a=('A', 'Trigger'),
b=('B', 'Trigger'))))
return self.runStep()

def test_interrupt(self):
def test_waitForFinish_interrupt(self):
self.setupStep(trigger.Trigger(schedulerNames=['a'],
waitForFinish=True))
self.expectOutcome(result=EXCEPTION, status_text=['interrupted'])
self.expectTriggeredWith(a=([], {}))
d = self.runStep(expect_waitForFinish=True)
self.expectTriggeredWith(a=(True, [], {}))
d = self.runStep()

# interrupt before the callLater representing the Triggerable
# schedulers completes
Expand Down

0 comments on commit a343732

Please sign in to comment.