Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #243 from Unity-Technologies/fixes/cleanUpCommandR…
Browse files Browse the repository at this point in the history
…eference

Fixes/clean up command reference
  • Loading branch information
mariangemarcano committed Mar 2, 2017
2 parents e9dd636 + 8ace561 commit c1fac9a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions master/buildbot/process/buildstep.py
Expand Up @@ -201,10 +201,28 @@ def remote_complete(self, failure=None):
self.buildslave.messageReceivedFromSlave()
# call the real remoteComplete a moment later, but first return an
# acknowledgement so the slave can retire the completion message.

self.unregisterCommandReference()

if self.active:
eventually(self._finished, failure)
return None

def unregisterCommandReference(self):
"""
Called when remote command has finished.
This function makes sure the object gets unregistered from self.remote.broker after the command finished
preventing "Maximum PB reference count exceeded." error
:return:
"""

processUniqueID = self.processUniqueID()
localUniqueID = self.remote.broker.luids.get(processUniqueID)

if localUniqueID and localUniqueID in self.remote.broker.localObjects:
self.remote.broker.proto_decref(localUniqueID)

def addStdout(self, data):
if 'stdio' in self.logs:
self.logs['stdio'].addStdout(data)
Expand Down
24 changes: 24 additions & 0 deletions master/buildbot/test/unit/test_process_buildstep.py
Expand Up @@ -24,6 +24,7 @@
from buildbot.test.fake import fakebuild, remotecommand
from buildbot.test.util import config, steps, compat
from buildbot.util.eventual import eventually
from twisted.spread import pb

class FakeLogFile:
def __init__(self, text):
Expand Down Expand Up @@ -428,3 +429,26 @@ class TestFakeRemoteShellCommand(unittest.TestCase, RemoteShellCommandTests):

def makeRemoteShellCommand(self, *args, **kwargs):
return remotecommand.FakeRemoteShellCommand(*args, **kwargs)


class TestRemoteShellCommand(unittest.TestCase):

def setUp(self):
self.step = buildstep.RemoteShellCommand("build", ["echo", "hello"])
self.step.buildslave = self.step.remote = mock.Mock()
self.step.processUniqueID = lambda: 2
self.step.remote.broker = pb.Broker()

def test_remote_complete_unregisterCommandReference(self):
self.step.remote.broker.luids = {2: 1}
self.step.remote.broker.localObjects = {1: pb.Local(self.step)}
self.step.remote_complete()
self.assertEqual(self.step.remote.broker.localObjects, {})
self.assertEqual(self.step.remote.broker.luids, {})

def test_remote_complete_commandReferenceNotInBroker(self):
self.step.remote.broker.luids = expectedLuids = {3: 2}
self.step.remote.broker.localObjects = expectedObjects = {2: pb.Local(mock.Mock())}
self.step.remote_complete()
self.assertEqual(self.step.remote.broker.localObjects, expectedObjects)
self.assertEqual(self.step.remote.broker.luids, expectedLuids)

0 comments on commit c1fac9a

Please sign in to comment.