diff --git a/master/buildbot/test/integration/test_upgrade.py b/master/buildbot/test/integration/test_upgrade.py index a6a5ce223a5..084e9824180 100644 --- a/master/buildbot/test/integration/test_upgrade.py +++ b/master/buildbot/test/integration/test_upgrade.py @@ -111,11 +111,13 @@ def tearDownUpgradeTest(self): # save subclasses the trouble of calling our setUp and tearDown methods def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpUpgradeTest() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownUpgradeTest() + yield self.tearDownUpgradeTest() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def assertModelMatches(self): diff --git a/master/buildbot/test/integration/worker/test_comm.py b/master/buildbot/test/integration/worker/test_comm.py index 217224df007..d812ce452d5 100644 --- a/master/buildbot/test/integration/worker/test_comm.py +++ b/master/buildbot/test/integration/worker/test_comm.py @@ -161,7 +161,7 @@ class TestWorkerComm(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) # set the worker port to a loopback address with unspecified @@ -195,6 +195,7 @@ def setUp(self): self.server_connection_string = "tcp:0:interface=127.0.0.1" self.client_connection_string_tpl = "tcp:host=127.0.0.1:port={port}" + @defer.inlineCallbacks def tearDown(self): if self.broker: del self.broker @@ -211,7 +212,8 @@ def tearDown(self): if self.buildworker and self.buildworker.detach_d: deferreds.append(self.buildworker.detach_d) - return defer.gatherResults(deferreds) + yield defer.gatherResults(deferreds) + yield self.tear_down_test_reactor() @defer.inlineCallbacks def addWorker(self, **kwargs): diff --git a/master/buildbot/test/integration/worker/test_workerside.py b/master/buildbot/test/integration/worker/test_workerside.py index 24b7f88dfe8..052a5b3f096 100644 --- a/master/buildbot/test/integration/worker/test_workerside.py +++ b/master/buildbot/test/integration/worker/test_workerside.py @@ -111,7 +111,7 @@ class TestWorkerConnection(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) # set the worker port to a loopback address with unspecified # port @@ -154,6 +154,7 @@ def tearDown(self): # if the worker is still attached, wait for it to detach, too if self.buildworker: yield self.buildworker.waitForCompleteShutdown() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def addMasterSideWorker( diff --git a/master/buildbot/test/reactor.py b/master/buildbot/test/reactor.py index e303d582ace..07b52f77551 100644 --- a/master/buildbot/test/reactor.py +++ b/master/buildbot/test/reactor.py @@ -15,6 +15,7 @@ import asyncio +from twisted.internet import defer from twisted.internet import threads from twisted.python import threadpool @@ -30,7 +31,7 @@ class TestReactorMixin: at the end """ - def setup_test_reactor(self, use_asyncio=False): + def setup_test_reactor(self, use_asyncio=False, auto_tear_down=True): self.patch(threadpool, 'ThreadPool', NonThreadPool) self.reactor = TestReactor() self.reactor.set_test_case(self) @@ -44,21 +45,32 @@ def deferToThread(f, *args, **kwargs): self.patch(threads, 'deferToThread', deferToThread) - # During shutdown sequence we must first stop the reactor and only then - # set unset the reactor used for eventually() because any callbacks - # that are run during reactor.stop() may use eventually() themselves. - self.addCleanup(_setReactor, None) - self.addCleanup(self.reactor.assert_no_remaining_calls) - self.addCleanup(self.reactor.stop) - + self._reactor_use_asyncio = use_asyncio if use_asyncio: self.asyncio_loop = AsyncIOLoopWithTwisted(self.reactor) asyncio.set_event_loop(self.asyncio_loop) self.asyncio_loop.start() - def stop(): - self.asyncio_loop.stop() - self.asyncio_loop.close() - asyncio.set_event_loop(None) + if auto_tear_down: + self.addCleanup(self.tear_down_test_reactor) + self._reactor_tear_down_called = False + + def tear_down_test_reactor(self): + if self._reactor_tear_down_called: + return + + self._reactor_tear_down_called = True + + if self._reactor_use_asyncio: + self.asyncio_loop.stop() + self.asyncio_loop.close() + asyncio.set_event_loop(None) + + # During shutdown sequence we must first stop the reactor and only then set unset the + # reactor used for eventually() because any callbacks that are run during reactor.stop() + # may use eventually() themselves. + self.reactor.stop() + self.reactor.assert_no_remaining_calls() + _setReactor(None) - self.addCleanup(stop) + return defer.succeed(None) diff --git a/master/buildbot/test/unit/changes/test_base.py b/master/buildbot/test/unit/changes/test_base.py index 9aa7935c299..e5d1b74ac9e 100644 --- a/master/buildbot/test/unit/changes/test_base.py +++ b/master/buildbot/test/unit/changes/test_base.py @@ -32,11 +32,13 @@ class Subclass(base.ChangeSource): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpChangeSource() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownChangeSource() + yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_activation(self): @@ -82,14 +84,16 @@ class Subclass(base.ReconfigurablePollingChangeSource): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpChangeSource() yield self.attachChangeSource(self.Subclass(name="DummyCS")) + @defer.inlineCallbacks def tearDown(self): - return self.tearDownChangeSource() + yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def runClockFor(self, secs): diff --git a/master/buildbot/test/unit/changes/test_bitbucket.py b/master/buildbot/test/unit/changes/test_bitbucket.py index 225f5ea4e6c..18c7f37ead4 100644 --- a/master/buildbot/test/unit/changes/test_bitbucket.py +++ b/master/buildbot/test/unit/changes/test_bitbucket.py @@ -274,7 +274,7 @@ class TestBitbucketPullrequestPoller( changesource.ChangeSourceMixin, TestReactorMixin, LoggingMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpLogging() # create pull requests @@ -304,8 +304,10 @@ def setUp(self): return self.setUpChangeSource() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownChangeSource() + yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() def _fakeGetPage(self, result): # Install a fake getPage that puts the requested URL in self.getPage_got_url diff --git a/master/buildbot/test/unit/changes/test_changes.py b/master/buildbot/test/unit/changes/test_changes.py index 067583a7386..eb86c77cc94 100644 --- a/master/buildbot/test/unit/changes/test_changes.py +++ b/master/buildbot/test/unit/changes/test_changes.py @@ -52,7 +52,7 @@ class Change(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True) self.change23 = changes.Change(**{ # using **dict(..) forces kwargs "category": 'devel', @@ -105,6 +105,10 @@ def setUp(self): }) self.change25.number = 25 + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_fromChdict(self): # get a real honest-to-goodness chdict from the fake db diff --git a/master/buildbot/test/unit/changes/test_gerritchangesource.py b/master/buildbot/test/unit/changes/test_gerritchangesource.py index d086b80f3cc..28c61beee4f 100644 --- a/master/buildbot/test/unit/changes/test_gerritchangesource.py +++ b/master/buildbot/test/unit/changes/test_gerritchangesource.py @@ -98,7 +98,7 @@ class TestGerritChangeSource( unittest.TestCase, ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() self._got_events = [] return self.setUpChangeSource() @@ -108,6 +108,7 @@ def tearDown(self): if self.master.running: yield self.master.stopService() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def create_gerrit(self, host, user, *args, **kwargs): @@ -1046,7 +1047,7 @@ class TestGerritEventLogPoller( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpChangeSource() yield self.master.startService() @@ -1054,6 +1055,7 @@ def setUp(self): def tearDown(self): yield self.master.stopService() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def newChangeSource(self, **kwargs): diff --git a/master/buildbot/test/unit/changes/test_github.py b/master/buildbot/test/unit/changes/test_github.py index 5a9b156ba0d..7198f3fa514 100644 --- a/master/buildbot/test/unit/changes/test_github.py +++ b/master/buildbot/test/unit/changes/test_github.py @@ -180,7 +180,7 @@ class TestGitHubPullrequestPoller( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpChangeSource() fake_storage_service = FakeSecretStorage() @@ -197,6 +197,7 @@ def setUp(self): def tearDown(self): yield self.master.stopService() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def newChangeSource(self, owner, repo, endpoint='https://api.github.com', **kwargs): diff --git a/master/buildbot/test/unit/changes/test_gitpoller.py b/master/buildbot/test/unit/changes/test_gitpoller.py index 8e7511b1715..bdab6d1b1ed 100644 --- a/master/buildbot/test/unit/changes/test_gitpoller.py +++ b/master/buildbot/test/unit/changes/test_gitpoller.py @@ -66,7 +66,7 @@ def createPoller(self): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() yield self.setUpChangeSource() yield self.master.startService() @@ -77,6 +77,7 @@ def setUp(self): def tearDown(self): yield self.master.stopService() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @async_to_deferred async def set_last_rev(self, state: dict[str, str]) -> None: @@ -2433,7 +2434,7 @@ class TestGitPollerConstructor( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpChangeSource() yield self.master.startService() @@ -2441,6 +2442,7 @@ def setUp(self): def tearDown(self): yield self.master.stopService() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_deprecatedFetchRefspec(self): diff --git a/master/buildbot/test/unit/changes/test_hgpoller.py b/master/buildbot/test/unit/changes/test_hgpoller.py index d602a168015..341c41e2526 100644 --- a/master/buildbot/test/unit/changes/test_hgpoller.py +++ b/master/buildbot/test/unit/changes/test_hgpoller.py @@ -39,7 +39,7 @@ class TestHgPollerBase( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() yield self.setUpChangeSource() @@ -71,6 +71,7 @@ def _isRepositoryReady(): def tearDown(self): yield self.master.stopService() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def check_current_rev(self, wished, branch='default'): diff --git a/master/buildbot/test/unit/changes/test_mail.py b/master/buildbot/test/unit/changes/test_mail.py index 3748de6e3f0..ee8788795ab 100644 --- a/master/buildbot/test/unit/changes/test_mail.py +++ b/master/buildbot/test/unit/changes/test_mail.py @@ -29,7 +29,7 @@ class TestMaildirSource( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.maildir = os.path.abspath("maildir") yield self.setUpChangeSource() @@ -56,6 +56,7 @@ def assertMailProcessed(self): def tearDown(self): yield self.tearDownDirs() yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() # tests diff --git a/master/buildbot/test/unit/changes/test_manager.py b/master/buildbot/test/unit/changes/test_manager.py index 5eb1d98536f..2e63de2bc00 100644 --- a/master/buildbot/test/unit/changes/test_manager.py +++ b/master/buildbot/test/unit/changes/test_manager.py @@ -28,15 +28,17 @@ class TestChangeManager(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) self.cm = manager.ChangeManager() self.master.startService() yield self.cm.setServiceParent(self.master) self.new_config = mock.Mock() + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() def make_sources(self, n, klass=base.ChangeSource, **kwargs): for i in range(n): diff --git a/master/buildbot/test/unit/changes/test_p4poller.py b/master/buildbot/test/unit/changes/test_p4poller.py index 929199ef7e0..a75c5d2c919 100644 --- a/master/buildbot/test/unit/changes/test_p4poller.py +++ b/master/buildbot/test/unit/changes/test_p4poller.py @@ -109,12 +109,14 @@ class TestP4Poller( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() yield self.setUpChangeSource() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownChangeSource() + yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() def add_p4_describe_result(self, number, result): self.expect_commands( diff --git a/master/buildbot/test/unit/changes/test_pb.py b/master/buildbot/test/unit/changes/test_pb.py index 17a190210ba..4d189442be0 100644 --- a/master/buildbot/test/unit/changes/test_pb.py +++ b/master/buildbot/test/unit/changes/test_pb.py @@ -40,12 +40,17 @@ class TestPBChangeSource( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpPBChangeSource() yield self.setUpChangeSource() self.master.pbmanager = self.pbmanager + @defer.inlineCallbacks + def tearDown(self): + yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() + def test_registration_no_workerport(self): return self._test_registration(None, exp_ConfigErrors=True, user='alice', passwd='sekrit') @@ -212,9 +217,13 @@ def test_reconfigService_default_changed_but_inactive(self): class TestChangePerspective(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_addChange_noprefix(self): cp = pb.ChangePerspective(self.master, None) diff --git a/master/buildbot/test/unit/changes/test_svnpoller.py b/master/buildbot/test/unit/changes/test_svnpoller.py index 112439a558a..cfab8c03a5c 100644 --- a/master/buildbot/test/unit/changes/test_svnpoller.py +++ b/master/buildbot/test/unit/changes/test_svnpoller.py @@ -259,12 +259,14 @@ class TestSVNPoller( MasterRunProcessMixin, changesource.ChangeSourceMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() return self.setUpChangeSource() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownChangeSource() + yield self.tearDownChangeSource() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def attachSVNPoller(self, *args, **kwargs): diff --git a/master/buildbot/test/unit/data/test_base.py b/master/buildbot/test/unit/data/test_base.py index 16383421ebe..1829f3de3a7 100644 --- a/master/buildbot/test/unit/data/test_base.py +++ b/master/buildbot/test/unit/data/test_base.py @@ -26,7 +26,11 @@ class ResourceType(TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() def makeResourceTypeSubclass(self, **attributes): attributes.setdefault('name', 'thing') diff --git a/master/buildbot/test/unit/data/test_build_data.py b/master/buildbot/test/unit/data/test_build_data.py index af3afc4fa94..d78c056e4bc 100644 --- a/master/buildbot/test/unit/data/test_build_data.py +++ b/master/buildbot/test/unit/data/test_build_data.py @@ -332,10 +332,14 @@ def test_get_builds_id(self, name, buildid, exp_names): class TestBuildData(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = build_data.BuildData(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_set_build_data(self): @self.assertArgSpecMatches(self.master.data.updates.setBuildData, self.rtype.setBuildData) def setBuildData(self, buildid, name, value, source): diff --git a/master/buildbot/test/unit/data/test_builders.py b/master/buildbot/test/unit/data/test_builders.py index bb9fc17e1b0..22799611000 100644 --- a/master/buildbot/test/unit/data/test_builders.py +++ b/master/buildbot/test/unit/data/test_builders.py @@ -221,7 +221,7 @@ def test_get_contains_two_tags_one_unknown(self): class Builder(interfaces.InterfaceTests, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = builders.Builder(self.master) yield self.master.db.insert_test_data([ @@ -229,6 +229,10 @@ def setUp(self): fakedb.Master(id=14), ]) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_findBuilderId(self): @self.assertArgSpecMatches( self.master.data.updates.findBuilderId, # fake diff --git a/master/buildbot/test/unit/data/test_buildrequests.py b/master/buildbot/test/unit/data/test_buildrequests.py index 2c139b593c0..05b37e7c0ef 100644 --- a/master/buildbot/test/unit/data/test_buildrequests.py +++ b/master/buildbot/test/unit/data/test_buildrequests.py @@ -276,10 +276,14 @@ class dBLayerException(Exception): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = buildrequests.BuildRequest(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def doTestCallthrough( self, diff --git a/master/buildbot/test/unit/data/test_builds.py b/master/buildbot/test/unit/data/test_builds.py index f40fed9d8c3..e4fc75e0837 100644 --- a/master/buildbot/test/unit/data/test_builds.py +++ b/master/buildbot/test/unit/data/test_builds.py @@ -340,10 +340,14 @@ class Build(interfaces.InterfaceTests, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = builds.Build(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def do_test_callthrough( self, diff --git a/master/buildbot/test/unit/data/test_buildsets.py b/master/buildbot/test/unit/data/test_buildsets.py index 1a7517c811d..d36f2a5cd0a 100644 --- a/master/buildbot/test/unit/data/test_buildsets.py +++ b/master/buildbot/test/unit/data/test_buildsets.py @@ -126,7 +126,7 @@ def test_get_incomplete(self): class Buildset(TestReactorMixin, util_interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = buildsets.Buildset(self.master) yield self.master.db.insert_test_data([ @@ -143,6 +143,10 @@ def setUp(self): fakedb.Builder(id=43, name='bldr2'), ]) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + SS234_DATA = { 'branch': 'br', 'codebase': 'cb', diff --git a/master/buildbot/test/unit/data/test_changes.py b/master/buildbot/test/unit/data/test_changes.py index 83ad7f4cefa..6943256bd40 100644 --- a/master/buildbot/test/unit/data/test_changes.py +++ b/master/buildbot/test/unit/data/test_changes.py @@ -194,10 +194,14 @@ class Change(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = changes.Change(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_addChange(self): @self.assertArgSpecMatches( self.master.data.updates.addChange, # fake diff --git a/master/buildbot/test/unit/data/test_changesources.py b/master/buildbot/test/unit/data/test_changesources.py index fe1167df958..5ecb0eb0cf4 100644 --- a/master/buildbot/test/unit/data/test_changesources.py +++ b/master/buildbot/test/unit/data/test_changesources.py @@ -148,10 +148,14 @@ def test_get_masterid_missing(self): class ChangeSource(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = changesources.ChangeSource(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_findChangeSourceId(self): @self.assertArgSpecMatches( self.master.data.updates.findChangeSourceId, # fake diff --git a/master/buildbot/test/unit/data/test_connector.py b/master/buildbot/test/unit/data/test_connector.py index f746021ca01..169ddb604c9 100644 --- a/master/buildbot/test/unit/data/test_connector.py +++ b/master/buildbot/test/unit/data/test_connector.py @@ -112,32 +112,44 @@ def updateBuilderList(self, masterid, builderNames): class TestFakeData(TestReactorMixin, unittest.TestCase, Tests): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) self.data = self.master.data + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class TestDataConnector(TestReactorMixin, unittest.TestCase, Tests): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True) self.data = connector.DataConnector() yield self.data.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class DataConnector(TestReactorMixin, unittest.TestCase): maxDiff = None @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) # don't load by default self.patch(connector.DataConnector, 'submodules', []) self.data = connector.DataConnector() yield self.data.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def patchFooPattern(self): cls = type('FooEndpoint', (base.Endpoint,), {}) ep = cls(None, self.master) diff --git a/master/buildbot/test/unit/data/test_logs.py b/master/buildbot/test/unit/data/test_logs.py index cd72286345c..7d73853a369 100644 --- a/master/buildbot/test/unit/data/test_logs.py +++ b/master/buildbot/test/unit/data/test_logs.py @@ -200,10 +200,14 @@ def test_get_builder_build_number_step_number(self): class Log(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = logs.Log(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def do_test_callthrough( self, dbMethodName, method, exp_args=None, exp_kwargs=None, *args, **kwargs diff --git a/master/buildbot/test/unit/data/test_masters.py b/master/buildbot/test/unit/data/test_masters.py index c3cd50d7256..1a98b635173 100644 --- a/master/buildbot/test/unit/data/test_masters.py +++ b/master/buildbot/test/unit/data/test_masters.py @@ -131,10 +131,14 @@ def test_get_builderid_missing(self): class Master(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = masters.Master(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_masterActive(self): @self.assertArgSpecMatches( self.master.data.updates.masterActive, # fake diff --git a/master/buildbot/test/unit/data/test_patches.py b/master/buildbot/test/unit/data/test_patches.py index eeb184aadc4..a1db26744cf 100644 --- a/master/buildbot/test/unit/data/test_patches.py +++ b/master/buildbot/test/unit/data/test_patches.py @@ -24,8 +24,12 @@ class Patch(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = patches.Patch(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + # no update methods -> nothing to test diff --git a/master/buildbot/test/unit/data/test_projects.py b/master/buildbot/test/unit/data/test_projects.py index c991afb6232..9f6ae11717b 100644 --- a/master/buildbot/test/unit/data/test_projects.py +++ b/master/buildbot/test/unit/data/test_projects.py @@ -115,13 +115,17 @@ def test_get(self, name, active_filter, expected_projectids): class Project(interfaces.InterfaceTests, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = projects.Project(self.master) yield self.master.db.insert_test_data([ fakedb.Project(id=13, name="fake_project"), ]) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_find_project_id(self): @self.assertArgSpecMatches( self.master.data.updates.find_project_id, # fake diff --git a/master/buildbot/test/unit/data/test_properties.py b/master/buildbot/test/unit/data/test_properties.py index 5a9a96b62f4..c99f1c25bac 100644 --- a/master/buildbot/test/unit/data/test_properties.py +++ b/master/buildbot/test/unit/data/test_properties.py @@ -91,10 +91,14 @@ def test_get_properties_from_builder(self): class Properties(interfaces.InterfaceTests, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=False, wantDb=True, wantData=True) self.rtype = properties.Properties(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def do_test_callthrough( self, dbMethodName, method, exp_args=None, exp_kwargs=None, *args, **kwargs diff --git a/master/buildbot/test/unit/data/test_schedulers.py b/master/buildbot/test/unit/data/test_schedulers.py index c94b9db3452..b1d637acd37 100644 --- a/master/buildbot/test/unit/data/test_schedulers.py +++ b/master/buildbot/test/unit/data/test_schedulers.py @@ -145,10 +145,14 @@ def test_get_masterid_missing(self): class Scheduler(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = schedulers.Scheduler(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_schedulerEnable(self): @self.assertArgSpecMatches( self.master.data.updates.schedulerEnable, self.rtype.schedulerEnable diff --git a/master/buildbot/test/unit/data/test_steps.py b/master/buildbot/test/unit/data/test_steps.py index bc5dae13f8b..17725abdcea 100644 --- a/master/buildbot/test/unit/data/test_steps.py +++ b/master/buildbot/test/unit/data/test_steps.py @@ -217,10 +217,14 @@ def test_get_buildername(self): class Step(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = steps.Step(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_addStep(self): @self.assertArgSpecMatches( self.master.data.updates.addStep, # fake diff --git a/master/buildbot/test/unit/data/test_test_result_sets.py b/master/buildbot/test/unit/data/test_test_result_sets.py index f52409b9532..84c0058f905 100644 --- a/master/buildbot/test/unit/data/test_test_result_sets.py +++ b/master/buildbot/test/unit/data/test_test_result_sets.py @@ -158,10 +158,14 @@ def test_get_result_sets_steps_stepid(self): class TestResultSet(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = test_result_sets.TestResultSet(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_add_test_result_set(self): @self.assertArgSpecMatches( self.master.data.updates.addTestResultSet, self.rtype.addTestResultSet diff --git a/master/buildbot/test/unit/data/test_test_results.py b/master/buildbot/test/unit/data/test_test_results.py index 1ff5ed355c7..29e5ef05f1f 100644 --- a/master/buildbot/test/unit/data/test_test_results.py +++ b/master/buildbot/test/unit/data/test_test_results.py @@ -98,10 +98,14 @@ def test_get_missing_results(self): class TestResult(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = test_results.TestResult(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_add_test_results(self): @self.assertArgSpecMatches( self.master.data.updates.addTestResults, self.rtype.addTestResults diff --git a/master/buildbot/test/unit/data/test_workers.py b/master/buildbot/test/unit/data/test_workers.py index 1c6500bdf6f..cd100cbb82e 100644 --- a/master/buildbot/test/unit/data/test_workers.py +++ b/master/buildbot/test/unit/data/test_workers.py @@ -294,7 +294,7 @@ def test_set_worker_paused_find_by_paused(self): class Worker(TestReactorMixin, interfaces.InterfaceTests, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.rtype = workers.Worker(self.master) yield self.master.db.insert_test_data([ @@ -302,6 +302,10 @@ def setUp(self): fakedb.Master(id=14), ]) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_signature_findWorkerId(self): @self.assertArgSpecMatches( self.master.data.updates.findWorkerId, # fake diff --git a/master/buildbot/test/unit/db/test_connector.py b/master/buildbot/test/unit/db/test_connector.py index b02f3d17078..eea63b334af 100644 --- a/master/buildbot/test/unit/db/test_connector.py +++ b/master/buildbot/test/unit/db/test_connector.py @@ -34,7 +34,7 @@ class TestDBConnector(TestReactorMixin, db.RealDatabaseMixin, unittest.TestCase) @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpRealDatabase( table_names=[ 'changes', @@ -65,6 +65,7 @@ def tearDown(self): yield self.db.stopService() yield self.tearDownRealDatabase() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def startService(self, check_version=False): diff --git a/master/buildbot/test/unit/process/test_botmaster_BotMaster.py b/master/buildbot/test/unit/process/test_botmaster_BotMaster.py index 9a8d1ca1b6b..7da0f15c8bd 100644 --- a/master/buildbot/test/unit/process/test_botmaster_BotMaster.py +++ b/master/buildbot/test/unit/process/test_botmaster_BotMaster.py @@ -30,12 +30,16 @@ class TestCleanShutdown(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) self.botmaster = BotMaster() yield self.botmaster.setServiceParent(self.master) self.botmaster.startService() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertReactorStopped(self, _=None): self.assertTrue(self.reactor.stop_called) @@ -152,7 +156,7 @@ def test_shutdown_cancel(self): class TestBotMaster(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True) self.master.mq = self.master.mq self.master.botmaster.disownServiceParent() @@ -161,8 +165,10 @@ def setUp(self): self.new_config = mock.Mock() self.botmaster.startService() + @defer.inlineCallbacks def tearDown(self): - return self.botmaster.stopService() + yield self.botmaster.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_reconfigServiceWithBuildbotConfig(self): diff --git a/master/buildbot/test/unit/process/test_build.py b/master/buildbot/test/unit/process/test_build.py index dfcfd6c4f22..e9412ec8ea8 100644 --- a/master/buildbot/test/unit/process/test_build.py +++ b/master/buildbot/test/unit/process/test_build.py @@ -180,7 +180,7 @@ def makeControllableStepFactory(): class TestBuild(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) r = FakeRequest() r.sources = [FakeSource()] r.sources[0].changes = [FakeChange()] @@ -205,6 +205,10 @@ def setUp(self): self.build.text = [] self.build.buildid = 666 + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertWorkerPreparationFailure(self, reason): states = "".join(self.master.data.updates.stepStateString.values()) self.assertIn(states, reason) @@ -887,7 +891,7 @@ def get_active_builds(): class TestMultipleSourceStamps(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.builder = FakeBuilder(self.master) @@ -911,6 +915,10 @@ def setUp(self): self.build = Build([r], self.builder) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_buildReturnSourceStamp(self): """ Test that a build returns the correct sourcestamp @@ -934,7 +942,7 @@ def test_buildReturnSourceStamp_empty_codebase(self): class TestBuildBlameList(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.builder = FakeBuilder(self.master) @@ -959,6 +967,10 @@ def setUp(self): self.patchSource.revision = "67890" self.patchSource.patch_info = ("jeff", "jeff's new feature") + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_blamelist_for_changes(self): r = FakeRequest() r.sources.extend([self.sourceByMe, self.sourceByHim]) @@ -983,7 +995,7 @@ class TestSetupProperties_MultipleSources(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.props = {} self.r = FakeRequest() self.r.sources = [] @@ -1004,6 +1016,10 @@ def setUp(self): # record properties that will be set self.build.properties.setProperty = self.setProperty + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def setProperty(self, n, v, s, runtime=False): if s not in self.props: self.props[s] = {} @@ -1028,7 +1044,7 @@ class TestSetupProperties_SingleSource(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.props = {} self.r = FakeRequest() self.r.sources = [] @@ -1044,6 +1060,10 @@ def setUp(self): # record properties that will be set self.build.properties.setProperty = self.setProperty + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def setProperty(self, n, v, s, runtime=False): if s not in self.props: self.props[s] = {} diff --git a/master/buildbot/test/unit/process/test_builder.py b/master/buildbot/test/unit/process/test_builder.py index a0e7c5b08f6..ac50ade4fb9 100644 --- a/master/buildbot/test/unit/process/test_builder.py +++ b/master/buildbot/test/unit/process/test_builder.py @@ -108,7 +108,7 @@ def reconfigService(self, name, _, **kwargs): class TestBuilder(TestReactorMixin, BuilderMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) # a collection of rows that would otherwise clutter up every test yield self.setUpBuilderMixin() self.base_rows = [ @@ -117,6 +117,10 @@ def setUp(self): fakedb.BuildsetSourceStamp(buildsetid=11, sourcestampid=21), ] + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def makeBuilder(self, patch_random=False, startBuildsForSucceeds=True, **config_kwargs): yield super().makeBuilder(patch_random=patch_random, **config_kwargs) @@ -480,9 +484,13 @@ def test_defaultProperties(self): class TestGetBuilderId(TestReactorMixin, BuilderMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpBuilderMixin() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_getBuilderId(self): # noReconfig because reconfigService calls getBuilderId, and we haven't @@ -503,7 +511,7 @@ def test_getBuilderId(self): class TestGetOldestRequestTime(TestReactorMixin, BuilderMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpBuilderMixin() # a collection of rows that would otherwise clutter up every test @@ -525,6 +533,10 @@ def setUp(self): ] yield self.db.insert_test_data(self.base_rows) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_gort_unclaimed(self): yield self.makeBuilder(name='bldr1') @@ -548,7 +560,7 @@ def test_gort_all_claimed(self): class TestGetNewestCompleteTime(TestReactorMixin, BuilderMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpBuilderMixin() # a collection of rows that would otherwise clutter up every test @@ -573,6 +585,10 @@ def setUp(self): ] yield self.db.insert_test_data(self.base_rows) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_gnct_completed(self): yield self.makeBuilder(name='bldr1') @@ -589,7 +605,7 @@ def test_gnct_no_completed(self): class TestGetHighestPriority(TestReactorMixin, BuilderMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpBuilderMixin() # a collection of rows that would otherwise clutter up every test @@ -612,6 +628,10 @@ def setUp(self): ] yield self.db.insert_test_data(self.base_rows) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_ghp_unclaimed(self): yield self.makeBuilder(name='bldr1') @@ -630,7 +650,7 @@ class TestReconfig(TestReactorMixin, BuilderMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpBuilderMixin() yield self.db.insert_test_data([ @@ -638,6 +658,10 @@ def setUp(self): fakedb.Project(id=302, name='new_project'), ]) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_reconfig(self): yield self.makeBuilder(description="Old", project="old_project", tags=["OldTag"]) diff --git a/master/buildbot/test/unit/process/test_buildrequest.py b/master/buildbot/test/unit/process/test_buildrequest.py index ec221ec4233..fae666f3ef3 100644 --- a/master/buildbot/test/unit/process/test_buildrequest.py +++ b/master/buildbot/test/unit/process/test_buildrequest.py @@ -30,7 +30,7 @@ class TestBuildRequestCollapser(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True) self.master.botmaster = mock.Mock(name='botmaster') self.master.botmaster.builders = {} @@ -53,8 +53,9 @@ def createBuilder(self, name, builderid=None): return bldr + @defer.inlineCallbacks def tearDown(self): - pass + yield self.tear_down_test_reactor() @defer.inlineCallbacks def do_request_collapse(self, rows, brids, exp): @@ -461,7 +462,11 @@ def test_asdict_with_patch(self): class TestBuildRequest(TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_fromBrdict(self): diff --git a/master/buildbot/test/unit/process/test_buildrequestdistributor.py b/master/buildbot/test/unit/process/test_buildrequestdistributor.py index beb2bafdad0..ad822350119 100644 --- a/master/buildbot/test/unit/process/test_buildrequestdistributor.py +++ b/master/buildbot/test/unit/process/test_buildrequestdistributor.py @@ -47,7 +47,7 @@ def pick_nth_by_name(builder, workers=None, br=None): class TestBRDBase(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.botmaster = mock.Mock(name='botmaster') self.botmaster.builders = {} self.builders = {} @@ -73,10 +73,11 @@ def prioritizeBuilders(master, builders): fakedb.BuildsetSourceStamp(sourcestampid=21, buildsetid=11), ] + @defer.inlineCallbacks def tearDown(self): if self.brd.running: - return self.brd.stopService() - return None + yield self.brd.stopService() + yield self.tear_down_test_reactor() def make_workers(self, worker_count): rows = self.base_rows[:] diff --git a/master/buildbot/test/unit/process/test_buildstep.py b/master/buildbot/test/unit/process/test_buildstep.py index 2882273b453..a4c7055d847 100644 --- a/master/buildbot/test/unit/process/test_buildstep.py +++ b/master/buildbot/test/unit/process/test_buildstep.py @@ -115,11 +115,13 @@ def run(self): return SUCCESS def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() # support @@ -1090,10 +1092,14 @@ def addLogObserver(self, logname, observer): class TestFakeItfc(unittest.TestCase, TestBuildStepMixin, TestReactorMixin, InterfaceTests): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setup_test_build_step() self.setup_step(buildstep.BuildStep()) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class TestRealItfc(unittest.TestCase, InterfaceTests): def setUp(self): @@ -1114,12 +1120,14 @@ def run(self): class TestCommandMixin(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setup_test_build_step() self.setup_step(CommandMixinExample()) + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_runRmdir(self): @@ -1231,11 +1239,13 @@ class TestShellMixin( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setup_test_build_step(with_secrets={"s3cr3t": "really_safe_string"}) + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_setupShellMixin_bad_arg(self): mixin = SimpleShellCommand() diff --git a/master/buildbot/test/unit/process/test_debug.py b/master/buildbot/test/unit/process/test_debug.py index 7801120849b..8bcdc01f4a6 100644 --- a/master/buildbot/test/unit/process/test_debug.py +++ b/master/buildbot/test/unit/process/test_debug.py @@ -32,10 +32,14 @@ class FakeManhole(service.AsyncService): class TestDebugServices(TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = mock.Mock(name='master') self.config = MasterConfig() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_reconfigService_manhole(self): master = yield fakemaster.make_master(self) diff --git a/master/buildbot/test/unit/process/test_log.py b/master/buildbot/test/unit/process/test_log.py index 7ecd7d18971..7d97f048858 100644 --- a/master/buildbot/test/unit/process/test_log.py +++ b/master/buildbot/test/unit/process/test_log.py @@ -29,9 +29,13 @@ class Tests(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def makeLog(self, type, logEncoding='utf-8'): logid = yield self.master.data.updates.addLog(stepid=27, name='testlog', type=str(type)) diff --git a/master/buildbot/test/unit/process/test_logobserver.py b/master/buildbot/test/unit/process/test_logobserver.py index cb61012606c..2097b3be79f 100644 --- a/master/buildbot/test/unit/process/test_logobserver.py +++ b/master/buildbot/test/unit/process/test_logobserver.py @@ -45,9 +45,13 @@ def finishReceived(self): class TestLogObserver(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_sequence(self): logid = yield self.master.data.updates.addLog(1, 'mine', 's') @@ -96,9 +100,13 @@ def finishReceived(self): class TestLineConsumerLogObesrver(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def do_test_sequence(self, consumer): logid = yield self.master.data.updates.addLog(1, 'mine', 's') @@ -169,9 +177,13 @@ def consumer(): class TestLogLineObserver(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_sequence(self): logid = yield self.master.data.updates.addLog(1, 'mine', 's') @@ -209,9 +221,13 @@ def test_old_setMaxLineLength(self): class TestOutputProgressObserver(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_sequence(self): logid = yield self.master.data.updates.addLog(1, 'mine', 's') @@ -229,9 +245,13 @@ def test_sequence(self): class TestBufferObserver(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def do_test_sequence(self, lo): logid = yield self.master.data.updates.addLog(1, 'mine', 's') diff --git a/master/buildbot/test/unit/process/test_metrics.py b/master/buildbot/test/unit/process/test_metrics.py index 0fca487b5dd..bc976af1dc2 100644 --- a/master/buildbot/test/unit/process/test_metrics.py +++ b/master/buildbot/test/unit/process/test_metrics.py @@ -28,7 +28,7 @@ class TestMetricBase(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.observer = metrics.MetricLogObserver() self.observer.parent = self.master = yield fakemaster.make_master(self) self.master.config.metrics = {"log_interval": 0, "periodic_interval": 0} @@ -36,9 +36,11 @@ def setUp(self): self.observer.startService() self.observer.reconfigServiceWithBuildbotConfig(self.master.config) + @defer.inlineCallbacks def tearDown(self): if self.observer.running: - self.observer.stopService() + yield self.observer.stopService() + yield self.tear_down_test_reactor() class TestMetricCountEvent(TestMetricBase): diff --git a/master/buildbot/test/unit/process/test_users_manual.py b/master/buildbot/test/unit/process/test_users_manual.py index 024dd933bed..25fd041421a 100644 --- a/master/buildbot/test/unit/process/test_users_manual.py +++ b/master/buildbot/test/unit/process/test_users_manual.py @@ -47,9 +47,13 @@ class TestUsersBase(unittest.TestCase): class TestCommandlineUserManagerPerspective(TestReactorMixin, unittest.TestCase, ManualUsersMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpManualUsers() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def call_perspective_commandline(self, *args): persp = manual.CommandlineUserManagerPerspective(self.master) return persp.perspective_commandline(*args) @@ -246,13 +250,17 @@ def test_perspective_commandline_get_no_match_format(self): class TestCommandlineUserManager(TestReactorMixin, unittest.TestCase, ManualUsersMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpManualUsers() self.manual_component = manual.CommandlineUserManager( username="user", passwd="userpw", port="9990" ) yield self.manual_component.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_no_userpass(self): d = defer.maybeDeferred(manual.CommandlineUserManager) return self.assertFailure(d, AssertionError) diff --git a/master/buildbot/test/unit/process/test_users_users.py b/master/buildbot/test/unit/process/test_users_users.py index 5e987a41e1a..d73956d56d9 100644 --- a/master/buildbot/test/unit/process/test_users_users.py +++ b/master/buildbot/test/unit/process/test_users_users.py @@ -28,11 +28,15 @@ class UsersTests(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True) self.db = self.master.db self.test_sha = users.encrypt("cancer") + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def verify_users(self, users): users_no_attrs = copy.deepcopy(users) diff --git a/master/buildbot/test/unit/reporters/test_base.py b/master/buildbot/test/unit/reporters/test_base.py index 046de202aef..7628954de36 100644 --- a/master/buildbot/test/unit/reporters/test_base.py +++ b/master/buildbot/test/unit/reporters/test_base.py @@ -40,11 +40,15 @@ class TestReporterBase( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.setUpLogging() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setupNotifier(self, generators): mn = ReporterBase(generators=generators) diff --git a/master/buildbot/test/unit/reporters/test_bitbucket.py b/master/buildbot/test/unit/reporters/test_bitbucket.py index 3e27819867a..295bfb899fd 100644 --- a/master/buildbot/test/unit/reporters/test_bitbucket.py +++ b/master/buildbot/test/unit/reporters/test_bitbucket.py @@ -38,7 +38,7 @@ class TestBitbucketStatusPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.reporter_test_repo = 'https://example.org/user/repo' @@ -62,6 +62,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.bsp.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_basic(self): @@ -271,7 +272,7 @@ class TestBitbucketStatusPushProperties( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.reporter_test_repo = 'https://example.org/user/repo' @@ -310,6 +311,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.bsp.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_properties(self): @@ -375,7 +377,7 @@ def test_auth_error(self): class TestBitbucketStatusPushRepoParsing(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) self.bsp = BitbucketStatusPush(Interpolate('key'), Interpolate('secret')) @@ -385,6 +387,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.bsp.stopService() + yield self.tear_down_test_reactor() def parse(self, repourl): return tuple(self.bsp.get_owner_and_repo(repourl)) diff --git a/master/buildbot/test/unit/reporters/test_bitbucketserver.py b/master/buildbot/test/unit/reporters/test_bitbucketserver.py index a9a39f32031..5f4ee48b9da 100644 --- a/master/buildbot/test/unit/reporters/test_bitbucketserver.py +++ b/master/buildbot/test/unit/reporters/test_bitbucketserver.py @@ -54,7 +54,7 @@ class TestBitbucketServerStatusPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) yield self.master.startService() @@ -72,6 +72,7 @@ def setupReporter(self, **kwargs): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def _check_start_and_finish_build(self, build): @@ -219,7 +220,7 @@ class TestBitbucketServerCoreAPIStatusPush( ): @defer.inlineCallbacks def setupReporter(self, token=None, **kwargs): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) @@ -251,8 +252,10 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): - if self.master and self.master.running: - yield self.master.stopService() + if self.master: + if self.master.running: + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def _check_start_and_finish_build(self, build, parentPlan=False, epoch=False): @@ -628,7 +631,7 @@ class TestBitbucketServerPRCommentPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) yield self.master.startService() @@ -666,6 +669,7 @@ def setupReporter(self, verbose=True, generator_class=BuildStatusGenerator, **kw @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def setupBuildResults(self, buildResults, set_pr=True): diff --git a/master/buildbot/test/unit/reporters/test_generators_build.py b/master/buildbot/test/unit/reporters/test_generators_build.py index 5118f39b970..c232f546c5c 100644 --- a/master/buildbot/test/unit/reporters/test_generators_build.py +++ b/master/buildbot/test/unit/reporters/test_generators_build.py @@ -35,10 +35,14 @@ class TestBuildGenerator(ConfigErrorsMixin, TestReactorMixin, unittest.TestCase, ReporterTestMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def insert_build_finished_get_props( self, results, add_logs=None, want_logs_content=False, **kwargs @@ -297,10 +301,14 @@ class TestBuildStartEndGenerator( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def insert_build_finished_get_props( self, results, add_logs=None, want_logs_content=False, **kwargs diff --git a/master/buildbot/test/unit/reporters/test_generators_buildrequest.py b/master/buildbot/test/unit/reporters/test_generators_buildrequest.py index 6ce7f00216b..8ddc4ea260e 100644 --- a/master/buildbot/test/unit/reporters/test_generators_buildrequest.py +++ b/master/buildbot/test/unit/reporters/test_generators_buildrequest.py @@ -36,7 +36,7 @@ class TestBuildRequestGenerator( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) @@ -44,6 +44,10 @@ def setUp(self): builder.master = self.master self.master.botmaster.getBuilderById = Mock(return_value=builder) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @parameterized.expand([ ('tags', 'tag'), ('tags', 1), diff --git a/master/buildbot/test/unit/reporters/test_generators_buildset.py b/master/buildbot/test/unit/reporters/test_generators_buildset.py index 0777b8dc75b..16e84f64be2 100644 --- a/master/buildbot/test/unit/reporters/test_generators_buildset.py +++ b/master/buildbot/test/unit/reporters/test_generators_buildset.py @@ -34,10 +34,14 @@ class TestBuildSetGeneratorBase( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def insert_build_finished_get_props(self, results, **kwargs): build = yield self.insert_build_finished(results, **kwargs) diff --git a/master/buildbot/test/unit/reporters/test_generators_utils.py b/master/buildbot/test/unit/reporters/test_generators_utils.py index ff06b638885..29d1ff539b3 100644 --- a/master/buildbot/test/unit/reporters/test_generators_utils.py +++ b/master/buildbot/test/unit/reporters/test_generators_utils.py @@ -36,10 +36,14 @@ class TestBuildGenerator(ConfigErrorsMixin, TestReactorMixin, unittest.TestCase, ReporterTestMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def insert_build_finished_get_props(self, results, **kwargs): build = yield self.insert_build_finished(results, **kwargs) diff --git a/master/buildbot/test/unit/reporters/test_generators_worker.py b/master/buildbot/test/unit/reporters/test_generators_worker.py index d845730bddb..1431f308a88 100644 --- a/master/buildbot/test/unit/reporters/test_generators_worker.py +++ b/master/buildbot/test/unit/reporters/test_generators_worker.py @@ -26,9 +26,13 @@ class TestWorkerMissingGenerator(ConfigErrorsMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def _get_worker_dict(self, worker_name): return { 'name': worker_name, diff --git a/master/buildbot/test/unit/reporters/test_gerrit.py b/master/buildbot/test/unit/reporters/test_gerrit.py index 3589f807743..871cdf205d1 100644 --- a/master/buildbot/test/unit/reporters/test_gerrit.py +++ b/master/buildbot/test/unit/reporters/test_gerrit.py @@ -122,10 +122,14 @@ def sampleSummaryCBDeferred(buildInfoList, results, master, arg): class TestGerritStatusPush(TestReactorMixin, unittest.TestCase, ReporterTestMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setupGerritStatusPushSimple(self, *args, **kwargs): serv = kwargs.pop("server", "serv") diff --git a/master/buildbot/test/unit/reporters/test_gerrit_verify_status.py b/master/buildbot/test/unit/reporters/test_gerrit_verify_status.py index 346741b9bda..fe8f2ca6686 100644 --- a/master/buildbot/test/unit/reporters/test_gerrit_verify_status.py +++ b/master/buildbot/test/unit/reporters/test_gerrit_verify_status.py @@ -39,7 +39,7 @@ class TestGerritVerifyStatusPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.reporter_test_props = {'gerrit_changes': [{'change_id': 12, 'revision_id': 2}]} @@ -57,8 +57,10 @@ def createGerritStatus(self, **kwargs): self.sp = GerritVerifyStatusPush("gerrit", auth=auth, **kwargs) yield self.sp.setServiceParent(self.master) + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_basic(self): diff --git a/master/buildbot/test/unit/reporters/test_github.py b/master/buildbot/test/unit/reporters/test_github.py index ad12f786f36..988fab2422b 100644 --- a/master/buildbot/test/unit/reporters/test_github.py +++ b/master/buildbot/test/unit/reporters/test_github.py @@ -35,7 +35,7 @@ class TestGitHubStatusPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() # project must be in the form / @@ -58,8 +58,10 @@ def setUp(self): def createService(self): return GitHubStatusPush(Interpolate('XXYYZZ')) + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_basic(self): @@ -300,7 +302,7 @@ def test_multiple_source_stamps_no_props(self): class TestGitHubStatusPushURL(TestReactorMixin, unittest.TestCase, ReporterTestMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() # project must be in the form / @@ -324,8 +326,10 @@ def setUp(self): def createService(self): return GitHubStatusPush('XXYYZZ') + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_ssh(self): diff --git a/master/buildbot/test/unit/reporters/test_gitlab.py b/master/buildbot/test/unit/reporters/test_gitlab.py index 1847452ef89..e0df58331ea 100644 --- a/master/buildbot/test/unit/reporters/test_gitlab.py +++ b/master/buildbot/test/unit/reporters/test_gitlab.py @@ -38,7 +38,7 @@ class TestGitLabStatusPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() # repository must be in the form http://gitlab// @@ -68,8 +68,10 @@ def setup_properties(props): builder.setup_properties = setup_properties self.master.botmaster.getBuilderById = mock.Mock(return_value=builder) + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_buildrequest(self): diff --git a/master/buildbot/test/unit/reporters/test_http.py b/master/buildbot/test/unit/reporters/test_http.py index 5beed2956ac..9f6e9bc2186 100644 --- a/master/buildbot/test/unit/reporters/test_http.py +++ b/master/buildbot/test/unit/reporters/test_http.py @@ -30,7 +30,7 @@ class TestHttpStatusPush(TestReactorMixin, unittest.TestCase, ReporterTestMixin, ConfigErrorsMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) yield self.master.startService() @@ -53,6 +53,7 @@ def createReporter(self, auth=("username", "passwd"), headers=None, **kwargs): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_basic(self): diff --git a/master/buildbot/test/unit/reporters/test_mail.py b/master/buildbot/test/unit/reporters/test_mail.py index 780d1fc8405..d80fc82dabe 100644 --- a/master/buildbot/test/unit/reporters/test_mail.py +++ b/master/buildbot/test/unit/reporters/test_mail.py @@ -41,10 +41,14 @@ class TestMailNotifier(ConfigErrorsMixin, TestReactorMixin, unittest.TestCase, ReporterTestMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setupMailNotifier(self, *args, **kwargs): mn = MailNotifier(*args, **kwargs) diff --git a/master/buildbot/test/unit/reporters/test_message.py b/master/buildbot/test/unit/reporters/test_message.py index 83400e0d04e..bd8c4820711 100644 --- a/master/buildbot/test/unit/reporters/test_message.py +++ b/master/buildbot/test/unit/reporters/test_message.py @@ -160,9 +160,13 @@ def test_get_message_source_stamp_text_with_props(self): class MessageFormatterTestBase(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setup_db(self, results1, results2, with_steps=False, extra_build_properties=None): if extra_build_properties is None: diff --git a/master/buildbot/test/unit/reporters/test_pushjet.py b/master/buildbot/test/unit/reporters/test_pushjet.py index 556cf7a7752..fb11bf42175 100644 --- a/master/buildbot/test/unit/reporters/test_pushjet.py +++ b/master/buildbot/test/unit/reporters/test_pushjet.py @@ -34,9 +34,13 @@ class TestPushjetNotifier(ConfigErrorsMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + # returns a Deferred def setupFakeHttp(self, base_url='https://api.pushjet.io'): return fakehttpclientservice.HTTPClientService.getService(self.master, self, base_url) diff --git a/master/buildbot/test/unit/reporters/test_pushover.py b/master/buildbot/test/unit/reporters/test_pushover.py index 09145925ead..797b396e375 100644 --- a/master/buildbot/test/unit/reporters/test_pushover.py +++ b/master/buildbot/test/unit/reporters/test_pushover.py @@ -34,9 +34,13 @@ class TestPushoverNotifier(ConfigErrorsMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + # returns a Deferred def setupFakeHttp(self): return fakehttpclientservice.HTTPClientService.getService( diff --git a/master/buildbot/test/unit/reporters/test_telegram.py b/master/buildbot/test/unit/reporters/test_telegram.py index cddfe95fb56..5dc4a019620 100644 --- a/master/buildbot/test/unit/reporters/test_telegram.py +++ b/master/buildbot/test/unit/reporters/test_telegram.py @@ -554,11 +554,15 @@ class TestTelegramService(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.patch(reactor, 'callLater', self.reactor.callLater) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) self.http = None + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setup_http_service(self): self.http = yield fakehttpclientservice.HTTPClientService.getService( diff --git a/master/buildbot/test/unit/reporters/test_utils.py b/master/buildbot/test/unit/reporters/test_utils.py index 3783d52fd44..6e3471cf6bc 100644 --- a/master/buildbot/test/unit/reporters/test_utils.py +++ b/master/buildbot/test/unit/reporters/test_utils.py @@ -39,9 +39,13 @@ class TestDataUtils(TestReactorMixin, unittest.TestCase, logging.LoggingMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setupDb(self): self.db = self.master.db @@ -612,9 +616,13 @@ def test_getPreviousBuildWithRetry(self): class TestURLUtils(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_UrlForBuild(self): self.assertEqual( utils.getURLForBuild(self.master, 1, 3), 'http://localhost:8080/#/builders/1/builds/3' diff --git a/master/buildbot/test/unit/reporters/test_words.py b/master/buildbot/test/unit/reporters/test_words.py index cdda6cc6fe9..22ed43f295c 100644 --- a/master/buildbot/test/unit/reporters/test_words.py +++ b/master/buildbot/test/unit/reporters/test_words.py @@ -48,7 +48,7 @@ class ContactMixin(TestReactorMixin): @defer.inlineCallbacks def setUp(self) -> Generator[Any, None, None]: - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.patch(reactor, 'callLater', self.reactor.callLater) self.patch(reactor, 'seconds', self.reactor.seconds) self.patch(reactor, 'stop', self.reactor.stop) @@ -88,6 +88,10 @@ def cancelCleanShutdown(): yield self.contact.channel.setServiceParent(self.master) yield self.master.startService() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def patch_send(self): self.sent = [] diff --git a/master/buildbot/test/unit/reporters/test_zulip.py b/master/buildbot/test/unit/reporters/test_zulip.py index 3a91d5a622b..2df5270271c 100644 --- a/master/buildbot/test/unit/reporters/test_zulip.py +++ b/master/buildbot/test/unit/reporters/test_zulip.py @@ -30,7 +30,7 @@ class TestZulipStatusPush( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_reporter_test() self.master = yield fakemaster.make_master( testcase=self, wantData=True, wantDb=True, wantMq=True @@ -40,6 +40,7 @@ def setUp(self): def tearDown(self): if self.master.running: yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def setupZulipStatusPush(self, endpoint="http://example.com", token="123", stream=None): diff --git a/master/buildbot/test/unit/schedulers/test_base.py b/master/buildbot/test/unit/schedulers/test_base.py index 1244185a9f2..2fc413dfa76 100644 --- a/master/buildbot/test/unit/schedulers/test_base.py +++ b/master/buildbot/test/unit/schedulers/test_base.py @@ -37,11 +37,13 @@ class BaseScheduler(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCas @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): - self.tearDownScheduler() + yield self.tearDownScheduler() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def makeScheduler(self, name='testsched', builderNames=None, properties=None, codebases=None): diff --git a/master/buildbot/test/unit/schedulers/test_basic.py b/master/buildbot/test/unit/schedulers/test_basic.py index d708b866df7..0092e2f2e86 100644 --- a/master/buildbot/test/unit/schedulers/test_basic.py +++ b/master/buildbot/test/unit/schedulers/test_basic.py @@ -102,11 +102,13 @@ def getChangeClassificationsForTimer(self, sched_id, timer_name): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() # tests @@ -352,11 +354,13 @@ def mkch(self, **kwargs): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_constructor_no_reason(self): @@ -593,11 +597,13 @@ class AnyBranchScheduler( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() def test_constructor_branch_forbidden(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/schedulers/test_canceller.py b/master/buildbot/test/unit/schedulers/test_canceller.py index 2e14ab4b6db..05eb90259ed 100644 --- a/master/buildbot/test/unit/schedulers/test_canceller.py +++ b/master/buildbot/test/unit/schedulers/test_canceller.py @@ -49,7 +49,7 @@ def test_multiple_filters_on_builder(self, name, builder, props, expected): class TestOldBuildrequestTracker(unittest.TestCase, TestReactorMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) filter = _OldBuildFilterSet() ss_filter = SourceStampFilter( @@ -61,6 +61,10 @@ def setUp(self): self.reactor, filter, lambda ss: ss['branch'], self.on_cancel ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def on_cancel(self, brid): self.cancellations.append(brid) @@ -384,7 +388,7 @@ def test_check_builders_keys_not_list(self, name, value, error): class TestOldBuildCanceller(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) self.master.mq.verifyMessages = False @@ -393,8 +397,10 @@ def setUp(self): yield self.master.startService() + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() def create_ss_dict(self, project, codebase, repository, branch): # Changes have the same structure for the attributes that we're using, so we reuse this diff --git a/master/buildbot/test/unit/schedulers/test_canceller_buildset.py b/master/buildbot/test/unit/schedulers/test_canceller_buildset.py index 9fceaa9ea27..fb54cbdbd9b 100644 --- a/master/buildbot/test/unit/schedulers/test_canceller_buildset.py +++ b/master/buildbot/test/unit/schedulers/test_canceller_buildset.py @@ -28,7 +28,7 @@ class TestOldBuildCanceller(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) self.master.mq.verifyMessages = False @@ -37,8 +37,10 @@ def setUp(self): yield self.master.startService() + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def insert_test_data(self): diff --git a/master/buildbot/test/unit/schedulers/test_dependent.py b/master/buildbot/test/unit/schedulers/test_dependent.py index afebea77f4a..ab0e8dc38b5 100644 --- a/master/buildbot/test/unit/schedulers/test_dependent.py +++ b/master/buildbot/test/unit/schedulers/test_dependent.py @@ -38,11 +38,13 @@ class Dependent(scheduler.SchedulerMixin, TestReactorMixin, StateTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def makeScheduler(self, upstream=None): diff --git a/master/buildbot/test/unit/schedulers/test_forcesched.py b/master/buildbot/test/unit/schedulers/test_forcesched.py index 317da38a7e9..58178ea1212 100644 --- a/master/buildbot/test/unit/schedulers/test_forcesched.py +++ b/master/buildbot/test/unit/schedulers/test_forcesched.py @@ -48,11 +48,13 @@ class TestForceScheduler( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def makeScheduler(self, name='testsched', builderNames=None, **kw): diff --git a/master/buildbot/test/unit/schedulers/test_timed_Nightly.py b/master/buildbot/test/unit/schedulers/test_timed_Nightly.py index 7aad90e65e9..6483d7e6f52 100644 --- a/master/buildbot/test/unit/schedulers/test_timed_Nightly.py +++ b/master/buildbot/test/unit/schedulers/test_timed_Nightly.py @@ -116,11 +116,13 @@ def mkch(self, **kwargs): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() def assertConsumingChanges(self, **kwargs): self.assertEqual(self.consumingChanges, kwargs) diff --git a/master/buildbot/test/unit/schedulers/test_timed_NightlyBase.py b/master/buildbot/test/unit/schedulers/test_timed_NightlyBase.py index 254172b3f96..3fd200a3026 100644 --- a/master/buildbot/test/unit/schedulers/test_timed_NightlyBase.py +++ b/master/buildbot/test/unit/schedulers/test_timed_NightlyBase.py @@ -31,9 +31,14 @@ class NightlyBase(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase) @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks + def tearDown(self): + self.tearDownScheduler() + yield self.tear_down_test_reactor() + def makeScheduler(self, firstBuildDuration=0, **kwargs): return self.attachScheduler(timed.NightlyBase(**kwargs), self.OBJECTID, self.SCHEDULERID) diff --git a/master/buildbot/test/unit/schedulers/test_timed_NightlyTriggerable.py b/master/buildbot/test/unit/schedulers/test_timed_NightlyTriggerable.py index cc19fdcff7d..0f780873c77 100644 --- a/master/buildbot/test/unit/schedulers/test_timed_NightlyTriggerable.py +++ b/master/buildbot/test/unit/schedulers/test_timed_NightlyTriggerable.py @@ -48,11 +48,13 @@ def makeScheduler(self, firstBuildDuration=0, **kwargs): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() # utilities diff --git a/master/buildbot/test/unit/schedulers/test_timed_Periodic.py b/master/buildbot/test/unit/schedulers/test_timed_Periodic.py index e6cd9c5bcdf..a7bba89b470 100644 --- a/master/buildbot/test/unit/schedulers/test_timed_Periodic.py +++ b/master/buildbot/test/unit/schedulers/test_timed_Periodic.py @@ -33,9 +33,14 @@ class Periodic(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks + def tearDown(self): + self.tearDownScheduler() + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def makeScheduler(self, firstBuildDuration=0, firstBuildError=False, exp_branch=None, **kwargs): self.sched = sched = timed.Periodic(**kwargs) diff --git a/master/buildbot/test/unit/schedulers/test_timed_Timed.py b/master/buildbot/test/unit/schedulers/test_timed_Timed.py index 517ec0b6a53..6545faf4fff 100644 --- a/master/buildbot/test/unit/schedulers/test_timed_Timed.py +++ b/master/buildbot/test/unit/schedulers/test_timed_Timed.py @@ -27,11 +27,13 @@ class Timed(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() class Subclass(timed.Timed): def getNextBuildTime(self, lastActuation): diff --git a/master/buildbot/test/unit/schedulers/test_triggerable.py b/master/buildbot/test/unit/schedulers/test_triggerable.py index 6ca1b0b83b8..df972260d29 100644 --- a/master/buildbot/test/unit/schedulers/test_triggerable.py +++ b/master/buildbot/test/unit/schedulers/test_triggerable.py @@ -38,15 +38,17 @@ class Triggerable(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase) @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) # Necessary to get an assertable submitted_at time. self.reactor.advance(946684799) yield self.setUpScheduler() self.subscription = None + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def makeScheduler(self, overrideBuildsetMethods=False, **kwargs): diff --git a/master/buildbot/test/unit/schedulers/test_trysched.py b/master/buildbot/test/unit/schedulers/test_trysched.py index b8ebec2501e..7facba036b6 100644 --- a/master/buildbot/test/unit/schedulers/test_trysched.py +++ b/master/buildbot/test/unit/schedulers/test_trysched.py @@ -35,11 +35,13 @@ class TryBase(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() def makeScheduler(self, **kwargs): return self.attachScheduler( @@ -130,14 +132,16 @@ class Try_Jobdir(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() self.jobdir = None + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() if self.jobdir: shutil.rmtree(self.jobdir) + yield self.tear_down_test_reactor() # tests @@ -874,11 +878,13 @@ class Try_Userpass_Perspective(scheduler.SchedulerMixin, TestReactorMixin, unitt @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() def makeScheduler(self, **kwargs): return self.attachScheduler( @@ -1051,11 +1057,13 @@ class Try_Userpass(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpScheduler() + @defer.inlineCallbacks def tearDown(self): self.tearDownScheduler() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def makeScheduler(self, **kwargs): diff --git a/master/buildbot/test/unit/scripts/test_cleanupdb.py b/master/buildbot/test/unit/scripts/test_cleanupdb.py index 12ac70333ac..613ed953f56 100644 --- a/master/buildbot/test/unit/scripts/test_cleanupdb.py +++ b/master/buildbot/test/unit/scripts/test_cleanupdb.py @@ -78,7 +78,7 @@ class TestCleanupDb( misc.StdoutAssertionsMixin, dirs.DirsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpDirs('basedir') with open(os.path.join('basedir', 'buildbot.tac'), "w", encoding='utf-8') as f: f.write( @@ -90,8 +90,10 @@ def setUp(self): self.setUpStdoutAssertions() self.ensureNoSqliteMemory() + @defer.inlineCallbacks def tearDown(self): self.tearDownDirs() + yield self.tear_down_test_reactor() def ensureNoSqliteMemory(self): # test may use mysql or pg if configured in env diff --git a/master/buildbot/test/unit/scripts/test_create_master.py b/master/buildbot/test/unit/scripts/test_create_master.py index 1bfb30af62d..b3171d419e7 100644 --- a/master/buildbot/test/unit/scripts/test_create_master.py +++ b/master/buildbot/test/unit/scripts/test_create_master.py @@ -91,13 +91,15 @@ class TestCreateMasterFunctions( unittest.TestCase, ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpDirs('test') self.basedir = os.path.abspath(os.path.join('test', 'basedir')) self.setUpStdoutAssertions() + @defer.inlineCallbacks def tearDown(self): self.tearDownDirs() + yield self.tear_down_test_reactor() def assertInTacFile(self, str): with open(os.path.join('test', 'buildbot.tac'), encoding='utf-8') as f: diff --git a/master/buildbot/test/unit/scripts/test_logwatcher.py b/master/buildbot/test/unit/scripts/test_logwatcher.py index 8eafcbd375d..e9fdd2d8704 100644 --- a/master/buildbot/test/unit/scripts/test_logwatcher.py +++ b/master/buildbot/test/unit/scripts/test_logwatcher.py @@ -48,10 +48,14 @@ def setUp(self): self.setUpDirs('workdir') self.addCleanup(self.tearDownDirs) - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.spawned_process = mock.Mock() self.reactor.spawnProcess = mock.Mock(return_value=self.spawned_process) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_start(self): lw = MockedLogWatcher('workdir/test.log', _reactor=self.reactor) lw._start = mock.Mock() diff --git a/master/buildbot/test/unit/scripts/test_upgrade_master.py b/master/buildbot/test/unit/scripts/test_upgrade_master.py index 4a82eeea15b..0f273e02ced 100644 --- a/master/buildbot/test/unit/scripts/test_upgrade_master.py +++ b/master/buildbot/test/unit/scripts/test_upgrade_master.py @@ -114,13 +114,15 @@ class TestUpgradeMasterFunctions( unittest.TestCase, ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpDirs('test') self.basedir = os.path.abspath(os.path.join('test', 'basedir')) self.setUpStdoutAssertions() + @defer.inlineCallbacks def tearDown(self): self.tearDownDirs() + yield self.tear_down_test_reactor() def writeFile(self, path, contents): with open(path, "w", encoding='utf-8') as f: diff --git a/master/buildbot/test/unit/steps/test_cmake.py b/master/buildbot/test/unit/steps/test_cmake.py index 75fe023bf4e..d40f760352e 100644 --- a/master/buildbot/test/unit/steps/test_cmake.py +++ b/master/buildbot/test/unit/steps/test_cmake.py @@ -28,11 +28,13 @@ class TestCMake(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def expect_and_run_command(self, *params): command = [CMake.DEFAULT_CMAKE, *list(params)] diff --git a/master/buildbot/test/unit/steps/test_cppcheck.py b/master/buildbot/test/unit/steps/test_cppcheck.py index e89f0aa0eb2..3a894063361 100644 --- a/master/buildbot/test/unit/steps/test_cppcheck.py +++ b/master/buildbot/test/unit/steps/test_cppcheck.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.properties import WithProperties @@ -27,11 +28,13 @@ class Cppcheck(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_success(self): self.setup_step(cppcheck.Cppcheck(enable=['all'], inconclusive=True)) diff --git a/master/buildbot/test/unit/steps/test_http.py b/master/buildbot/test/unit/steps/test_http.py index cd813e21db4..fd139603089 100644 --- a/master/buildbot/test/unit/steps/test_http.py +++ b/master/buildbot/test/unit/steps/test_http.py @@ -66,7 +66,7 @@ def render_POST(self, request): class TestHTTPStep(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) if txrequests is None: raise unittest.SkipTest("Need to install txrequests to test http steps") @@ -89,6 +89,7 @@ def tearDown(self): yield self.site.close_connections() finally: yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def get_connection_string(self): return f"http://127.0.0.1:{self.port}" diff --git a/master/buildbot/test/unit/steps/test_master.py b/master/buildbot/test/unit/steps/test_master.py index 61d483c4a1c..3e79ee2566f 100644 --- a/master/buildbot/test/unit/steps/test_master.py +++ b/master/buildbot/test/unit/steps/test_master.py @@ -36,19 +36,21 @@ class TestMasterShellCommand(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) if runtime.platformType == 'win32': self.comspec = os.environ.get(_COMSPEC_ENV) os.environ[_COMSPEC_ENV] = r'C:\WINDOWS\system32\cmd.exe' return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): if runtime.platformType == 'win32': if self.comspec: os.environ[_COMSPEC_ENV] = self.comspec else: del os.environ[_COMSPEC_ENV] - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_constr_args(self): self.setup_step( @@ -168,11 +170,13 @@ def test_constr_args_descriptionSuffix(self): class TestSetProperty(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_simple(self): self.setup_step( @@ -190,11 +194,13 @@ def test_simple(self): class TestLogRenderable(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_simple(self): self.setup_step( @@ -211,11 +217,13 @@ def test_simple(self): class TestsSetProperties(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def doOneTest(self, **kwargs): # all three tests should create a 'a' property with 'b' value, all with different @@ -242,11 +250,13 @@ def manipulate(props): class TestAssert(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_eq_pass(self): self.setup_step(master.Assert(Property("test_prop") == "foo")) diff --git a/master/buildbot/test/unit/steps/test_maxq.py b/master/buildbot/test/unit/steps/test_maxq.py index 208679462b0..a548c422141 100644 --- a/master/buildbot/test/unit/steps/test_maxq.py +++ b/master/buildbot/test/unit/steps/test_maxq.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot import config @@ -26,11 +27,13 @@ class TestShellCommandExecution(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_testdir_required(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_mswin.py b/master/buildbot/test/unit/steps/test_mswin.py index ab3f192afc9..42314014f67 100644 --- a/master/buildbot/test/unit/steps/test_mswin.py +++ b/master/buildbot/test/unit/steps/test_mswin.py @@ -35,11 +35,13 @@ class TestRobocopySimple(TestBuildStepMixin, TestReactorMixin, unittest.TestCase """ def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def _run_simple_test( self, diff --git a/master/buildbot/test/unit/steps/test_package_deb_lintian.py b/master/buildbot/test/unit/steps/test_package_deb_lintian.py index 46ed38376fa..52910777aab 100644 --- a/master/buildbot/test/unit/steps/test_package_deb_lintian.py +++ b/master/buildbot/test/unit/steps/test_package_deb_lintian.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot import config @@ -25,11 +26,13 @@ class TestDebLintian(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_fileloc(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_package_deb_pbuilder.py b/master/buildbot/test/unit/steps/test_package_deb_pbuilder.py index 6173b6752c6..03f059dd71e 100644 --- a/master/buildbot/test/unit/steps/test_package_deb_pbuilder.py +++ b/master/buildbot/test/unit/steps/test_package_deb_pbuilder.py @@ -15,6 +15,7 @@ import time +from twisted.internet import defer from twisted.trial import unittest from buildbot import config @@ -30,11 +31,13 @@ class TestDebPbuilder(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_new(self): self.setup_step(pbuilder.DebPbuilder()) @@ -488,11 +491,13 @@ def test_othermirror(self): class TestDebCowbuilder(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_new(self): self.setup_step(pbuilder.DebCowbuilder()) @@ -639,11 +644,13 @@ def test_buildonly_reg(self): class TestUbuPbuilder(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_distribution(self): with self.assertRaises(config.ConfigErrors): @@ -691,11 +698,13 @@ def test_new(self): class TestUbuCowbuilder(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_distribution(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_package_rpm_mock.py b/master/buildbot/test/unit/steps/test_package_rpm_mock.py index 6eb7f189c03..22a3022c273 100644 --- a/master/buildbot/test/unit/steps/test_package_rpm_mock.py +++ b/master/buildbot/test/unit/steps/test_package_rpm_mock.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot import config @@ -27,7 +28,7 @@ class TestMock(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() def tearDown(self): @@ -108,11 +109,13 @@ def test_resultdir_renderable(self): class TestMockBuildSRPM(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_spec(self): with self.assertRaises(config.ConfigErrors): @@ -149,11 +152,13 @@ def test_success(self): class TestMockRebuild(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_srpm(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_package_rpm_rpmbuild.py b/master/buildbot/test/unit/steps/test_package_rpm_rpmbuild.py index 3f5e904bc25..fbca59aa42f 100644 --- a/master/buildbot/test/unit/steps/test_package_rpm_rpmbuild.py +++ b/master/buildbot/test/unit/steps/test_package_rpm_rpmbuild.py @@ -30,11 +30,13 @@ class RpmBuild(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_specfile(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_package_rpm_rpmlint.py b/master/buildbot/test/unit/steps/test_package_rpm_rpmlint.py index 19e93d4e41e..d633b126a30 100644 --- a/master/buildbot/test/unit/steps/test_package_rpm_rpmlint.py +++ b/master/buildbot/test/unit/steps/test_package_rpm_rpmlint.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.results import SUCCESS @@ -24,11 +25,13 @@ class TestRpmLint(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_success(self): self.setup_step(rpmlint.RpmLint()) diff --git a/master/buildbot/test/unit/steps/test_python.py b/master/buildbot/test/unit/steps/test_python.py index 79cc9c76189..437af94a89c 100644 --- a/master/buildbot/test/unit/steps/test_python.py +++ b/master/buildbot/test/unit/steps/test_python.py @@ -125,11 +125,13 @@ class BuildEPYDoc(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_sample(self): self.setup_step(python.BuildEPYDoc()) @@ -142,11 +144,13 @@ def test_sample(self): class PyLint(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @parameterized.expand([('no_results', True), ('with_results', False)]) def test_success(self, name, store_results): @@ -439,11 +443,13 @@ def test_regex_parseable_1_3_1(self): class PyFlakes(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_success(self): self.setup_step(python.PyFlakes()) @@ -525,11 +531,13 @@ def test_misc(self): class TestSphinx(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_builddir_required(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_python_twisted.py b/master/buildbot/test/unit/steps/test_python_twisted.py index 6c00c4554d5..0c5366596d8 100644 --- a/master/buildbot/test/unit/steps/test_python_twisted.py +++ b/master/buildbot/test/unit/steps/test_python_twisted.py @@ -15,6 +15,7 @@ import textwrap +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.properties import Property @@ -93,11 +94,13 @@ class Trial(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_run_env(self): self.setup_step( @@ -397,11 +400,13 @@ def test_run_jobsProperties(self): class HLint(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_run_ok(self): self.setup_build(build_files=['foo.xhtml']) @@ -466,11 +471,13 @@ def test_run_warnings(self): class RemovePYCs(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_run_ok(self): self.setup_step(python_twisted.RemovePYCs()) diff --git a/master/buildbot/test/unit/steps/test_renderable.py b/master/buildbot/test/unit/steps/test_renderable.py index cd9090b951b..d24407cfb69 100644 --- a/master/buildbot/test/unit/steps/test_renderable.py +++ b/master/buildbot/test/unit/steps/test_renderable.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.buildstep import BuildStep @@ -32,11 +33,13 @@ class TestBuildStepNameIsRenderable( TestBuildStepMixin, unittest.TestCase, TestReactorMixin, configmixin.ConfigErrorsMixin ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_name_is_renderable(self): step = TestBuildStep(name=Interpolate('%(kw:foo)s', foo='bar')) diff --git a/master/buildbot/test/unit/steps/test_shell.py b/master/buildbot/test/unit/steps/test_shell.py index 8a4f449628c..f8cf6e7951d 100644 --- a/master/buildbot/test/unit/steps/test_shell.py +++ b/master/buildbot/test/unit/steps/test_shell.py @@ -40,11 +40,13 @@ class TestShellCommandExecution( TestBuildStepMixin, configmixin.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_doStepIf_False(self): self.setup_step(shell.ShellCommand(command="echo hello", doStepIf=False)) @@ -180,11 +182,13 @@ def test_missing_command_error(self): class TreeSize(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_run_success(self): self.setup_step(shell.TreeSize()) @@ -216,11 +220,13 @@ def test_run_failed(self): class SetPropertyFromCommand(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_constructor_conflict(self): with self.assertRaises(config.ConfigErrors): @@ -349,11 +355,13 @@ def test_error_none_set(self): class PerlModuleTest(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_new_version_success(self): self.setup_step(shell.PerlModuleTest(command="cmd")) @@ -462,11 +470,13 @@ def test_old_version_failed(self): class Configure(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_class_attrs(self): step = shell.Configure() @@ -484,11 +494,13 @@ class WarningCountingShellCommand( TestBuildStepMixin, configmixin.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_no_warnings(self): self.setup_step(shell.WarningCountingShellCommand(workdir='w', command=['make'])) @@ -812,11 +824,13 @@ def test_missing_command_error(self): class Compile(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_class_args(self): # since this step is just a pre-configured WarningCountingShellCommand, @@ -832,11 +846,13 @@ def test_class_args(self): class Test(TestBuildStepMixin, configmixin.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_setTestResults(self): step = self.setup_step(shell.Test()) diff --git a/master/buildbot/test/unit/steps/test_shellsequence.py b/master/buildbot/test/unit/steps/test_shellsequence.py index 66eff46e848..e8b84b599f1 100644 --- a/master/buildbot/test/unit/steps/test_shellsequence.py +++ b/master/buildbot/test/unit/steps/test_shellsequence.py @@ -38,7 +38,7 @@ class TestOneShellCommand( TestBuildStepMixin, configmixin.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() def tearDown(self): diff --git a/master/buildbot/test/unit/steps/test_source_base_Source.py b/master/buildbot/test/unit/steps/test_source_base_Source.py index 056900a48b6..6efd4e437b4 100644 --- a/master/buildbot/test/unit/steps/test_source_base_Source.py +++ b/master/buildbot/test/unit/steps/test_source_base_Source.py @@ -32,11 +32,13 @@ def startVC(self): class TestSource(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def setup_deferred_mock(self): m = mock.Mock() @@ -168,11 +170,13 @@ def test_old_style_source_step_throws_exception(self): class TestSourceDescription(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_constructor_args_strings(self): step = Source( @@ -204,11 +208,13 @@ def mode_incremental(self): class TestSourceAttrGroup(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_attrgroup_hasattr(self): step = AttrGroup() diff --git a/master/buildbot/test/unit/steps/test_source_bzr.py b/master/buildbot/test/unit/steps/test_source_bzr.py index 7d8c8a40b47..ac5bbb9a079 100644 --- a/master/buildbot/test/unit/steps/test_source_bzr.py +++ b/master/buildbot/test/unit/steps/test_source_bzr.py @@ -16,6 +16,7 @@ import os +from twisted.internet import defer from twisted.internet import error from twisted.python.reflect import namedModule from twisted.trial import unittest @@ -37,11 +38,13 @@ class TestBzr(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def test_mode_full(self): self.setup_step( diff --git a/master/buildbot/test/unit/steps/test_source_cvs.py b/master/buildbot/test/unit/steps/test_source_cvs.py index fd428b0579f..199563f3ce6 100644 --- a/master/buildbot/test/unit/steps/test_source_cvs.py +++ b/master/buildbot/test/unit/steps/test_source_cvs.py @@ -15,6 +15,7 @@ import time +from twisted.internet import defer from twisted.internet import error from twisted.trial import unittest @@ -37,11 +38,13 @@ class TestCVS(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def setup_step(self, step, *args, **kwargs): super().setup_step(step, *args, **kwargs) diff --git a/master/buildbot/test/unit/steps/test_source_darcs.py b/master/buildbot/test/unit/steps/test_source_darcs.py index 43116dfe224..393bd8c5ae1 100644 --- a/master/buildbot/test/unit/steps/test_source_darcs.py +++ b/master/buildbot/test/unit/steps/test_source_darcs.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.internet import error from twisted.trial import unittest @@ -33,11 +34,13 @@ class TestDarcs(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def test_no_empty_step_config(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/steps/test_source_gerrit.py b/master/buildbot/test/unit/steps/test_source_gerrit.py index 0ef8505b31b..211f9f50f79 100644 --- a/master/buildbot/test/unit/steps/test_source_gerrit.py +++ b/master/buildbot/test/unit/steps/test_source_gerrit.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.results import SUCCESS @@ -29,11 +30,13 @@ class TestGerrit( sourcesteps.SourceStepMixin, config.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def test_mode_full_clean(self): self.setup_step( diff --git a/master/buildbot/test/unit/steps/test_source_git.py b/master/buildbot/test/unit/steps/test_source_git.py index 17a1b3113d3..5e7ebe91d3a 100644 --- a/master/buildbot/test/unit/steps/test_source_git.py +++ b/master/buildbot/test/unit/steps/test_source_git.py @@ -48,12 +48,14 @@ class TestGit( stepClass = git.Git def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.sourceName = self.stepClass.__name__ return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def test_mode_full_filters_2_26(self): self.setup_step( @@ -4185,7 +4187,7 @@ class TestGitPush( stepClass = git.GitPush def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() def tearDown(self): @@ -4668,7 +4670,7 @@ class TestGitTag(TestBuildStepMixin, config.ConfigErrorsMixin, TestReactorMixin, stepClass = git.GitTag def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() def tearDown(self): @@ -4764,14 +4766,16 @@ class TestGitCommit( stepClass = git.GitCommit def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.message_list = ['my commit', '42'] self.path_list = ['file1.txt', 'file2.txt'] return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_add_fail(self): self.setup_step( diff --git a/master/buildbot/test/unit/steps/test_source_gitlab.py b/master/buildbot/test/unit/steps/test_source_gitlab.py index bf83370fd36..3c6e1f0b021 100644 --- a/master/buildbot/test/unit/steps/test_source_gitlab.py +++ b/master/buildbot/test/unit/steps/test_source_gitlab.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.results import SUCCESS @@ -31,7 +32,7 @@ class TestGitLab( stepClass = gitlab.GitLab def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.sourceName = self.stepClass.__name__ return self.setUpSourceStep() @@ -53,8 +54,10 @@ def setup_step(self, step, args, **kwargs): step.build.properties.setProperty("target_project_id", 239, "gitlab target project ID") return step + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def test_with_merge_branch(self): self.setup_step( diff --git a/master/buildbot/test/unit/steps/test_source_mercurial.py b/master/buildbot/test/unit/steps/test_source_mercurial.py index 66ff7a8d072..478e920d73a 100644 --- a/master/buildbot/test/unit/steps/test_source_mercurial.py +++ b/master/buildbot/test/unit/steps/test_source_mercurial.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.internet import error from twisted.python.reflect import namedModule from twisted.trial import unittest @@ -34,11 +35,13 @@ class TestMercurial(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def patch_workerVersionIsOlderThan(self, result): self.patch(mercurial.Mercurial, 'workerVersionIsOlderThan', lambda x, y, z: result) diff --git a/master/buildbot/test/unit/steps/test_source_mtn.py b/master/buildbot/test/unit/steps/test_source_mtn.py index 4e5b3793083..b6378097936 100644 --- a/master/buildbot/test/unit/steps/test_source_mtn.py +++ b/master/buildbot/test/unit/steps/test_source_mtn.py @@ -14,6 +14,7 @@ # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.internet import error from twisted.trial import unittest @@ -41,11 +42,13 @@ class TestMonotone( MTN_VER = 'monotone 1.0 (base revision: UNKNOWN_REV)' def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def test_mode_full_clean(self): self.setup_step( diff --git a/master/buildbot/test/unit/steps/test_source_p4.py b/master/buildbot/test/unit/steps/test_source_p4.py index b75c59dd0cb..e33b41a2843 100644 --- a/master/buildbot/test/unit/steps/test_source_p4.py +++ b/master/buildbot/test/unit/steps/test_source_p4.py @@ -17,6 +17,7 @@ import platform import textwrap +from twisted.internet import defer from twisted.internet import error from twisted.python import reflect from twisted.trial import unittest @@ -36,11 +37,13 @@ class TestP4(sourcesteps.SourceStepMixin, TestReactorMixin, ConfigErrorsMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def setup_step(self, step, args=None, patch=None, **kwargs): if args is None: diff --git a/master/buildbot/test/unit/steps/test_source_repo.py b/master/buildbot/test/unit/steps/test_source_repo.py index 15c6685f8f8..10f5d2f9b00 100644 --- a/master/buildbot/test/unit/steps/test_source_repo.py +++ b/master/buildbot/test/unit/steps/test_source_repo.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.changes.changes import Change @@ -60,13 +61,15 @@ def test_parse3(self): class TestRepo(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.shouldRetry = False self.logEnviron = True return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def shouldLogEnviron(self): r = self.logEnviron diff --git a/master/buildbot/test/unit/steps/test_source_svn.py b/master/buildbot/test/unit/steps/test_source_svn.py index 7acb85c21ff..921c8902c59 100644 --- a/master/buildbot/test/unit/steps/test_source_svn.py +++ b/master/buildbot/test/unit/steps/test_source_svn.py @@ -121,11 +121,13 @@ class TestSVN(sourcesteps.SourceStepMixin, TestReactorMixin, unittest.TestCase): """ def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setUpSourceStep() + @defer.inlineCallbacks def tearDown(self): - return self.tearDownSourceStep() + yield self.tearDownSourceStep() + yield self.tear_down_test_reactor() def patch_workerVersionIsOlderThan(self, result): self.patch(svn.SVN, 'workerVersionIsOlderThan', lambda x, y, z: result) diff --git a/master/buildbot/test/unit/steps/test_subunit.py b/master/buildbot/test/unit/steps/test_subunit.py index 0af83a07233..6ae22bbc245 100644 --- a/master/buildbot/test/unit/steps/test_subunit.py +++ b/master/buildbot/test/unit/steps/test_subunit.py @@ -17,6 +17,7 @@ import re import sys +from twisted.internet import defer from twisted.trial import unittest from buildbot.process.results import FAILURE @@ -55,11 +56,13 @@ def setUp(self): if TestProtocolClient is None: raise unittest.SkipTest("Need to install python-subunit to test subunit step") - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_empty(self): self.setup_step(subunit.SubunitShellCommand(command='test')) diff --git a/master/buildbot/test/unit/steps/test_transfer.py b/master/buildbot/test/unit/steps/test_transfer.py index 5faf8c3950a..4f92d22fd22 100644 --- a/master/buildbot/test/unit/steps/test_transfer.py +++ b/master/buildbot/test/unit/steps/test_transfer.py @@ -43,16 +43,18 @@ class TestFileUpload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) fd, self.destfile = tempfile.mkstemp() os.close(fd) os.unlink(self.destfile) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): if os.path.exists(self.destfile): os.unlink(self.destfile) - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def testConstructorModeType(self): with self.assertRaises(config.ConfigErrors): @@ -309,18 +311,20 @@ def test_init_positional_args(self): class TestDirectoryUpload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.destdir = os.path.abspath('destdir') if os.path.exists(self.destdir): shutil.rmtree(self.destdir) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): if os.path.exists(self.destdir): shutil.rmtree(self.destdir) - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def testBasic(self): self.setup_step(transfer.DirectoryUpload(workersrc="srcdir", masterdest=self.destdir)) @@ -493,18 +497,20 @@ def test_init_positional_args(self): class TestMultipleFileUpload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.destdir = os.path.abspath('destdir') if os.path.exists(self.destdir): shutil.rmtree(self.destdir) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): if os.path.exists(self.destdir): shutil.rmtree(self.destdir) - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def testEmpty(self): self.setup_step(transfer.MultipleFileUpload(workersrcs=[], masterdest=self.destdir)) @@ -936,16 +942,19 @@ def test_init_positional_args(self): class TestFileDownload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) fd, self.destfile = tempfile.mkstemp() os.close(fd) os.unlink(self.destfile) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): if os.path.exists(self.destfile): os.unlink(self.destfile) - return self.tear_down_test_build_step() + + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_init_workerdest_keyword(self): step = transfer.FileDownload(mastersrc='srcfile', workerdest='dstfile') @@ -1046,11 +1055,13 @@ def test_no_file(self): class TestStringDownload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() # check that ConfigErrors is raised on invalid 'mode' argument @@ -1154,11 +1165,13 @@ def test_init_positional_args(self): class TestJSONStringDownload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def testBasic(self): @@ -1255,11 +1268,13 @@ def test_init_positional_args(self): class TestJSONPropertiesDownload(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def testBasic(self): diff --git a/master/buildbot/test/unit/steps/test_trigger.py b/master/buildbot/test/unit/steps/test_trigger.py index 3a72992b08a..84d1757f8dd 100644 --- a/master/buildbot/test/unit/steps/test_trigger.py +++ b/master/buildbot/test/unit/steps/test_trigger.py @@ -100,11 +100,13 @@ def BRID_TO_BUILD_NUMBER(brid): class TestTrigger(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def setup_step(self, step, sourcestampsInBuild=None, gotRevisionsInBuild=None, *args, **kwargs): diff --git a/master/buildbot/test/unit/steps/test_vstudio.py b/master/buildbot/test/unit/steps/test_vstudio.py index 93c846c7a3f..1fb64daa743 100644 --- a/master/buildbot/test/unit/steps/test_vstudio.py +++ b/master/buildbot/test/unit/steps/test_vstudio.py @@ -228,11 +228,13 @@ class VisualStudio(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): """ def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_default_config(self): vs = vstudio.VisualStudio() @@ -349,11 +351,13 @@ def test_rendering(self): class TestVC6(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def getExpectedEnv(self, installdir, LIB=None, p=None, i=None): include = [ @@ -447,11 +451,13 @@ def test_env_prepend(self): class TestVC7(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def getExpectedEnv(self, installdir, LIB=None, p=None, i=None): include = [ @@ -582,11 +588,13 @@ def getExpectedEnv(self, installdir, x64=False, LIB=None, i=None, p=None): class TestVC8(VC8ExpectedEnvMixin, TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_args(self): self.setup_step(vstudio.VC8(projectfile='pf', config='cfg', project='pj', arch='arch')) @@ -643,11 +651,13 @@ def test_rendering(self): class TestVCExpress9(VC8ExpectedEnvMixin, TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_args(self): self.setup_step(vstudio.VCExpress9(projectfile='pf', config='cfg', project='pj')) @@ -700,11 +710,13 @@ def test_mode_build_env(self): class TestVC9(VC8ExpectedEnvMixin, TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_installdir(self): self.setup_step(vstudio.VC9(projectfile='pf', config='cfg', project='pj')) @@ -721,11 +733,13 @@ def test_installdir(self): class TestVC10(VC8ExpectedEnvMixin, TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_installdir(self): self.setup_step(vstudio.VC10(projectfile='pf', config='cfg', project='pj')) @@ -742,11 +756,13 @@ def test_installdir(self): class TestVC11(VC8ExpectedEnvMixin, TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_installdir(self): self.setup_step(vstudio.VC11(projectfile='pf', config='cfg', project='pj')) @@ -763,11 +779,13 @@ def test_installdir(self): class TestMsBuild(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_no_platform(self): @@ -865,11 +883,13 @@ def test_rebuild_solution(self): class TestMsBuild141(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_no_platform(self): @@ -985,11 +1005,13 @@ def test_aliases_MsBuild15(self): class TestMsBuild16(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_version_range_is_correct(self): self.setup_step( @@ -1012,11 +1034,13 @@ def test_version_range_is_correct(self): class TestMsBuild17(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_version_range_is_correct(self): self.setup_step( diff --git a/master/buildbot/test/unit/steps/test_worker.py b/master/buildbot/test/unit/steps/test_worker.py index 9a8da907ad9..cefa8e0693a 100644 --- a/master/buildbot/test/unit/steps/test_worker.py +++ b/master/buildbot/test/unit/steps/test_worker.py @@ -42,11 +42,13 @@ class TestSetPropertiesFromEnv(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_simple(self): self.setup_step( @@ -81,11 +83,13 @@ def test_case_folding(self): class TestFileExists(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_found(self): self.setup_step(worker.FileExists(file="x")) @@ -123,11 +127,13 @@ def test_old_version(self): class TestCopyDirectory(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_success(self): self.setup_step(worker.CopyDirectory(src="s", dest="d")) @@ -166,11 +172,13 @@ def test_render(self): class TestRemoveDirectory(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_success(self): self.setup_step(worker.RemoveDirectory(dir="d")) @@ -194,11 +202,13 @@ def test_render(self): class TestMakeDirectory(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_success(self): self.setup_step(worker.MakeDirectory(dir="d")) @@ -235,11 +245,13 @@ def run(self): class TestCompositeStepMixin(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_runRemoteCommand(self): cmd_args = ('foo', {'bar': False}) diff --git a/master/buildbot/test/unit/test_download_secret_to_worker.py b/master/buildbot/test/unit/test_download_secret_to_worker.py index fcd2bb11182..6d53bd9ec01 100644 --- a/master/buildbot/test/unit/test_download_secret_to_worker.py +++ b/master/buildbot/test/unit/test_download_secret_to_worker.py @@ -17,6 +17,7 @@ import os import stat +from twisted.internet import defer from twisted.python.filepath import FilePath from twisted.trial import unittest @@ -37,14 +38,16 @@ class TestDownloadFileSecretToWorkerCommand( TestBuildStepMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) tempdir = FilePath(self.mktemp()) tempdir.createDirectory() self.temp_path = tempdir.path return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def testBasic(self): self.setup_step( @@ -79,14 +82,16 @@ def testBasic(self): class TestRemoveWorkerFileSecretCommand30(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) tempdir = FilePath(self.mktemp()) tempdir.createDirectory() self.temp_path = tempdir.path return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def testBasic(self): self.setup_build(worker_version={'*': '3.0'}) @@ -119,14 +124,16 @@ class TestRemoveFileSecretToWorkerCommand( TestBuildStepMixin, configmixin.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) tempdir = FilePath(self.mktemp()) tempdir.createDirectory() self.temp_path = tempdir.path return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def testBasic(self): self.setup_step( diff --git a/master/buildbot/test/unit/test_fake_httpclientservice.py b/master/buildbot/test/unit/test_fake_httpclientservice.py index 19586fa8994..cd3dec8dc5f 100644 --- a/master/buildbot/test/unit/test_fake_httpclientservice.py +++ b/master/buildbot/test/unit/test_fake_httpclientservice.py @@ -43,7 +43,7 @@ def doGetRoot(self): class Test(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - yield self.setup_test_reactor() + yield self.setup_test_reactor(auto_tear_down=False) baseurl = 'http://127.0.0.1:8080' master = yield fakemaster.make_master(self) @@ -54,6 +54,10 @@ def setUp(self): yield self.tested.setServiceParent(master) yield master.startService() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_root(self): self._http.expect("get", "/", content_json={'foo': 'bar'}) diff --git a/master/buildbot/test/unit/test_fake_secrets_manager.py b/master/buildbot/test/unit/test_fake_secrets_manager.py index 2bd98574615..1f28dc0af8e 100644 --- a/master/buildbot/test/unit/test_fake_secrets_manager.py +++ b/master/buildbot/test/unit/test_fake_secrets_manager.py @@ -11,12 +11,16 @@ class TestSecretsManager(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.master.config.secretsProviders = [ FakeSecretStorage(secretdict={"foo": "bar", "other": "value"}) ] + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def testGetManagerService(self): secret_service_manager = SecretManager() diff --git a/master/buildbot/test/unit/test_interpolate_secrets.py b/master/buildbot/test/unit/test_interpolate_secrets.py index 449a4c0ef5e..ae882384edb 100644 --- a/master/buildbot/test/unit/test_interpolate_secrets.py +++ b/master/buildbot/test/unit/test_interpolate_secrets.py @@ -21,7 +21,7 @@ def __init__(self, master): class TestInterpolateSecrets(TestReactorMixin, unittest.TestCase, ConfigErrorsMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) fakeStorageService = FakeSecretStorage() fakeStorageService.reconfigService(secretdict={"foo": "bar", "other": "value"}) @@ -30,6 +30,10 @@ def setUp(self): yield self.secretsrv.setServiceParent(self.master) self.build = FakeBuildWithMaster(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_secret(self): command = Interpolate("echo %(secret:foo)s") @@ -48,10 +52,14 @@ def test_secret_not_found(self): class TestInterpolateSecretsNoService(TestReactorMixin, unittest.TestCase, ConfigErrorsMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.build = FakeBuildWithMaster(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_secret(self): command = Interpolate("echo %(secret:fuo)s") @@ -64,7 +72,7 @@ def test_secret(self): class TestInterpolateSecretsHiddenSecrets(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) fakeStorageService = FakeSecretStorage() password = "bar" @@ -76,6 +84,10 @@ def setUp(self): yield self.secretsrv.setServiceParent(self.master) self.build = FakeBuildWithMaster(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_secret(self): command = Interpolate("echo %(secret:foo)s") diff --git a/master/buildbot/test/unit/test_janitor_configurator.py b/master/buildbot/test/unit/test_janitor_configurator.py index 6679774c361..8df1cf8f216 100644 --- a/master/buildbot/test/unit/test_janitor_configurator.py +++ b/master/buildbot/test/unit/test_janitor_configurator.py @@ -68,12 +68,14 @@ class LogChunksJanitorTests( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setup_test_build_step() self.patch(janitor, "now", lambda: datetime.datetime(year=2017, month=1, day=1)) + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_basic(self): diff --git a/master/buildbot/test/unit/test_machine_generic.py b/master/buildbot/test/unit/test_machine_generic.py index 39e9b6ea51f..7ac46d457d3 100644 --- a/master/buildbot/test/unit/test_machine_generic.py +++ b/master/buildbot/test/unit/test_machine_generic.py @@ -55,11 +55,12 @@ class TestActions( MasterRunProcessMixin, config.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase ): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() + @defer.inlineCallbacks def tearDown(self): - pass + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_local_wake_action(self): @@ -262,12 +263,16 @@ def test_remote_ssh_suspend_action_no_keys(self, write_local_file_mock, temp_dir class TestHttpAction(config.ConfigErrorsMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.http = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, "http://localhost/request" ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_http_wrong_method(self): manager = FakeManager(self.master) diff --git a/master/buildbot/test/unit/test_master.py b/master/buildbot/test/unit/test_master.py index febdc5da3e0..ae369945861 100644 --- a/master/buildbot/test/unit/test_master.py +++ b/master/buildbot/test/unit/test_master.py @@ -80,7 +80,7 @@ def test_configfile_default(self): class StartupAndReconfig(dirs.DirsMixin, logging.LoggingMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpLogging() self.basedir = os.path.abspath('basedir') yield self.setUpDirs(self.basedir) @@ -107,8 +107,10 @@ def setUp(self): self.data = self.master.data = fakedata.FakeDataConnector(self.master, self) yield self.data.setServiceParent(self.master) + @defer.inlineCallbacks def tearDown(self): - return self.tearDownDirs() + yield self.tearDownDirs() + yield self.tear_down_test_reactor() # tests @defer.inlineCallbacks diff --git a/master/buildbot/test/unit/test_mq.py b/master/buildbot/test/unit/test_mq.py index 19ff407ada9..34190bf10c5 100644 --- a/master/buildbot/test/unit/test_mq.py +++ b/master/buildbot/test/unit/test_mq.py @@ -133,16 +133,24 @@ def test_waitUntilEvent_check_false(self): class TestFakeMQ(TestReactorMixin, unittest.TestCase, Tests): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True) self.mq = self.master.mq self.mq.verifyMessages = False + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class TestSimpleMQ(TestReactorMixin, unittest.TestCase, RealTests): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.mq = simple.SimpleMQ() yield self.mq.setServiceParent(self.master) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() diff --git a/master/buildbot/test/unit/test_mq_connector.py b/master/buildbot/test/unit/test_mq_connector.py index dd14d3135c1..69351e5bbcd 100644 --- a/master/buildbot/test/unit/test_mq_connector.py +++ b/master/buildbot/test/unit/test_mq_connector.py @@ -42,12 +42,16 @@ def startConsuming(self, callback, filter, persistent_name=None): class MQConnector(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.mqconfig = self.master.config.mq = {} self.conn = connector.MQConnector() yield self.conn.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def patchFakeMQ(self, name='fake'): self.patch( connector.MQConnector, diff --git a/master/buildbot/test/unit/test_mq_simple.py b/master/buildbot/test/unit/test_mq_simple.py index 29439d8c6d8..910cdccce21 100644 --- a/master/buildbot/test/unit/test_mq_simple.py +++ b/master/buildbot/test/unit/test_mq_simple.py @@ -26,7 +26,7 @@ class SimpleMQ(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.mq = simple.SimpleMQ() self.mq.setServiceParent(self.master) @@ -36,6 +36,7 @@ def setUp(self): def tearDown(self): if self.mq.running: yield self.mq.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_forward_data(self): diff --git a/master/buildbot/test/unit/test_mq_wamp.py b/master/buildbot/test/unit/test_mq_wamp.py index d984ba35275..51bf1d72b4d 100644 --- a/master/buildbot/test/unit/test_mq_wamp.py +++ b/master/buildbot/test/unit/test_mq_wamp.py @@ -126,7 +126,7 @@ class WampMQ(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.master.wamp = FakeWampConnector() self.mq = wamp.WampMQ() @@ -137,6 +137,7 @@ def setUp(self): def tearDown(self): if self.mq.running: yield self.mq.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_startConsuming_basic(self): @@ -248,7 +249,7 @@ class WampMQReal(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) if "WAMP_ROUTER_URL" not in os.environ: raise unittest.SkipTest(self.HOW_TO_RUN) self.master = yield fakemaster.make_master(self) @@ -261,8 +262,10 @@ def setUp(self): config.mq['router_url'] = os.environ["WAMP_ROUTER_URL"] yield self.connector.reconfigServiceWithBuildbotConfig(config) + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_forward_data(self): diff --git a/master/buildbot/test/unit/test_secret_in_passwordstore.py b/master/buildbot/test/unit/test_secret_in_passwordstore.py index ecf132eae03..3f86e804b39 100644 --- a/master/buildbot/test/unit/test_secret_in_passwordstore.py +++ b/master/buildbot/test/unit/test_secret_in_passwordstore.py @@ -33,7 +33,7 @@ class TestSecretInPass( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() self.master = yield fakemaster.make_master(self) with mock.patch.object(Path, "is_file", return_value=True): @@ -45,6 +45,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.srvpass.stopService() + yield self.tear_down_test_reactor() def create_temp_dir(self, dirname): tempdir = FilePath(self.mktemp()) diff --git a/master/buildbot/test/unit/test_secret_rendered_service.py b/master/buildbot/test/unit/test_secret_rendered_service.py index 237906885e1..894294677d4 100644 --- a/master/buildbot/test/unit/test_secret_rendered_service.py +++ b/master/buildbot/test/unit/test_secret_rendered_service.py @@ -25,7 +25,7 @@ def returnRenderedSecrets(self, secretKey): class TestRenderSecrets(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) fakeStorageService = FakeSecretStorage(secretdict={"foo": "bar", "other": "value"}) self.secretsrv = SecretManager() @@ -38,6 +38,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_secret_rendered(self): diff --git a/master/buildbot/test/unit/test_stats_service.py b/master/buildbot/test/unit/test_stats_service.py index 89afbeaeb28..bf957da383b 100644 --- a/master/buildbot/test/unit/test_stats_service.py +++ b/master/buildbot/test/unit/test_stats_service.py @@ -45,7 +45,7 @@ class TestStatsServicesBase(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) yield self.master.db.insert_test_data([ @@ -62,6 +62,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() class TestStatsServicesConfiguration(TestStatsServicesBase): diff --git a/master/buildbot/test/unit/test_steps_git_diffinfo.py b/master/buildbot/test/unit/test_steps_git_diffinfo.py index d8c18d2e2d0..15940f90ef8 100644 --- a/master/buildbot/test/unit/test_steps_git_diffinfo.py +++ b/master/buildbot/test/unit/test_steps_git_diffinfo.py @@ -13,6 +13,7 @@ # # Copyright Buildbot Team Members +from twisted.internet import defer from twisted.trial import unittest from buildbot.process import results @@ -32,11 +33,13 @@ class TestDiffInfo(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): skip = 'unidiff is required for GitDiffInfo tests' def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() def test_merge_base_failure(self): self.setup_step(gitdiffinfo.GitDiffInfo()) diff --git a/master/buildbot/test/unit/test_steps_mixin.py b/master/buildbot/test/unit/test_steps_mixin.py index b150ad64e2b..97976a64c5d 100644 --- a/master/buildbot/test/unit/test_steps_mixin.py +++ b/master/buildbot/test/unit/test_steps_mixin.py @@ -48,11 +48,13 @@ def run(self): class TestTestBuildStepMixin(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) return self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_setup_build(self): diff --git a/master/buildbot/test/unit/test_wamp_connector.py b/master/buildbot/test/unit/test_wamp_connector.py index cd0b44660dc..9e6505e5401 100644 --- a/master/buildbot/test/unit/test_wamp_connector.py +++ b/master/buildbot/test/unit/test_wamp_connector.py @@ -59,7 +59,7 @@ class TestedWampConnector(connector.WampConnector): class WampConnector(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield fakemaster.make_master(self) self.connector = TestedWampConnector() @@ -69,6 +69,10 @@ def setUp(self): yield master.startService() yield self.connector.reconfigServiceWithBuildbotConfig(config) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_reconfig_same_config(self): config = FakeConfig({'type': 'wamp', 'router_url': "wss://foo", 'realm': "bb"}) diff --git a/master/buildbot/test/unit/util/test_backoff.py b/master/buildbot/test/unit/util/test_backoff.py index 6ed49e29b22..c7ea157512a 100644 --- a/master/buildbot/test/unit/util/test_backoff.py +++ b/master/buildbot/test/unit/util/test_backoff.py @@ -28,7 +28,11 @@ class TestException(Exception): class ExponentialBackoffEngineAsyncTests(unittest.TestCase, TestReactorMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() def test_construct_asserts(self): with self.assertRaises(ValueError): diff --git a/master/buildbot/test/unit/util/test_codebase.py b/master/buildbot/test/unit/util/test_codebase.py index 1f07353f438..0d0737ca242 100644 --- a/master/buildbot/test/unit/util/test_codebase.py +++ b/master/buildbot/test/unit/util/test_codebase.py @@ -42,11 +42,15 @@ class TestAbsoluteSourceStampsMixin( @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True, wantData=True) self.db = self.master.db self.object = FakeObject(self.master, self.codebases) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def mkch(self, **kwargs): ch = self.makeFakeChange(**kwargs) diff --git a/master/buildbot/test/unit/util/test_deferwaiter.py b/master/buildbot/test/unit/util/test_deferwaiter.py index 199df122b6d..f4fc399aa6d 100644 --- a/master/buildbot/test/unit/util/test_deferwaiter.py +++ b/master/buildbot/test/unit/util/test_deferwaiter.py @@ -76,7 +76,11 @@ def test_passes_result(self): class RepeatedActionHandlerTests(unittest.TestCase, TestReactorMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_does_not_add_action_on_start(self): @@ -428,7 +432,11 @@ def action(): class NonRepeatedActionHandlerTests(unittest.TestCase, TestReactorMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_does_not_add_action_on_start(self): diff --git a/master/buildbot/test/unit/util/test_kubeclientservice.py b/master/buildbot/test/unit/util/test_kubeclientservice.py index 8ff0a39b2ef..1b9acb3b45a 100644 --- a/master/buildbot/test/unit/util/test_kubeclientservice.py +++ b/master/buildbot/test/unit/util/test_kubeclientservice.py @@ -106,7 +106,7 @@ class KubeClientServiceTestKubeHardcodedConfig( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self._http = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, "http://localhost:8001" @@ -116,6 +116,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() def test_basic(self): self.config = kubeclientservice.KubeHardcodedConfig( diff --git a/master/buildbot/test/unit/util/test_misc.py b/master/buildbot/test/unit/util/test_misc.py index e654d883c1a..31a6be70dba 100644 --- a/master/buildbot/test/unit/util/test_misc.py +++ b/master/buildbot/test/unit/util/test_misc.py @@ -86,9 +86,13 @@ def check_locked(self, arg1, arg2): class TestCancelAfter(TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.d = defer.Deferred() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_succeeds(self): d = misc.cancelAfter(10, self.d, self.reactor) self.assertIdentical(d, self.d) diff --git a/master/buildbot/test/unit/util/test_poll.py b/master/buildbot/test/unit/util/test_poll.py index 450e08727d8..4e86c9efa95 100644 --- a/master/buildbot/test/unit/util/test_poll.py +++ b/master/buildbot/test/unit/util/test_poll.py @@ -31,7 +31,7 @@ def poll(self): raise RuntimeError('oh noes') def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = mock.Mock() self.master.reactor = self.reactor @@ -39,9 +39,11 @@ def setUp(self): self.calls = 0 self.fail_after_running = False + @defer.inlineCallbacks def tearDown(self): poll.reset_poll_methods() self.assertEqual(self.reactor.getDelayedCalls(), []) + yield self.tear_down_test_reactor() def test_call_not_started_does_nothing(self): self.reactor.advance(100) @@ -190,7 +192,7 @@ def poll(self): raise RuntimeError('oh noes') def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = mock.Mock() self.master.reactor = self.reactor @@ -200,8 +202,10 @@ def setUp(self): self.duration = 1 self.fail_after_running = False + @defer.inlineCallbacks def tearDown(self): poll.reset_poll_methods() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_call_when_started_forces_run(self): diff --git a/master/buildbot/test/unit/util/test_runprocess.py b/master/buildbot/test/unit/util/test_runprocess.py index 1854c84ab97..c5821373af2 100644 --- a/master/buildbot/test/unit/util/test_runprocess.py +++ b/master/buildbot/test/unit/util/test_runprocess.py @@ -37,11 +37,15 @@ class TestRunProcess(TestReactorMixin, LoggingMixin, unittest.TestCase): FAKE_PID = 1234 def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpLogging() self.process = None self.reactor.spawnProcess = self.fake_spawn_process + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def fake_spawn_process(self, pp, command, args, env, workdir, usePTY=False): self.assertIsNone(self.process) self.pp = pp diff --git a/master/buildbot/test/unit/util/test_service.py b/master/buildbot/test/unit/util/test_service.py index dfc355bad49..e3cc95102e9 100644 --- a/master/buildbot/test/unit/util/test_service.py +++ b/master/buildbot/test/unit/util/test_service.py @@ -103,12 +103,13 @@ class DummyService(service.ClusteredBuildbotService): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True, wantData=True) self.svc = self.makeService() + @defer.inlineCallbacks def tearDown(self): - pass + yield self.tear_down_test_reactor() def makeService(self, attach_to_master=True, name=SVC_NAME, serviceid=SVC_ID): svc = self.DummyService(name=name) diff --git a/master/buildbot/test/unit/util/test_state.py b/master/buildbot/test/unit/util/test_state.py index c6e55ec7e10..342a80b9861 100644 --- a/master/buildbot/test/unit/util/test_state.py +++ b/master/buildbot/test/unit/util/test_state.py @@ -34,10 +34,14 @@ class TestStateMixin(TestReactorMixin, StateTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True) self.object = FakeObject(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_getState(self): yield self.set_fake_state(self.object, 'fav_color', ['red', 'purple']) diff --git a/master/buildbot/test/unit/util/test_test_result_submitter.py b/master/buildbot/test/unit/util/test_test_result_submitter.py index 7d3cc7e6c3c..65d33110be5 100644 --- a/master/buildbot/test/unit/util/test_test_result_submitter.py +++ b/master/buildbot/test/unit/util/test_test_result_submitter.py @@ -25,7 +25,7 @@ class TestTestResultSubmitter(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantData=True, wantDb=True) yield self.master.startService() @@ -44,6 +44,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_complete_empty(self): diff --git a/master/buildbot/test/unit/util/test_watchdog.py b/master/buildbot/test/unit/util/test_watchdog.py index fa6cd31ae5f..d2eaea5b0b6 100644 --- a/master/buildbot/test/unit/util/test_watchdog.py +++ b/master/buildbot/test/unit/util/test_watchdog.py @@ -15,6 +15,7 @@ from unittest import mock +from twisted.internet import defer from twisted.trial import unittest from buildbot.test.reactor import TestReactorMixin @@ -23,7 +24,11 @@ class TestWatchdog(TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() def test_not_started_no_calls(self): m = mock.Mock() diff --git a/master/buildbot/test/unit/worker/test_base.py b/master/buildbot/test/unit/worker/test_base.py index ebe9c2e08a7..dc2abccc1f7 100644 --- a/master/buildbot/test/unit/worker/test_base.py +++ b/master/buildbot/test/unit/worker/test_base.py @@ -115,9 +115,13 @@ def canStartBuild(self): class RealWorkerItfc(TestReactorMixin, unittest.TestCase, WorkerInterfaceTests): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.wrk = ConcreteWorker('wrk', 'pa') + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def callAttached(self): self.master = yield fakemaster.make_master(self, wantData=True) @@ -133,10 +137,14 @@ def callAttached(self): class FakeWorkerItfc(TestReactorMixin, unittest.TestCase, WorkerInterfaceTests): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.wrk = worker.FakeWorker(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def callAttached(self): self.conn = fakeprotocol.FakeConnection(self.wrk) return self.wrk.attached(self.conn) @@ -145,7 +153,7 @@ def callAttached(self): class TestAbstractWorker(logging.LoggingMixin, TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setUpLogging() self.master = yield fakemaster.make_master(self, wantDb=True, wantData=True) self.botmaster = self.master.botmaster @@ -153,6 +161,10 @@ def setUp(self): self.workers = self.master.workers = bworkermanager.FakeWorkerManager() yield self.workers.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def createWorker(self, name='bot', password='pass', attached=False, configured=True, **kwargs): worker = ConcreteWorker(name, password, **kwargs) @@ -916,13 +928,17 @@ def test_worker_quarantine_stop_timer(self): class TestAbstractLatentWorker(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True, wantData=True) self.botmaster = self.master.botmaster yield self.master.workers.disownServiceParent() self.workers = self.master.workers = bworkermanager.FakeWorkerManager() yield self.workers.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def do_test_reconfigService(self, old, new, existingRegistration=True): old.parent = self.master diff --git a/master/buildbot/test/unit/worker/test_docker.py b/master/buildbot/test/unit/worker/test_docker.py index 1c1cfb41ac0..6a64748e02e 100644 --- a/master/buildbot/test/unit/worker/test_docker.py +++ b/master/buildbot/test/unit/worker/test_docker.py @@ -47,7 +47,7 @@ def _create_client(self, *args, **kwargs): return self._client def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.patch(dockerworker, 'docker', docker) @@ -61,6 +61,10 @@ def setUp(self): docker.Client.containerCreated = False docker.Client.start_exception = None + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_constructor_noimage_nodockerfile(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/worker/test_kubernetes.py b/master/buildbot/test/unit/worker/test_kubernetes.py index 873a66c72ef..2762ef209d3 100644 --- a/master/buildbot/test/unit/worker/test_kubernetes.py +++ b/master/buildbot/test/unit/worker/test_kubernetes.py @@ -63,7 +63,7 @@ class TestKubernetesWorker(TestReactorMixin, unittest.TestCase): worker = None def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) @defer.inlineCallbacks def setupWorker(self, *args, config=None, **kwargs): @@ -86,6 +86,10 @@ def setupWorker(self, *args, config=None, **kwargs): self.addCleanup(self.master.stopService) return worker + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def get_expected_metadata(self): return {"name": "buildbot-worker-87de7e"} diff --git a/master/buildbot/test/unit/worker/test_libvirt.py b/master/buildbot/test/unit/worker/test_libvirt.py index 1c3ed07a7d1..e9bc24a4457 100644 --- a/master/buildbot/test/unit/worker/test_libvirt.py +++ b/master/buildbot/test/unit/worker/test_libvirt.py @@ -67,12 +67,16 @@ class TestException(Exception): class TestLibVirtWorker(TestReactorMixin, MasterRunProcessMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setup_master_run_process() self.connections = {} self.patch(libvirtworker, "libvirt", libvirtfake) self.threadpool = TestServerThreadPool(self) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def libvirt_open(self, uri): if uri not in self.connections: raise RuntimeError('Could not find test connection') diff --git a/master/buildbot/test/unit/worker/test_local.py b/master/buildbot/test/unit/worker/test_local.py index 4aa20222464..fb128729d04 100644 --- a/master/buildbot/test/unit/worker/test_local.py +++ b/master/buildbot/test/unit/worker/test_local.py @@ -32,11 +32,15 @@ class TestLocalWorker(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True, wantData=True) self.botmaster = self.master.botmaster self.workers = self.master.workers + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def createWorker(self, name='bot', attached=False, configured=True, **kwargs): worker = local.LocalWorker(name, **kwargs) if configured: diff --git a/master/buildbot/test/unit/worker/test_manager.py b/master/buildbot/test/unit/worker/test_manager.py index ca02fbfd246..ef363095ed5 100644 --- a/master/buildbot/test/unit/worker/test_manager.py +++ b/master/buildbot/test/unit/worker/test_manager.py @@ -47,7 +47,7 @@ class FakeWorker2(FakeWorker): class TestWorkerManager(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantData=True) self.master.mq = self.master.mq self.workers = workermanager.WorkerManager(self.master) @@ -61,8 +61,10 @@ def setUp(self): self.new_config = mock.Mock() self.workers.startService() + @defer.inlineCallbacks def tearDown(self): - return self.workers.stopService() + yield self.workers.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_reconfigServiceWorkers_add_remove(self): diff --git a/master/buildbot/test/unit/worker/test_marathon.py b/master/buildbot/test/unit/worker/test_marathon.py index 6a25b2a80d7..7ba37295f0f 100644 --- a/master/buildbot/test/unit/worker/test_marathon.py +++ b/master/buildbot/test/unit/worker/test_marathon.py @@ -29,10 +29,11 @@ class TestMarathonLatentWorker(unittest.TestCase, TestReactorMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.build = Properties(image="busybox:latest", builder="docker_worker") self.worker = None + @defer.inlineCallbacks def tearDown(self): if self.worker is not None: @@ -40,8 +41,9 @@ class FakeResult: code = 200 self._http.delete = lambda _: defer.succeed(FakeResult()) - self.worker.master.stopService() + yield self.worker.master.stopService() self.flushLoggedErrors(LatentWorkerSubstantiatiationCancelled) + yield self.tear_down_test_reactor() def test_constructor_normal(self): worker = MarathonLatentWorker('bot', 'tcp://marathon.local', 'foo', 'bar', 'debian:wheezy') diff --git a/master/buildbot/test/unit/worker/test_openstack.py b/master/buildbot/test/unit/worker/test_openstack.py index df4d89bd9a3..cf9d65bee8c 100644 --- a/master/buildbot/test/unit/worker/test_openstack.py +++ b/master/buildbot/test/unit/worker/test_openstack.py @@ -43,7 +43,7 @@ class TestOpenStackWorker(TestReactorMixin, unittest.TestCase): bs_image_args = {"flavor": 1, "image": '28a65eb4-f354-4420-97dc-253b826547f7', **os_auth} def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.patch(openstack, "client", novaclient) self.patch(openstack, "loading", novaclient) self.patch(openstack, "session", novaclient) @@ -55,6 +55,10 @@ def setUp(self): ) self.masterhash = hashlib.sha1(b'fake:/master').hexdigest()[:6] + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def setupWorker(self, *args, **kwargs): worker = openstack.OpenStackLatentWorker(*args, **kwargs) diff --git a/master/buildbot/test/unit/worker/test_protocols_base.py b/master/buildbot/test/unit/worker/test_protocols_base.py index d0b1abe4fb2..1563cac5fa5 100644 --- a/master/buildbot/test/unit/worker/test_protocols_base.py +++ b/master/buildbot/test/unit/worker/test_protocols_base.py @@ -15,6 +15,7 @@ from unittest import mock +from twisted.internet import defer from twisted.trial import unittest from buildbot.test.fake import fakeprotocol @@ -25,17 +26,25 @@ class TestFakeConnection(protocols.ConnectionInterfaceTest, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.worker = mock.Mock() self.conn = fakeprotocol.FakeConnection(self.worker) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class TestConnection(protocols.ConnectionInterfaceTest, TestReactorMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.worker = mock.Mock() self.conn = base.Connection(self.worker.workername) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_notify(self): cb = mock.Mock() diff --git a/master/buildbot/test/unit/worker/test_protocols_msgpack.py b/master/buildbot/test/unit/worker/test_protocols_msgpack.py index a35cc7d10b3..f7ffe0d9174 100644 --- a/master/buildbot/test/unit/worker/test_protocols_msgpack.py +++ b/master/buildbot/test/unit/worker/test_protocols_msgpack.py @@ -32,9 +32,13 @@ class TestListener(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_constructor(self): listener = msgpack.Listener(self.master) self.assertEqual(listener.master, self.master) @@ -84,21 +88,29 @@ class TestConnectionApi( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.conn = msgpack.Connection(self.master, mock.Mock(), mock.Mock()) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class TestConnection(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.protocol = mock.Mock() self.worker = mock.Mock() self.worker.workername = 'test_worker' self.conn = msgpack.Connection(self.master, self.worker, self.protocol) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_constructor(self): self.assertEqual(self.conn.protocol, self.protocol) self.assertEqual(self.conn.master, self.master) diff --git a/master/buildbot/test/unit/worker/test_protocols_pb.py b/master/buildbot/test/unit/worker/test_protocols_pb.py index 64179fc0649..1dca42960cd 100644 --- a/master/buildbot/test/unit/worker/test_protocols_pb.py +++ b/master/buildbot/test/unit/worker/test_protocols_pb.py @@ -30,9 +30,13 @@ class TestListener(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def makeListener(self): listener = pb.Listener(self.master) return listener @@ -85,19 +89,27 @@ class TestConnectionApi( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.conn = pb.Connection(self.master, mock.Mock(), mock.Mock()) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + class TestConnection(TestReactorMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self) self.mind = mock.Mock() self.worker = mock.Mock() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_constructor(self): conn = pb.Connection(self.master, self.worker, self.mind) diff --git a/master/buildbot/test/unit/worker/test_upcloud.py b/master/buildbot/test/unit/worker/test_upcloud.py index 5148a12fa03..e6cd2490475 100644 --- a/master/buildbot/test/unit/worker/test_upcloud.py +++ b/master/buildbot/test/unit/worker/test_upcloud.py @@ -81,7 +81,11 @@ class TestUpcloudWorker(TestReactorMixin, unittest.TestCase): worker = None def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def setupWorker(self, *args, **kwargs): diff --git a/master/buildbot/test/unit/www/test_auth.py b/master/buildbot/test/unit/www/test_auth.py index 1fc6ed131a9..491f8bb53c9 100644 --- a/master/buildbot/test/unit/www/test_auth.py +++ b/master/buildbot/test/unit/www/test_auth.py @@ -42,10 +42,14 @@ def setUpAuthResource(self): class AuthRootResource(TestReactorMixin, www.WwwTestMixin, AuthResourceMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpAuthResource() self.rsrc = auth.AuthRootResource(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_getChild_login(self): glr = mock.Mock(name='glr') self.master.www.auth.getLoginResource = glr @@ -62,12 +66,16 @@ def test_getChild_logout(self): class AuthBase(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.auth = auth.AuthBase() self.master = yield self.make_master(url='h:/a/b/') self.auth.master = self.master self.req = self.make_request(b'/') + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_maybeAutoLogin(self): self.assertEqual((yield self.auth.maybeAutoLogin(self.req)), None) @@ -103,11 +111,15 @@ def test_exists(self): class RemoteUserAuth(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.auth = auth.RemoteUserAuth(header=b'HDR') yield self.make_master() self.request = self.make_request(b'/') + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_maybeAutoLogin(self): self.request.input_headers[b'HDR'] = b'rachel@foo.com' @@ -143,11 +155,15 @@ def test_get_login_resource_does_not_throw(self): class AuthRealm(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.auth = auth.RemoteUserAuth(header=b'HDR') self.auth = auth.NoAuth() yield self.make_master() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_requestAvatar(self): realm = auth.AuthRealm(self.master, self.auth) itfc, rsrc, _ = realm.requestAvatar("me", None, IResource) @@ -157,7 +173,7 @@ def test_requestAvatar(self): class TwistedICredAuthBase(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) # twisted.web makes it difficult to simulate the authentication process, so # this only tests the mechanics of the getLoginResource method. @@ -192,7 +208,11 @@ def check_credentials(self, us, ps): return us == 'fellow' and ps == 'correct' def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_callable(self): @@ -208,9 +228,13 @@ def test_callable(self): class LoginResource(TestReactorMixin, www.WwwTestMixin, AuthResourceMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpAuthResource() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_render(self): self.rsrc = auth.LoginResource(self.master) @@ -227,10 +251,14 @@ class PreAuthenticatedLoginResource( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpAuthResource() self.rsrc = auth.PreAuthenticatedLoginResource(self.master, 'him') + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_render(self): self.auth.maybeAutoLogin = mock.Mock() @@ -252,10 +280,14 @@ def updateUserInfo(request): class LogoutResource(TestReactorMixin, www.WwwTestMixin, AuthResourceMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) yield self.setUpAuthResource() self.rsrc = auth.LogoutResource(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_render(self): self.master.session.expire = mock.Mock() diff --git a/master/buildbot/test/unit/www/test_authz.py b/master/buildbot/test/unit/www/test_authz.py index 46687583f24..481829bfad4 100644 --- a/master/buildbot/test/unit/www/test_authz.py +++ b/master/buildbot/test/unit/www/test_authz.py @@ -36,7 +36,7 @@ class Authz(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) authzcfg = authz.Authz( # simple matcher with '*' glob character stringsMatcher=authz.fnmatchStrMatcher, @@ -107,6 +107,10 @@ def setUp(self): ), ]) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def setAllowRules(self, allow_rules): # we should add links to authz and master instances in each new rule for r in allow_rules: diff --git a/master/buildbot/test/unit/www/test_avatar.py b/master/buildbot/test/unit/www/test_avatar.py index f8467dfeb17..6fb72107764 100644 --- a/master/buildbot/test/unit/www/test_avatar.py +++ b/master/buildbot/test/unit/www/test_avatar.py @@ -32,7 +32,11 @@ def getUserAvatar(self, email, username, size, defaultAvatarUrl): class AvatarResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_default(self): @@ -530,7 +534,7 @@ def getUserAvatar(self, email, username, size, defaultAvatarUrl): class GitHubAvatar(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield self.make_master( url='http://a/b/', @@ -558,6 +562,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_username(self): @@ -732,7 +737,7 @@ def test_email_error(self): class GitHubAvatarBasicAuth(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) avatar_method = avatar.AvatarGitHub(client_id="oauth_id", client_secret="oauth_secret") master = yield self.make_master( @@ -760,6 +765,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() def test_incomplete_credentials(self): with self.assertRaises(config.ConfigErrors): diff --git a/master/buildbot/test/unit/www/test_config.py b/master/buildbot/test/unit/www/test_config.py index 68d89baaa1d..a1acc763b46 100644 --- a/master/buildbot/test/unit/www/test_config.py +++ b/master/buildbot/test/unit/www/test_config.py @@ -51,7 +51,11 @@ def test_serialize_www_frontend_theme_to_css(self): class TestConfigResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_render(self): @@ -84,7 +88,11 @@ def test_render(self): class IndexResourceTest(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() def get_react_base_path(self): path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) diff --git a/master/buildbot/test/unit/www/test_endpointmatchers.py b/master/buildbot/test/unit/www/test_endpointmatchers.py index 5dbe2e1b9b2..457da4877b7 100644 --- a/master/buildbot/test/unit/www/test_endpointmatchers.py +++ b/master/buildbot/test/unit/www/test_endpointmatchers.py @@ -27,13 +27,17 @@ class EndpointBase(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url='h:/a/b/') self.db = self.master.db self.matcher = self.makeMatcher() self.matcher.setAuthz(self.master.authz) yield self.insertData() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def makeMatcher(self): raise NotImplementedError() diff --git a/master/buildbot/test/unit/www/test_graphql.py b/master/buildbot/test/unit/www/test_graphql.py index 891ee17926c..ed433cc869a 100644 --- a/master/buildbot/test/unit/www/test_graphql.py +++ b/master/buildbot/test/unit/www/test_graphql.py @@ -225,11 +225,15 @@ class DisabledV3RootResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCa @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url="http://server/path/") self.rsrc = graphql.V3RootResource(self.master) self.rsrc.reconfigResource(self.master.config) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_basic_disabled(self): yield self.render_resource(self.rsrc, b"/") diff --git a/master/buildbot/test/unit/www/test_hooks_base.py b/master/buildbot/test/unit/www/test_hooks_base.py index 799541e2b0f..4b551ec8b6f 100644 --- a/master/buildbot/test/unit/www/test_hooks_base.py +++ b/master/buildbot/test/unit/www/test_hooks_base.py @@ -39,9 +39,13 @@ def _prepare_request(payload, headers=None): class TestChangeHookConfiguredWithBase(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_base_change_hook(self) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def _check_base_with_change(self, payload): self.request = _prepare_request(payload) @@ -98,7 +102,7 @@ def test_base_with_changes(self): class TestChangeHookConfiguredWithCustomBase(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) class CustomBase(BaseHookHandler): def getChanges(self, request): @@ -113,6 +117,10 @@ def getChanges(self, request): self.changeHook = yield _prepare_base_change_hook(self, custom_class=CustomBase) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def _check_base_with_change(self, payload): self.request = _prepare_request(payload) diff --git a/master/buildbot/test/unit/www/test_hooks_bitbucket.py b/master/buildbot/test/unit/www/test_hooks_bitbucket.py index 396c2a5c9de..779b8568d21 100644 --- a/master/buildbot/test/unit/www/test_hooks_bitbucket.py +++ b/master/buildbot/test/unit/www/test_hooks_bitbucket.py @@ -139,12 +139,16 @@ class TestChangeHookConfiguredWithBitbucketChange(unittest.TestCase, TestReactor @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield fakeMasterForHooks(self) self.change_hook = change_hook.ChangeHookResource( dialects={'bitbucket': True}, master=master ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def testGitWithChange(self): change_dict = {b'payload': [gitJsonPayload]} diff --git a/master/buildbot/test/unit/www/test_hooks_bitbucketcloud.py b/master/buildbot/test/unit/www/test_hooks_bitbucketcloud.py index 8727052276b..9f711eb0e53 100644 --- a/master/buildbot/test/unit/www/test_hooks_bitbucketcloud.py +++ b/master/buildbot/test/unit/www/test_hooks_bitbucketcloud.py @@ -684,7 +684,7 @@ def _prepare_request(payload, headers=None, change_dict=None): class TestChangeHookConfiguredWithGitChange(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield fakeMasterForHooks(self) self.change_hook = change_hook.ChangeHookResource( dialects={ @@ -695,6 +695,10 @@ def setUp(self): master=master, ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertDictSubset(self, expected_dict, response_dict): expected = {} for key in expected_dict.keys(): diff --git a/master/buildbot/test/unit/www/test_hooks_bitbucketserver.py b/master/buildbot/test/unit/www/test_hooks_bitbucketserver.py index d72c339b49b..d620f61d89d 100644 --- a/master/buildbot/test/unit/www/test_hooks_bitbucketserver.py +++ b/master/buildbot/test/unit/www/test_hooks_bitbucketserver.py @@ -709,7 +709,7 @@ def _prepare_request(payload, headers=None, change_dict=None): class TestChangeHookConfiguredWithGitChange(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield fakeMasterForHooks(self) self.change_hook = change_hook.ChangeHookResource( dialects={ @@ -720,6 +720,10 @@ def setUp(self): master=master, ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertDictSubset(self, expected_dict, response_dict): expected = {} for key in expected_dict.keys(): diff --git a/master/buildbot/test/unit/www/test_hooks_github.py b/master/buildbot/test/unit/www/test_hooks_github.py index 7c41b325a12..6e5933140d4 100644 --- a/master/buildbot/test/unit/www/test_hooks_github.py +++ b/master/buildbot/test/unit/www/test_hooks_github.py @@ -609,7 +609,7 @@ def _prepare_request(event, payload, _secret=None, headers=None): class TestChangeHookConfiguredWithGitChange(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_github_change_hook( self, strict=False, github_property_whitelist=["github.*"] ) @@ -628,6 +628,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() def assertDictSubset(self, expected_dict, response_dict): expected = {} @@ -886,7 +887,7 @@ class TestChangeHookConfiguredWithGitChangeCustomPullrequestRef( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_github_change_hook( self, strict=False, github_property_whitelist=["github.*"], pullrequest_ref="head" ) @@ -905,6 +906,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_git_pull_request_with_custom_ref(self): @@ -927,7 +929,7 @@ class TestChangeHookConfiguredWithGitChangeCustomPullrequestRefWithAuth( ): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) _token = '7e076f41-b73a-4045-a817' self.changeHook = yield _prepare_github_change_hook( self, @@ -954,6 +956,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_git_pull_request_with_custom_ref(self): @@ -977,7 +980,7 @@ class TestChangeHookRefWithAuth(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_github_change_hook( self, @@ -1012,6 +1015,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_git_pull_request(self): @@ -1030,7 +1034,7 @@ def test_git_pull_request(self): class TestChangeHookConfiguredWithAuthAndCustomSkips(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) _token = '7e076f41-b73a-4045-a817' self.changeHook = yield _prepare_github_change_hook( self, strict=False, skips=[r'\[ *bb *skip *\]'], token=_token @@ -1053,6 +1057,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def _check_push_with_skip_message(self, payload): @@ -1121,7 +1126,7 @@ def test_pull_request_no_skip(self): class TestChangeHookConfiguredWithAuth(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) _token = '7e076f41-b73a-4045-a817' self.changeHook = yield _prepare_github_change_hook( @@ -1145,6 +1150,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() def assertDictSubset(self, expected_dict, response_dict): expected = {} @@ -1243,7 +1249,7 @@ def test_git_pull_request_with_skip_message(self): class TestChangeHookConfiguredWithCustomApiRoot(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_github_change_hook( self, strict=False, github_api_endpoint='https://black.magic.io' ) @@ -1262,6 +1268,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def _check_pull_request(self, payload): @@ -1281,7 +1288,7 @@ def test_pull_request(self): class TestChangeHookConfiguredWithCustomApiRootWithAuth(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) _token = '7e076f41-b73a-4045-a817' self.changeHook = yield _prepare_github_change_hook( @@ -1305,6 +1312,7 @@ def setUp(self): @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def _check_pull_request(self, payload): @@ -1326,7 +1334,7 @@ class TestChangeHookConfiguredWithStrict(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) fakeStorageService = FakeSecretStorage() fakeStorageService.reconfigService(secretdict={"secret_key": self._SECRET}) @@ -1339,6 +1347,10 @@ def setUp(self): ) self.changeHook.master.addService(secretService) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_signature_ok(self): self.request = _prepare_request(b'push', gitJsonPayload, _secret=self._SECRET) @@ -1430,9 +1442,13 @@ def test_signature_missing(self): class TestChangeHookConfiguredWithCodebaseValue(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_github_change_hook(self, codebase='foobar') + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def _check_git_with_change(self, payload): self.request = _prepare_request(b'push', payload) @@ -1455,9 +1471,13 @@ def _codebase_function(payload): class TestChangeHookConfiguredWithCodebaseFunction(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.changeHook = yield _prepare_github_change_hook(self, codebase=_codebase_function) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def _check_git_with_change(self, payload): self.request = _prepare_request(b'push', payload) @@ -1476,7 +1496,7 @@ def test_git_with_change_json(self): class TestChangeHookConfiguredWithCustomEventHandler(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) class CustomGitHubEventHandler(GitHubEventHandler): def handle_ping(self, _, __): @@ -1487,6 +1507,10 @@ def handle_ping(self, _, __): self, **{'class': CustomGitHubEventHandler} ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_ping(self): self.request = _prepare_request(b'ping', b'{}') diff --git a/master/buildbot/test/unit/www/test_hooks_gitlab.py b/master/buildbot/test/unit/www/test_hooks_gitlab.py index 73d1600d43a..2adf7f5c6de 100644 --- a/master/buildbot/test/unit/www/test_hooks_gitlab.py +++ b/master/buildbot/test/unit/www/test_hooks_gitlab.py @@ -1019,10 +1019,14 @@ def FakeRequestMR(content): class TestChangeHookConfiguredWithGitChange(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield fakeMasterForHooks(self) self.changeHook = change_hook.ChangeHookResource(dialects={'gitlab': True}, master=master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def check_changes_tag_event(self, r, project='', codebase=None): self.assertEqual(len(self.changeHook.master.data.updates.changesAdded), 2) change = self.changeHook.master.data.updates.changesAdded[0] @@ -1248,7 +1252,7 @@ class TestChangeHookConfiguredWithSecret(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakeMasterForHooks(self) fakeStorageService = FakeSecretStorage() @@ -1262,6 +1266,10 @@ def setUp(self): dialects={'gitlab': {'secret': util.Secret("secret_key")}}, master=self.master ) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_missing_secret(self): self.request = FakeRequest(content=gitJsonPayloadTag) diff --git a/master/buildbot/test/unit/www/test_hooks_gitorious.py b/master/buildbot/test/unit/www/test_hooks_gitorious.py index e8c0310646d..f81989f8c1e 100644 --- a/master/buildbot/test/unit/www/test_hooks_gitorious.py +++ b/master/buildbot/test/unit/www/test_hooks_gitorious.py @@ -64,11 +64,15 @@ class TestChangeHookConfiguredWithGitChange(unittest.TestCase, TestReactorMixin): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) dialects = {'gitorious': True} master = yield fakeMasterForHooks(self) self.changeHook = change_hook.ChangeHookResource(dialects=dialects, master=master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + # Test 'base' hook with attributes. We should get a json string # representing a Change object as a dictionary. All values show be set. @defer.inlineCallbacks diff --git a/master/buildbot/test/unit/www/test_hooks_poller.py b/master/buildbot/test/unit/www/test_hooks_poller.py index 920d733eaed..e54eb884746 100644 --- a/master/buildbot/test/unit/www/test_hooks_poller.py +++ b/master/buildbot/test/unit/www/test_hooks_poller.py @@ -35,7 +35,7 @@ def poll(self): self.called = True def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) @defer.inlineCallbacks def setUpRequest(self, args, options=True, activate=True): @@ -66,8 +66,10 @@ def setUpRequest(self, args, options=True, activate=True): yield self.request.test_render(self.changeHook) yield util.asyncSleep(0.1) + @defer.inlineCallbacks def tearDown(self): - return self.master.stopService() + yield self.master.stopService() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_no_args(self): diff --git a/master/buildbot/test/unit/www/test_ldapuserinfo.py b/master/buildbot/test/unit/www/test_ldapuserinfo.py index b27a95e03b7..56031bf386e 100644 --- a/master/buildbot/test/unit/www/test_ldapuserinfo.py +++ b/master/buildbot/test/unit/www/test_ldapuserinfo.py @@ -186,7 +186,7 @@ class LdapAvatar(CommonTestCase, TestReactorMixin, WwwTestMixin): @defer.inlineCallbacks def setUp(self): CommonTestCase.setUp(self) - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) master = yield self.make_master(url='http://a/b/', avatar_methods=[self.userInfoProvider]) @@ -195,6 +195,10 @@ def setUp(self): yield self.master.startService() + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def makeUserInfoProvider(self): self.userInfoProvider = ldapuserinfo.LdapUserInfo( uri="ldap://uri", diff --git a/master/buildbot/test/unit/www/test_oauth.py b/master/buildbot/test/unit/www/test_oauth.py index 3493159d466..053a1a2af32 100644 --- a/master/buildbot/test/unit/www/test_oauth.py +++ b/master/buildbot/test/unit/www/test_oauth.py @@ -60,7 +60,7 @@ def raise_for_status(self): class OAuth2Auth(TestReactorMixin, www.WwwTestMixin, ConfigErrorsMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) if requests is None: raise unittest.SkipTest("Need to install requests to test oauth2") @@ -113,6 +113,10 @@ def setUp(self): yield secret_service.setServiceParent(self._master) self.githubAuth_secret.reconfigAuth(master, master.config) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_getGoogleLoginURL(self): res = yield self.googleAuth.getLoginURL('http://redir') @@ -553,7 +557,7 @@ def _instantiateAuth(self, cls, config): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) if requests is None: raise unittest.SkipTest("Need to install requests to test oauth2") @@ -584,6 +588,7 @@ def tearDown(self): for reader in reactor.getReaders(): if isinstance(reader, Server): reader.connectionLost(f) + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_E2E(self): diff --git a/master/buildbot/test/unit/www/test_resource.py b/master/buildbot/test/unit/www/test_resource.py index b0020ed93b3..15c325d1680 100644 --- a/master/buildbot/test/unit/www/test_resource.py +++ b/master/buildbot/test/unit/www/test_resource.py @@ -28,7 +28,11 @@ class ResourceSubclass(resource.Resource): class Resource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_base_url(self): @@ -45,7 +49,11 @@ def test_reconfigResource_registration(self): class RedirectResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) + + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_redirect(self): diff --git a/master/buildbot/test/unit/www/test_rest.py b/master/buildbot/test/unit/www/test_rest.py index cfb9ef21e97..adf972f1caf 100644 --- a/master/buildbot/test/unit/www/test_rest.py +++ b/master/buildbot/test/unit/www/test_rest.py @@ -37,9 +37,13 @@ class RestRootResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): maxVersion = 3 def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) _ = graphql # used for import side effect + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + @defer.inlineCallbacks def test_render(self): master = yield self.make_master(url='h:/a/b/') @@ -71,12 +75,16 @@ def test_versions_limited(self): class V2RootResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url='http://server/path/') self.master.data._scanModule(endpoint) self.rsrc = rest.V2RootResource(self.master) self.rsrc.reconfigResource(self.master.config) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertSimpleError(self, message, responseCode): content = json.dumps({'error': message}) self.assertRequest(content=unicode2bytes(content), responseCode=responseCode) @@ -140,7 +148,7 @@ def test_default_origin(self): class V2RootResource_CORS(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url='h:/') self.master.data._scanModule(endpoint) self.rsrc = rest.V2RootResource(self.master) @@ -153,6 +161,10 @@ def renderRest(request): self.rsrc.renderRest = renderRest + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertOk(self, expectHeaders=True, content=b'ok', origin=b'h://good'): hdrs = ( { @@ -260,7 +272,7 @@ def test_cors_origin_preflight_bad_origin(self): class V2RootResource_REST(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url='h:/') self.master.config.www['debug'] = True self.master.data._scanModule(endpoint) @@ -277,6 +289,10 @@ def allow(*args, **kw): endpoint.Test.kind = EndpointKind.COLLECTION endpoint.Test.rtype = endpoint.Test + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertRestCollection( self, typeName, items, total=None, contentType=None, orderSignificant=False ): @@ -753,7 +769,7 @@ def assertRestAuthError(self, message, responseCode=400): class V2RootResource_JSONRPC2(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url='h:/') def allow(*args, **kw): @@ -765,6 +781,10 @@ def allow(*args, **kw): self.rsrc = rest.V2RootResource(self.master) self.rsrc.reconfigResource(self.master.config) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def assertJsonRpcError(self, message, responseCode=400, jsonrpccode=None): got = {} got['contentType'] = self.request.headers[b'content-type'] diff --git a/master/buildbot/test/unit/www/test_service.py b/master/buildbot/test/unit/www/test_service.py index 249a2c7cb89..2bdd9bbae4a 100644 --- a/master/buildbot/test/unit/www/test_service.py +++ b/master/buildbot/test/unit/www/test_service.py @@ -59,11 +59,15 @@ def reconfigResource(self, new_config): class Test(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield self.make_master(url='h:/a/b/') self.svc = self.master.www = service.WWWService() yield self.svc.setServiceParent(self.master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def makeConfig(self, **kwargs): w = {"port": None, "auth": auth.NoAuth(), "logfileName": 'l'} w.update(kwargs) diff --git a/master/buildbot/test/unit/www/test_sse.py b/master/buildbot/test/unit/www/test_sse.py index 02cc0a119f4..d9180bc3c00 100644 --- a/master/buildbot/test/unit/www/test_sse.py +++ b/master/buildbot/test/unit/www/test_sse.py @@ -32,10 +32,14 @@ class EventResource(TestReactorMixin, www.WwwTestMixin, unittest.TestCase): @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = master = yield self.make_master(url=b'h:/a/b/') self.sse = sse.EventResource(master) + @defer.inlineCallbacks + def tearDown(self): + yield self.tear_down_test_reactor() + def test_simpleapi(self): self.render_resource(self.sse, b'/changes/*/*') self.readUUID(self.request) diff --git a/master/buildbot/test/util/connector_component.py b/master/buildbot/test/util/connector_component.py index 10b1d9eca9b..1935dac1c23 100644 --- a/master/buildbot/test/util/connector_component.py +++ b/master/buildbot/test/util/connector_component.py @@ -52,7 +52,7 @@ class ConnectorComponentMixin(TestReactorMixin, db.RealDatabaseMixin): @defer.inlineCallbacks def setUpConnectorComponent(self, table_names=None, basedir='basedir', dialect_name='sqlite'): """Set up C{self.db}, using the given db_url and basedir.""" - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) if table_names is None: table_names = [] @@ -74,6 +74,7 @@ def tearDownConnectorComponent(self): del self.db.pool del self.db.model del self.db + yield self.tear_down_test_reactor() class FakeConnectorComponentMixin(TestReactorMixin): @@ -81,8 +82,12 @@ class FakeConnectorComponentMixin(TestReactorMixin): @defer.inlineCallbacks def setUpConnectorComponent(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantDb=True) self.db = self.master.db self.db.checkForeignKeys = True self.insert_test_data = self.db.insert_test_data + + @defer.inlineCallbacks + def tearDownConnectorComponent(self): + yield self.tear_down_test_reactor() diff --git a/master/buildbot/test/util/endpoint.py b/master/buildbot/test/util/endpoint.py index 0b3c822b7b1..707b08fb1a1 100644 --- a/master/buildbot/test/util/endpoint.py +++ b/master/buildbot/test/util/endpoint.py @@ -38,7 +38,7 @@ class EndpointMixin(TestReactorMixin, interfaces.InterfaceTests): @defer.inlineCallbacks def setUpEndpoint(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.master = yield fakemaster.make_master(self, wantMq=True, wantDb=True, wantData=True) self.db = self.master.db self.mq = self.master.mq @@ -68,8 +68,9 @@ def setUpEndpoint(self): if pp is not None ] + @defer.inlineCallbacks def tearDownEndpoint(self): - pass + yield self.tear_down_test_reactor() def validateData(self, object): validation.verifyData(self, self.rtype.entityType, {}, object) diff --git a/master/buildbot/test/util/integration.py b/master/buildbot/test/util/integration.py index 74e5c092b07..ed7a5bca3e6 100644 --- a/master/buildbot/test/util/integration.py +++ b/master/buildbot/test/util/integration.py @@ -85,11 +85,13 @@ def getMaster(case, reactor, config_dict): class RunFakeMasterTestCase(unittest.TestCase, TestReactorMixin, DebugIntegrationLogsMixin): def setUp(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.setupDebugIntegrationLogs() + @defer.inlineCallbacks def tearDown(self): self.assertFalse(self.master.running, "master is still running!") + yield self.tear_down_test_reactor() @defer.inlineCallbacks def setup_master(self, config_dict): diff --git a/master/buildbot/test/util/migration.py b/master/buildbot/test/util/migration.py index 7be51c67081..cc979034282 100644 --- a/master/buildbot/test/util/migration.py +++ b/master/buildbot/test/util/migration.py @@ -46,7 +46,7 @@ class MigrateTestMixin(TestReactorMixin, db.RealDatabaseMixin, dirs.DirsMixin): @defer.inlineCallbacks def setUpMigrateTest(self): - self.setup_test_reactor() + self.setup_test_reactor(auto_tear_down=False) self.basedir = os.path.abspath("basedir") self.setUpDirs('basedir') @@ -57,9 +57,11 @@ def setUpMigrateTest(self): yield self.db.setServiceParent(master) self.db.pool = self.db_pool + @defer.inlineCallbacks def tearDownMigrateTest(self): self.tearDownDirs() - return self.tearDownRealDatabase() + yield self.tearDownRealDatabase() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def do_test_migration(self, base_revision, target_revision, setup_thd_cb, verify_thd_cb): diff --git a/master/docs/manual/configuration/tests/reactor.rst b/master/docs/manual/configuration/tests/reactor.rst index c38831286a4..279183b831b 100644 --- a/master/docs/manual/configuration/tests/reactor.rst +++ b/master/docs/manual/configuration/tests/reactor.rst @@ -15,8 +15,17 @@ TestReactorMixin For more information see the documentation of `twisted.internet.task.Clock `_. - .. py:method:: setup_test_reactor(use_asyncio=False) + .. py:method:: setup_test_reactor(use_asyncio=False, auto_tear_down=True) - :param bool use_asyncio Whether to enable asyncio integration. + :param bool use_asyncio: Whether to enable asyncio integration. + :param bool auto_tear_down: Whether to automatically tear down the test reactor. This + option is deprecated in favor of ``tear_down_test_reactor()`` as the automatic tear + down can only run before ``tearDown()`` and thus in many tests the test reactor is + shut down prematurely. Call this function in the ``setUp()`` of the test case to setup fake reactor. + + .. py:method:: tear_down_test_reactor() + + Call this function in the ``tearDown()`` of the test case to tear down fake reactor. + The function returns a ``Deferred``. diff --git a/master/docs/manual/configuration/tests/steps.rst b/master/docs/manual/configuration/tests/steps.rst index ba9bfddb341..74405982a88 100644 --- a/master/docs/manual/configuration/tests/steps.rst +++ b/master/docs/manual/configuration/tests/steps.rst @@ -16,12 +16,15 @@ TestBuildStepMixin class RemovePYCs(TestBuildStepMixin, TestReactorMixin, unittest.TestCase): + @defer.inlineCallbacks def setUp(self): - self.setup_test_reactor() - return self.setup_test_build_step() + yield self.setup_test_reactor(auto_tear_down=False) + yield self.setup_test_build_step() + @defer.inlineCallbacks def tearDown(self): - return self.tear_down_test_build_step() + yield self.tear_down_test_build_step() + yield self.tear_down_test_reactor() @defer.inlineCallbacks def test_run_ok(self): @@ -32,7 +35,7 @@ TestBuildStepMixin .exit(0) ) self.expect_outcome(result=SUCCESS, state_string='remove .pycs') - return self.run_step() + yield self.run_step() Basic workflow is as follows: diff --git a/newsfragments/teast-reactor-mixin-explicit-tear-down.feature b/newsfragments/teast-reactor-mixin-explicit-tear-down.feature new file mode 100644 index 00000000000..f6442ac58dc --- /dev/null +++ b/newsfragments/teast-reactor-mixin-explicit-tear-down.feature @@ -0,0 +1 @@ +Added a way to setup ``TestReactorMixin`` with explicit tear down function.