~go-bot/juju-core/trunk

« back to all changes in this revision

Viewing changes to testing/mgo.go

[r=jameinel],[bug=1301353] testing/mgo: use /usr/lib/juju/bin/mongod

As part of fixing bug #130135, the test suite can now search PATH for
'mongod' and if it doesn't find it, also search for
'/usr/lib/juju/bin/mongod' and disable the store's JS tests.

I came across some other parts of the codebase that were panic() ing
when mongod failed to start, so I fixed that as well.

https://codereview.appspot.com/100380044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        // Params is a list of additional parameters that will be passed to
61
61
        // the mongod application
62
62
        Params []string
 
63
 
 
64
        // WithoutV8 is true if we believe this Mongo doesn't actually have the
 
65
        // V8 engine
 
66
        WithoutV8 bool
63
67
}
64
68
 
65
69
// Addr returns the address of the MongoDB server.
112
116
                inst.port = 0
113
117
                os.RemoveAll(inst.dir)
114
118
                inst.dir = ""
115
 
                return err
 
119
                logger.Warningf("failed to start mongo: %v", err)
 
120
        } else {
 
121
                logger.Debugf("started mongod pid %d in %s on port %d", inst.server.Process.Pid, dbdir, inst.port)
116
122
        }
117
 
        logger.Debugf("started mongod pid %d in %s on port %d", inst.server.Process.Pid, dbdir, inst.port)
118
 
        return nil
 
123
        return err
119
124
}
120
125
 
121
126
// run runs the MongoDB server at the
147
152
        if inst.Params != nil {
148
153
                mgoargs = append(mgoargs, inst.Params...)
149
154
        }
150
 
        server := exec.Command("mongod", mgoargs...)
 
155
        // Look for mongod first. This is so we can run the V8 tests for the
 
156
        // store
 
157
        mongopath, err := exec.LookPath("mongod")
 
158
        if err != nil {
 
159
                logger.Debugf("failed to find 'mongodb', in PATH, looking for /usr/lib/juju/bin/mongod")
 
160
                mongopath, err = exec.LookPath("/usr/lib/juju/bin/mongod")
 
161
                if err != nil {
 
162
                        return err
 
163
                }
 
164
                inst.WithoutV8 = true
 
165
        }
 
166
        logger.Debugf("found mongod at: %q", mongopath)
 
167
        server := exec.Command(mongopath, mgoargs...)
151
168
        out, err := server.StdoutPipe()
152
169
        if err != nil {
153
170
                return err
154
171
        }
155
172
        server.Stderr = server.Stdout
156
173
        exited := make(chan struct{})
157
 
        started := make(chan struct{})
 
174
        started := make(chan error)
158
175
        listening := make(chan error, 1)
159
176
        go func() {
160
 
                <-started
 
177
                err := <-started
 
178
                if err != nil {
 
179
                        close(listening)
 
180
                        close(exited)
 
181
                        return
 
182
                }
161
183
                // Wait until the server is listening.
162
184
                var buf bytes.Buffer
163
185
                prefix := fmt.Sprintf("mongod:%v", mgoport)
183
205
        }()
184
206
        inst.exited = exited
185
207
        err = server.Start()
186
 
        close(started)
 
208
        started <- err
187
209
        if err != nil {
188
210
                return err
189
211
        }
239
261
 
240
262
func (s *MgoSuite) SetUpSuite(c *gc.C) {
241
263
        if MgoServer.addr == "" {
242
 
                panic("MgoSuite tests must be run with MgoTestPackage")
 
264
                c.Fatalf("No Mongo Server Address, MgoSuite tests must be run with MgoTestPackage")
243
265
        }
244
266
        mgo.SetDebug(true)
245
267
        mgo.SetStats(true)