Merge lp:~thumper/juju-core/cleanup-suite into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 1791
Proposed branch: lp:~thumper/juju-core/cleanup-suite
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 153 lines (+110/-9)
3 files modified
testing/cleanup.go (+46/-0)
testing/cleanup_test.go (+57/-0)
testing/log.go (+7/-9)
To merge this branch: bzr merge lp:~thumper/juju-core/cleanup-suite
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+185199@code.launchpad.net

Commit message

Add a base cleaner suite to add cleanup methods

Also made the LoggerSuite embed it, so most existing
tests get the magic.

https://codereview.appspot.com/13633045/

Description of the change

Add a base cleaner suite to add cleanup methods

Also made the LoggerSuite embed it, so most existing
tests get the magic.

https://codereview.appspot.com/13633045/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+185199_code.launchpad.net,

Message:
Please take a look.

Description:
Add a base cleaner suite to add cleanup methods

Also made the LoggerSuite embed it, so most existing
tests get the magic.

https://code.launchpad.net/~thumper/juju-core/cleanup-suite/+merge/185199

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/13633045/

Affected files (+112, -9 lines):
   A [revision details]
   A testing/cleanup.go
   A testing/cleanup_test.go
   M testing/log.go

Revision history for this message
Andrew Wilkins (axwalk) wrote :

On 2013/09/12 05:05:17, thumper wrote:
> Please take a look.

LGTM.

https://codereview.appspot.com/13633045/

Revision history for this message
Ian Booth (wallyworld) wrote :

LGTM but I'd like some tests to ensure there's no cross contamination
between suite and test cleanup

https://codereview.appspot.com/13633045/

Revision history for this message
Go Bot (go-bot) wrote :
Download full text (165.0 KiB)

The attempt to merge lp:~thumper/juju-core/cleanup-suite into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/agent 0.714s
ok launchpad.net/juju-core/agent/tools 0.238s
ok launchpad.net/juju-core/bzr 6.872s
ok launchpad.net/juju-core/cert 2.158s
ok launchpad.net/juju-core/charm 0.571s
? launchpad.net/juju-core/charm/hooks [no test files]
ok launchpad.net/juju-core/cloudinit 0.020s
ok launchpad.net/juju-core/cmd 0.249s
? launchpad.net/juju-core/cmd/builddb [no test files]
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]

----------------------------------------------------------------------
PANIC: addmachine.go:0: AddMachineSuite.SetUpTest

[LOG] 98.04033 INFO juju mongod: error command line: unknown option sslOnNormalPorts
[LOG] 98.04037 INFO juju mongod: use --help for help
... Panic: no reachable servers (PC=0x414321)

/usr/lib/go/src/pkg/runtime/panic.c:229
  in panic
/home/tarmac/trees/src/launchpad.net/juju-core/testing/mgo.go:198
  in MgoDial
/home/tarmac/trees/src/launchpad.net/juju-core/testing/mgo.go:205
  in MgoSuite.SetUpTest
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/conn.go:138
  in JujuConnSuite.SetUpTest
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/repo.go:25
  in RepoSuite.SetUpTest

----------------------------------------------------------------------
PANIC: addmachine.go:0: AddMachineSuite.TearDownTest

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)

/usr/lib/go/src/pkg/runtime/panic.c:229
  in panic
/usr/lib/go/src/pkg/runtime/panic.c:487
  in panicstring
/usr/lib/go/src/pkg/runtime/os_linux.c:236
  in sigpanic
/home/tarmac/trees/src/launchpad.net/juju-core/state/state.go:1044
  in State.SetAdminMongoPassword
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/conn.go:264
  in JujuConnSuite.tearDownConn
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/conn.go:144
  in JujuConnSuite.TearDownTest
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/repo.go:44
  in RepoSuite.TearDownTest

----------------------------------------------------------------------
PANIC: addmachine_test.go:82: AddMachineSuite.TestAddContainerToExistingMachine

... Panic: Fixture has panicked (see related PANIC)

----------------------------------------------------------------------
PANIC: addmachine.go:0: AddRelationSuite.SetUpTest

... Panic: no reachable servers (PC=0x414321)

