Merge lp:~benji/charms/oneiric/buildbot-slave/who-needs-sleep into lp:~yellow/charms/oneiric/buildbot-slave/trunk

Proposed by Benji York
Status: Merged
Approved by: Graham Binns
Approved revision: 11
Merged at revision: 11
Proposed branch: lp:~benji/charms/oneiric/buildbot-slave/who-needs-sleep
Merge into: lp:~yellow/charms/oneiric/buildbot-slave/trunk
Diff against target: 144 lines (+8/-86)
2 files modified
hooks/tests.py (+0/-51)
tests/buildbot-slave.test (+8/-35)
To merge this branch: bzr merge lp:~benji/charms/oneiric/buildbot-slave/who-needs-sleep
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+92298@code.launchpad.net

Description of the change

This branch makes the test_master_slave_relationship test more resilient (removing a sleep) and much faster (by parallelizing unit startup.

I noticed that the (do_not_)test_script test won't run any more (it doesn't pass a required argument to .deploy()) so I removed it. It's safe in Bazaar's Bosom should we need to call upon it.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/tests.py'
2--- hooks/tests.py 2012-02-07 13:56:40 +0000
3+++ hooks/tests.py 1970-01-01 00:00:00 +0000
4@@ -1,51 +0,0 @@
5-# Copyright 2012 Canonical Ltd. This software is licensed under the
6-# GNU Affero General Public License version 3 (see the file LICENSE).
7-
8-import unittest
9-
10-from helpers import command
11-from subprocess import CalledProcessError
12-
13-
14-class TestCommand(unittest.TestCase):
15-
16- def test_simple_command(self):
17- # Creating a simple command (ls) works and running the command
18- # produces a string.
19- ls = command('/bin/ls')
20- self.assertIsInstance(ls(), str)
21-
22- def test_arguments(self):
23- # Arguments can be passed to commands.
24- ls = command('/bin/ls')
25- self.assertIn('Usage:', ls('--help'))
26-
27- def test_missing_executable(self):
28- # If the command does not exist, an OSError (No such file or
29- # directory) is raised.
30- bad = command('this command does not exist')
31- with self.assertRaises(OSError) as info:
32- bad()
33- self.assertEqual(2, info.exception.errno)
34-
35- def test_error(self):
36- # If the command returns a non-zero exit code, an exception is raised.
37- ls = command('/bin/ls')
38- with self.assertRaises(CalledProcessError):
39- ls('--not a valid switch')
40-
41- def test_baked_in_arguments(self):
42- # Arguments can be passed when creating the command as well as when
43- # executing it.
44- ll = command('/bin/ls', '-l')
45- self.assertIn('rw', ll()) # Assumes a file is r/w in the pwd.
46- self.assertIn('Usage:', ll('--help'))
47-
48- def test_quoting(self):
49- # There is no need to quote special shell characters in commands.
50- ls = command('/bin/ls')
51- ls('--help', '>')
52-
53-
54-if __name__ == '__main__':
55- unittest.main()
56
57=== target is u'../../buildbot-master/hooks/tests.py'
58=== modified file 'tests/buildbot-slave.test'
59--- tests/buildbot-slave.test 2012-02-09 12:06:33 +0000
60+++ tests/buildbot-slave.test 2012-02-09 15:55:30 +0000
61@@ -6,14 +6,14 @@
62 import os
63 import time
64 import unittest
65-import urllib2
66
67 from helpers import (
68 command,
69 encode_file,
70 unit_info,
71+ wait_for_page_contents,
72+ wait_for_relation,
73 wait_for_unit,
74- wait_for_relation,
75 )
76 from openport import (
77 PORT,
78@@ -56,7 +56,6 @@
79 # (e.g. just after `juju bootstrap`).
80 # We should try to wait for unit in a smarter way
81 # (maybe checking for "pending"?).
82- wait_for_unit(service_name, timeout=600)
83
84 def add_relation(self, relation, service1, service2):
85 juju('add-relation',
86@@ -71,52 +70,26 @@
87 def test_deploy(self):
88 # Ensure the charm starts correctly when deployed.
89 self.deploy(self.charm_name)
90+ wait_for_unit(self.charm_name)
91 self.assertEqual('started', unit_info(self.charm_name, 'state'))
92
93- def do_not_test_script(self):
94- # DISABLED BECAUSE IT FAILS ALL THE TIME.
95- # Ensure a script supplied during deploy is correctly run.
96- config = os.path.join(self.tests_dir, 'config.test.yaml')
97- try:
98- started = self.deploy(config=config)
99- self.assertTrue(started)
100- address = unit_info(self.charm_name, 'public-address')
101- url = 'http://{}:{}'.format(address, PORT)
102- try:
103- stream = urllib2.urlopen(url)
104- except urllib2.HTTPError:
105- self.fail('Unable to connect to {}.'.format(url))
106- self.assertEqual(TEXT, stream.read())
107- finally:
108-# juju('destroy-service', self.charm_name)
109- pass
110-
111 def test_master_slave_relationship(self):
112 master_charm_name = 'buildbot-master'
113+ # We deploy both and then wait because it's quite a bit faster.
114 self.deploy(master_charm_name)
115 self.deploy(self.charm_name)
116+ wait_for_unit(master_charm_name)
117+ wait_for_unit(self.charm_name)
118 juju('set', master_charm_name, 'extra-packages=git')
119 config_path = os.path.join(os.path.dirname(__file__), 'test.cfg')
120 config = encode_file(config_path)
121 juju('set', 'buildbot-master', 'config-file='+config)
122 juju('expose', master_charm_name)
123 juju('set', self.charm_name, 'builders=runtests')
124- # XXX 2012-02-08 gmb
125- # This avoids us trying to check whether the slave
126- # is connected until the relation is initialized,
127- # but... (see next XXX)
128 self.add_relation('buildbot', self.charm_name, master_charm_name)
129- # XXX 2012-02-08 gmb:
130- # This still sometimes gets called _before_ the
131- # buildslave connects to the buildbot master. Hence
132- # this rather ugly sleep here.
133- time.sleep(5)
134 url = self.get_url(master_charm_name, 8010, '/buildslaves')
135- try:
136- stream = urllib2.urlopen(url)
137- except urllib2.HTTPError:
138- self.fail('Unable to connect to {}.'.format(url))
139- self.assertIn('Idle', stream.read())
140+ wait_for_page_contents(url, 'buildbot-slave/')
141+ wait_for_page_contents(url, 'Idle')
142
143
144 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches

to all changes: