Merge lp:~dave-cheney/juju-core/033-testing-mgo-panic into lp:~juju/juju-core/trunk

Proposed by Dave Cheney
Status: Work in progress
Proposed branch: lp:~dave-cheney/juju-core/033-testing-mgo-panic
Merge into: lp:~juju/juju-core/trunk
Diff against target: 138 lines (+23/-21)
4 files modified
environs/dummy/environs.go (+10/-8)
state/ssh_test.go (+1/-1)
testing/mgo.go (+9/-9)
testing/mgo_test.go (+3/-3)
To merge this branch: bzr merge lp:~dave-cheney/juju-core/033-testing-mgo-panic
Reviewer Review Type Date Requested Status
The Go Language Gophers Pending
Review via email: mp+132146@code.launchpad.net

Description of the change

testing: prefer Assert over panic

https://codereview.appspot.com/6775079/

To post a comment you must log in.
Revision history for this message
Roger Peppe (rogpeppe) wrote :

https://codereview.appspot.com/6775079/diff/1/environs/dummy/environs.go
File environs/dummy/environs.go (right):

https://codereview.appspot.com/6775079/diff/1/environs/dummy/environs.go#newcode30
environs/dummy/environs.go:30: "time"
nice

https://codereview.appspot.com/6775079/diff/1/environs/dummy/environs.go#newcode173
environs/dummy/environs.go:173: testing.MgoReset(new(gocheck.C))
this seems wrong. if we haven't got a gocheck.C, panic is the only
viable alternative. there's no guarantee that new(gocheck.C) gives us a
working *C value.

one possibility would be to change MgoReset to accept an interface that
implements Fatalf, and write an implementation here that turns Fatalf
into panic.

https://codereview.appspot.com/6775079/diff/1/testing/mgo.go
File testing/mgo.go (right):

https://codereview.appspot.com/6775079/diff/1/testing/mgo.go#newcode86
testing/mgo.go:86: panic("MgoSuite tests must be run with
MgoTestPackage")
if you're gonna prefer Assert over panic then calling Assert rather than
panic might be a good plan. but in general i think this all works ok,
and we can leave the panics alone.

https://codereview.appspot.com/6775079/diff/1/testing/mgo.go#newcode117
testing/mgo.go:117: panic(err)
ditto

https://codereview.appspot.com/6775079/diff/1/testing/mgo.go#newcode122
testing/mgo.go:122: panic(err)
ditto

https://codereview.appspot.com/6775079/diff/1/testing/mgo.go#newcode130
testing/mgo.go:130: panic(fmt.Errorf("Cannot drop MongoDB database %v:
%v", name, err))
ditto

https://codereview.appspot.com/6775079/

Unmerged revisions

700. By Dave Cheney

pass C to MgoReset

699. By Dave Cheney

store: prefer c.Assert to panic

Updates #1073125.

Replace a bunch of panics with Asserts to make the underlying issue more obvious.

R=rog
CC=
https://codereview.appspot.com/6818053

698. By Dave Cheney

worker/provisioner: fix race on config reload

Bug #1064144 was cause by a race between the PA reloading it's config -or-
observing a change to the machines collection. This proposal adds an observer
that the tests can use to wait until the PA has ack'd the configuration
change.

R=fwereade, niemeyer
CC=
https://codereview.appspot.com/6742049

697. By William Reade

state: drop obsolete relation lifecycle

drop:

* Relation.EnsureDying
* Relation.EnsureDead
* State.RemoveRelation

...and use Relation.Destroy and RelationUnit.LeaveScope instead throughout.

R=niemeyer
CC=
https://codereview.appspot.com/6812047

696. By William Reade

state: Relation.Destroy

...and `juju remove-relation`, because it's trivial now that Destroy exists.

Points to note:

* Relation.EnsureDying, Relation.EnsureDead, and State.RemoveRelation are
  now obsolete, and will be remove entirely in a followup CL; omitted here
  due to volume of change.
* It's still called remove-relation, instead of destroy-relation + alias,
  because it seems more sensible to fix remove-unit at the same time and it
  also deserves a separate CL IMO.

R=niemeyer
CC=
https://codereview.appspot.com/6783051

695. By Roger Peppe

worker/uniter: make logger predictable

The stdout pipe is closed too early by os/exec;
do the work ourselves to prevent this.

R=dfc, niemeyer
CC=
https://codereview.appspot.com/6774050

694. By William Reade

juju:implement add-relation

R=niemeyer
CC=
https://codereview.appspot.com/6761044

693. By William Reade

upstart: use better Out value

We now use the same value for upstart conf Out fields as we do --log-file
params. No idea what I did to lead myself to think it didn't work...

Also, made log file names more consistent (ie $kind-$name.log, with no
explicit "-agent")

R=rog, niemeyer
CC=
https://codereview.appspot.com/6766051

692. By William Reade

uniter/charm: verify upgrade symlink overwrite

Verifies non-existence of lp:988115 in juju-core

R=niemeyer
CC=
https://codereview.appspot.com/6760046

691. By Frank Mueller

firewaller: integrated global mode

Firewaller now recognizes the global mode. It dies a
port usage counting usage counting and opens each
used port only once and closes it after the last using unit
has gone. The handling of ports in case of a restart has
been removed from this CL to a later one.

R=
CC=
https://codereview.appspot.com/6713054

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/dummy/environs.go'
2--- environs/dummy/environs.go 2012-10-19 09:16:42 +0000
3+++ environs/dummy/environs.go 2012-10-30 15:39:22 +0000
4@@ -22,6 +22,14 @@
5 import (
6 "errors"
7 "fmt"
8+ "net"
9+ "net/http"
10+ "os"
11+ "strings"
12+ "sync"
13+ "time"
14+
15+ "launchpad.net/gocheck"
16 "launchpad.net/juju-core/environs"
17 "launchpad.net/juju-core/environs/config"
18 "launchpad.net/juju-core/log"
19@@ -30,12 +38,6 @@
20 "launchpad.net/juju-core/testing"
21 "launchpad.net/juju-core/trivial"
22 "launchpad.net/juju-core/version"
23- "net"
24- "net/http"
25- "os"
26- "strings"
27- "sync"
28- "time"
29 )
30
31 // stateInfo returns a *state.Info which allows clients to connect to the
32@@ -168,7 +170,7 @@
33 providerInstance.ops = discardOperations
34 providerInstance.state = make(map[string]*environState)
35 if testing.MgoAddr != "" {
36- testing.MgoReset()
37+ testing.MgoReset(new(gocheck.C))
38 }
39 }
40
41@@ -471,7 +473,7 @@
42 defer e.state.mu.Unlock()
43 e.state.ops <- OpDestroy{Env: e.state.name}
44 if testing.MgoAddr != "" {
45- testing.MgoReset()
46+ testing.MgoReset(new(gocheck.C))
47 }
48 e.state.bootstrapped = false
49 e.state.storage.files = make(map[string][]byte)
50
51=== modified file 'state/ssh_test.go'
52--- state/ssh_test.go 2012-09-21 12:01:53 +0000
53+++ state/ssh_test.go 2012-10-30 15:39:22 +0000
54@@ -325,7 +325,7 @@
55 c.Assert(food[0]["spam"], Equals, "lots")
56 c.Assert(food[1]["eggs"], Equals, "fried")
57
58- testing.MgoReset()
59+ testing.MgoReset(c)
60 morefood := make([]map[string]string, 0)
61 err = menu.Find(nil).All(&morefood)
62 c.Assert(err, IsNil)
63
64=== modified file 'testing/mgo.go'
65--- testing/mgo.go 2012-10-12 16:03:12 +0000
66+++ testing/mgo.go 2012-10-30 15:39:22 +0000
67@@ -91,22 +91,20 @@
68 func (s *MgoSuite) TearDownSuite(c *C) {}
69
70 // MgoDial returns a new connection to the shared MongoDB server.
71-func MgoDial() *mgo.Session {
72+func MgoDial(c *C) *mgo.Session {
73 session, err := mgo.Dial(MgoAddr)
74- if err != nil {
75- panic(err)
76- }
77+ c.Assert(err, IsNil)
78 return session
79 }
80
81 func (s *MgoSuite) SetUpTest(c *C) {
82 mgo.ResetStats()
83- s.Session = MgoDial()
84+ s.Session = MgoDial(c)
85 }
86
87 // MgoReset deletes all content from the shared MongoDB server.
88-func MgoReset() {
89- session := MgoDial()
90+func MgoReset(c *C) {
91+ session := MgoDial(c)
92 defer session.Close()
93 dbnames, err := session.DatabaseNames()
94 if isUnauthorized(err) {
95@@ -145,8 +143,10 @@
96 }
97
98 func (s *MgoSuite) TearDownTest(c *C) {
99- MgoReset()
100- s.Session.Close()
101+ MgoReset(c)
102+ if s.Session != nil {
103+ s.Session.Close()
104+ }
105 for i := 0; ; i++ {
106 stats := mgo.GetStats()
107 if stats.SocketsInUse == 0 && stats.SocketsAlive == 0 {
108
109=== modified file 'testing/mgo_test.go'
110--- testing/mgo_test.go 2012-10-10 12:41:22 +0000
111+++ testing/mgo_test.go 2012-10-30 15:39:22 +0000
112@@ -39,7 +39,7 @@
113 }
114
115 func (s *mgoSuite) TestMgoResetWhenUnauthorized(c *C) {
116- session := testing.MgoDial()
117+ session := testing.MgoDial(c)
118 defer session.Close()
119 err := session.DB("admin").AddUser("admin", "foo", false)
120 if err != nil && err.Error() != "need to login" {
121@@ -51,7 +51,7 @@
122 func (s *mgoSuite) TestMgoStartAndClean(c *C) {
123 c.Assert(testing.MgoAddr, Not(Equals), "")
124
125- session := testing.MgoDial()
126+ session := testing.MgoDial(c)
127 defer session.Close()
128 menu := session.DB("food").C("menu")
129 err := menu.Insert(
130@@ -66,7 +66,7 @@
131 c.Assert(food[0]["spam"], Equals, "lots")
132 c.Assert(food[1]["eggs"], Equals, "fried")
133
134- testing.MgoReset()
135+ testing.MgoReset(c)
136 morefood := make([]map[string]string, 0)
137 err = menu.Find(nil).All(&morefood)
138 c.Assert(err, IsNil)

Subscribers

People subscribed via source and target branches