Merge lp:~jtv/maas/db-fixture into lp:~maas-committers/maas/trunk
Status: | Merged |
---|---|
Merged at revision: | 16 |
Proposed branch: | lp:~jtv/maas/db-fixture |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
105 lines (+22/-22) 6 files modified
Makefile (+1/-1) README.txt (+3/-3) bin/maasdb (+2/-2) src/maas/development.py (+4/-0) src/maas/testing/runner.py (+12/-0) src/maasserver/tests/simple_tests.py (+0/-16) |
To merge this branch: | bzr merge lp:~jtv/maas/db-fixture |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gavin Panella (community) | Approve | ||
Review via email: mp+88898@code.launchpad.net |
Commit message
Start test database cluster from test runner.
Description of the change
Set up the testing database cluster as part of the test runner.
It took me a while to find a hook into the test runner that I could use. The one I found was: use a custom test runner based on the django one, but with a call to maasdb added to it. I couldn't define the custom runner in development.py or maas/__init__.py etc. because it'd just lead to circular imports and a mysterious failure.
To try this out, create a new branch (so there's certainly no database cluster running in it), "make," then check "ps -ef | grep postgres" to verify that there still is no postgres running in the branch, then "./bin/test" to see that the tests can access the database. I added some only-slightly-
You may notice that database setup before a test takes a while. That doesn't go away when I remove the custom test runner though; I guess it's something we just can't get rid of.
Something a bit nasty I did was to hard-code "./db/" as the database cluster location. Ideally I'd have some way of specifying "main branch directory/db."
The maasdb script does nothing when asked to start a cluster that's already running. Doesn't take very long to find out, either.
Jeroen
This is a neat solution :)
[1]
+ def setup_databases (self, *args, **kwargs): 'bin/maasdb' , 'start', './db/']) "Failed to start database cluster.")
+ """Fire up the db cluster, then punt to original implementation."""
+ process = Popen([
+ retval = process.wait()
+ if retval != 0:
+ raise RuntimeError(
Consider subprocess. check_call( ) here; it'll raise CalledProcessError
if the command does not exit with 0. Four lines into one:
It would also be nice to make this quiet unless there's an
error. Django doesn't seem to know about subunit output yet, but it
would be nice not to muddy things in advance. Witness how long it has
taken to make the Launchpad test suite STFU.
[2]
class SimpleTest( TestCase) : addition( self): create_ nodes(self) : l([], list(Node. objects. all())) l([n], list(Node. objects. all())) nodes_exist_ initially( self): l([], list(Node. objects. all()))
- def test_basic_
- """
- Tests that 1 + 1 always equals 2.
- """
- self.assertEqual(1 + 1, 2)
+
+ def test_can_
+ self.assertEqua
+ n = Node(name='foo', status='NEW')
+ n.save()
+ self.assertEqua
+
+ def test_no_
+ self.assertEqua
+
Raphael's recent changes provide enough to exercise your change, so
consider removing this.