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

Subscribers

People subscribed via source and target branches

to all changes: