Skip to content

Commit

Permalink
Merge pull request #1603 from tardyp/websocket
Browse files Browse the repository at this point in the history
Websocket based event source
  • Loading branch information
tardyp committed Mar 23, 2015
2 parents ec0eaab + 579489d commit 56040b6
Show file tree
Hide file tree
Showing 20 changed files with 508 additions and 629 deletions.
1 change: 1 addition & 0 deletions master/buildbot/data/buildrequests.py
Expand Up @@ -108,6 +108,7 @@ class BuildRequest(base.ResourceType):
eventPathPatterns = """
/buildsets/:buildsetid/builders/:builderid/buildrequests/:buildrequestid
/buildrequests/:buildrequestid
/builders/:builderid/buildrequests/:buildrequestid
"""

class EntityType(types.Entity):
Expand Down
12 changes: 9 additions & 3 deletions master/buildbot/test/unit/test_data_buildsets.py
Expand Up @@ -192,9 +192,7 @@ def check(xxx_todo_changeme):
(bsid, brids) = xxx_todo_changeme
self.assertEqual((bsid, brids), expectedReturn)
# check the correct message was received
self.assertEqual(
sorted(self.master.mq.productions),
sorted(expectedMessages))
self.master.mq.assertProductions(expectedMessages, orderMatters=False)
# and that the correct data was inserted into the db
self.master.db.buildsets.assertBuildset(bsid, expectedBuildset)
d.addCallback(check)
Expand Down Expand Up @@ -226,6 +224,12 @@ def _buildRequestMessage2(self, brid, bsid, builderid):
('buildrequests', str(brid), 'new'),
self._buildRequestMessageDict(brid, bsid, builderid))

def _buildRequestMessage3(self, brid, bsid, builderid):
return (
('builders', str(builderid),
'buildrequests', str(brid), 'new'),
self._buildRequestMessageDict(brid, bsid, builderid))

def _buildsetMessage(self, bsid, external_idstring=u'extid',
reason=u'because', scheduler=u'fakesched', sourcestampids=[234],
submitted_at=A_TIMESTAMP):
Expand Down Expand Up @@ -261,8 +265,10 @@ class FakeSched(object):
expectedMessages = [
self._buildRequestMessage1(1000, 200, 42),
self._buildRequestMessage2(1000, 200, 42),
self._buildRequestMessage3(1000, 200, 42),
self._buildRequestMessage1(1001, 200, 43),
self._buildRequestMessage2(1001, 200, 43),
self._buildRequestMessage3(1001, 200, 43),
self._buildsetMessage(200),
]
expectedBuildset = dict(reason=u'because',
Expand Down
76 changes: 76 additions & 0 deletions master/buildbot/test/unit/test_www_ws.py
@@ -0,0 +1,76 @@
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from buildbot.test.util import www
from buildbot.util import json
from buildbot.www import ws
from mock import Mock
from twisted.trial import unittest


class WsResource(www.WwwTestMixin, unittest.TestCase):

def setUp(self):
self.master = master = self.make_master(url='h:/a/b/')
self.ws = ws.WsResource(master)
self.proto = self.ws._factory.buildProtocol("me")
self.gotMsg = []
self.proto.sendMessage = Mock(spec=self.proto.sendMessage)

def test_ping(self):
self.proto.onMessage(json.dumps(dict(cmd="ping", _id=1)), False)
self.proto.sendMessage.assert_called_with('{"msg":"pong","code":200,"_id":1}')

def test_bad_cmd(self):
self.proto.onMessage(json.dumps(dict(cmd="poing", _id=1)), False)
self.proto.sendMessage.assert_called_with(
'{"_id":1,"code":404,"error":"no such command \'poing\'"}')

def test_no_cmd(self):
self.proto.onMessage(json.dumps(dict(_id=1)), False)
self.proto.sendMessage.assert_called_with(
'{"_id":null,"code":400,"error":"no \'cmd\' in websocket frame"}')

def test_no_id(self):
self.proto.onMessage(json.dumps(dict(cmd="ping")), False)
self.proto.sendMessage.assert_called_with(
'{"_id":null,"code":400,"error":"no \'_id\' in websocket frame"}')

def test_startConsuming(self):
self.proto.onMessage(json.dumps(dict(cmd="startConsuming", path="builds/*/*", _id=1)), False)
self.proto.sendMessage.assert_called_with(
'{"msg":"OK","code":200,"_id":1}')
self.master.mq.verifyMessages = False
self.master.mq.callConsumer(("builds", "1", "new"), {"buildid": 1})
self.proto.sendMessage.assert_called_with(
'{"k":"builds/1/new","m":{"buildid":1}}')

def test_startConsumingBadPath(self):
self.proto.onMessage(json.dumps(dict(cmd="startConsuming", path={}, _id=1)), False)
self.proto.sendMessage.assert_called_with(
'{"_id":1,"code":400,"error":"invalid path format \'{}\'"}')

def test_stopConsumingNotRegistered(self):
self.proto.onMessage(json.dumps(dict(cmd="stopConsuming", path="builds/*/*", _id=1)), False)
self.proto.sendMessage.assert_called_with(
'{"_id":1,"code":400,"error":"path was not consumed \'builds/*/*\'"}')

def test_stopConsuming(self):
self.proto.onMessage(json.dumps(dict(cmd="startConsuming", path="builds/*/*", _id=1)), False)
self.proto.sendMessage.assert_called_with(
'{"msg":"OK","code":200,"_id":1}')
self.proto.onMessage(json.dumps(dict(cmd="stopConsuming", path="builds/*/*", _id=2)), False)
self.proto.sendMessage.assert_called_with(
'{"msg":"OK","code":200,"_id":2}')
4 changes: 2 additions & 2 deletions master/buildbot/www/sse.py
@@ -1,4 +1,4 @@
# This file is part of . Buildbot is free software: you can
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
Expand All @@ -11,7 +11,7 @@
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Team Members
# Copyright Buildbot Team Members

import uuid

Expand Down

0 comments on commit 56040b6

Please sign in to comment.