/usr/lib/go/src/pkg/runtime/panic.c:229
  in panic
/home/tarmac/trees/src/launchpad.net/juju-core/testing/mgo.go:198
  in MgoDial
/home/tarmac/trees/src/launchpad.net/juju-core/testing/mgo.go:205
  in MgoSuite.SetUpTest
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/conn.go:138
  in JujuConnSuite.SetUpTest
/home/tarmac/trees/src/launchpad.net/juju-core/juju/testing/repo.go:25
  in RepoSuite.SetUpTest

----------------------------------------------------------------------
PANIC: addmachine.go:0: AddRelationSuite.TearDownTest

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)

/usr/lib/go/src/pkg/...

Revision history for this message
Roger Peppe (rogpeppe) wrote :

LGTM with a couple of minor suggestions.

Embedding this into LoggingSuite makes me
feel twitchy though. This a marriage entirely
of convenience - LoggingSuite previously
was about a single thing only, and now has
this functionality shoehorned in just because
lots of things use LoggingSuite.

I would be more inclined to embed it in some
of the "kitchen-sink" suites: JujuConnSuite;
or rename LoggingSuite to LoggingAndCleanupSuite
perhaps throughout.

I like the functionality in general though.

https://codereview.appspot.com/13633045/diff/1/testing/cleanup.go
File testing/cleanup.go (right):

https://codereview.appspot.com/13633045/diff/1/testing/cleanup.go#newcode14
testing/cleanup.go:14: testStack []func()
One possibility is to use jc.Restorer instead of func() here, which
perhaps makes the purpose of the functions more clear.

It doesn't really make any difference, just a thought.

https://codereview.appspot.com/13633045/diff/1/testing/cleanup_test.go
File testing/cleanup_test.go (right):

https://codereview.appspot.com/13633045/diff/1/testing/cleanup_test.go#newcode10
testing/cleanup_test.go:10: testing.CleanupSuite
I'm not sure we need to embed this - you can just
declare it in each test, which I think will make the
tests a little clearer as it avoids shared state.

https://codereview.appspot.com/13633045/

Revision history for this message
John A Meinel (jameinel) wrote :

The problem with embedding it in each test, is then you have to update your SetUp and TearDown to call yet-another method, etc. So it is "just one more embed" but that is one more of a bunch of other bits.

This is the sort of thing you would put on a "base" suite if we had such a thing. LoggingSuite comes pretty close. We could rename it for clarity if we like that more.

The failure in the test suite was because the bot rebooted and I missed one line. It should land now. I'm going to mark it Approved because I don't want Tim to have to wait on Bot failure. However, please respond to Roger's comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'testing/cleanup.go'
--- testing/cleanup.go 1970-01-01 00:00:00 +0000
+++ testing/cleanup.go 2013-09-12 05:03:44 +0000
@@ -0,0 +1,46 @@
1// Copyright 2013 Canonical Ltd.
2// Licensed under the AGPLv3, see LICENCE file for details.
3
4package testing
5
6import (
7 gc "launchpad.net/gocheck"
8)
9
10// CleanupSuite adds the ability to add cleanup functions that are called
11// during either test tear down or suite tear down depending on the method
12// called.
13type CleanupSuite struct {
14 testStack []func()
15 suiteStack []func()
16}
17
18func (s *CleanupSuite) SetUpSuite(c *gc.C) {
19 s.suiteStack = nil
20}
21
22func (s *CleanupSuite) TearDownSuite(c *gc.C) {
23 s.callStack(s.suiteStack)
24}
25
26func (s *CleanupSuite) SetUpTest(c *gc.C) {
27 s.testStack = nil
28}
29
30func (s *CleanupSuite) TearDownTest(c *gc.C) {
31 s.callStack(s.testStack)
32}
33
34func (s *CleanupSuite) callStack(stack []func()) {
35 for i := len(stack) - 1; i >= 0; i-- {
36 stack[i]()
37 }
38}
39
40func (s *CleanupSuite) AddCleanup(cleanup func()) {
41 s.testStack = append(s.testStack, cleanup)
42}
43
44func (s *CleanupSuite) AddSuiteCleanup(cleanup func()) {
45 s.suiteStack = append(s.suiteStack, cleanup)
46}
047
=== added file 'testing/cleanup_test.go'
--- testing/cleanup_test.go 1970-01-01 00:00:00 +0000
+++ testing/cleanup_test.go 2013-09-12 05:03:44 +0000
@@ -0,0 +1,57 @@
1package testing_test
2
3import (
4 gc "launchpad.net/gocheck"
5
6 "launchpad.net/juju-core/testing"
7)
8
9type cleanupSuite struct {
10 testing.CleanupSuite
11}
12
13var _ = gc.Suite(&cleanupSuite{})
14
15func (s *cleanupSuite) TestTearDownSuiteEmpty(c *gc.C) {
16 // The suite stack is empty initially, check we can tear that down.
17 s.TearDownSuite(c)
18 s.SetUpSuite(c)
19}
20
21func (s *cleanupSuite) TestTearDownTestEmpty(c *gc.C) {
22 // The test stack is empty initially, check we can tear that down.
23 s.TearDownTest(c)
24 s.SetUpTest(c)
25}
26
27func (s *cleanupSuite) TestAddSuiteCleanup(c *gc.C) {
28 order := []string{}
29 s.AddSuiteCleanup(func() {
30 order = append(order, "first")
31 })
32 s.AddSuiteCleanup(func() {
33 order = append(order, "second")
34 })
35
36 s.TearDownSuite(c)
37 c.Assert(order, gc.DeepEquals, []string{"second", "first"})
38
39 // and to avoid calling them twice, clear out the stack.
40 s.SetUpSuite(c)
41}
42
43func (s *cleanupSuite) TestAddCleanup(c *gc.C) {
44 order := []string{}
45 s.AddCleanup(func() {
46 order = append(order, "first")
47 })
48 s.AddCleanup(func() {
49 order = append(order, "second")
50 })
51
52 s.TearDownTest(c)
53 c.Assert(order, gc.DeepEquals, []string{"second", "first"})
54
55 // and to avoid calling them twice, clear out the stack.
56 s.SetUpTest(c)
57}
058
=== modified file 'testing/log.go'
--- testing/log.go 2013-08-28 17:20:01 +0000
+++ testing/log.go 2013-09-12 05:03:44 +0000
@@ -14,7 +14,7 @@
14// LoggingSuite redirects the juju logger to the test logger14// LoggingSuite redirects the juju logger to the test logger
15// when embedded in a gocheck suite type.15// when embedded in a gocheck suite type.
16type LoggingSuite struct {16type LoggingSuite struct {
17 restoreLog func()17 CleanupSuite
18}18}
1919
20type gocheckWriter struct {20type gocheckWriter struct {
@@ -27,21 +27,19 @@
27}27}
2828
29func (t *LoggingSuite) SetUpSuite(c *gc.C) {29func (t *LoggingSuite) SetUpSuite(c *gc.C) {
30 t.CleanupSuite.SetUpSuite(c)
30 t.setUp(c)31 t.setUp(c)
31}32 t.AddSuiteCleanup(func() {
3233 loggo.ResetLoggers()
33func (t *LoggingSuite) TearDownSuite(c *gc.C) {34 loggo.ResetWriters()
34 loggo.ResetLoggers()35 })
35 loggo.ResetWriters()
36}36}
3737
38func (t *LoggingSuite) SetUpTest(c *gc.C) {38func (t *LoggingSuite) SetUpTest(c *gc.C) {
39 t.CleanupSuite.SetUpTest(c)
39 t.setUp(c)40 t.setUp(c)
40}41}
4142
42func (t *LoggingSuite) TearDownTest(c *gc.C) {
43}
44
45func (t *LoggingSuite) setUp(c *gc.C) {43func (t *LoggingSuite) setUp(c *gc.C) {
46 loggo.ResetWriters()44 loggo.ResetWriters()
47 loggo.ReplaceDefaultWriter(&gocheckWriter{c})45 loggo.ReplaceDefaultWriter(&gocheckWriter{c})

Subscribers

People subscribed via source and target branches

to status/vote changes: