Merge lp:~pedronis/ubuntu-push/server-tweaks into lp:ubuntu-push

Proposed by Samuele Pedroni
Status: Merged
Approved by: John Lenton
Approved revision: 92
Merged at revision: 92
Proposed branch: lp:~pedronis/ubuntu-push/server-tweaks
Merge into: lp:ubuntu-push
Prerequisite: lp:~pedronis/ubuntu-push/compare-config
Diff against target: 122 lines (+25/-11)
5 files modified
server/acceptance/suites/helpers.go (+2/-2)
server/acceptance/suites/suite.go (+4/-3)
server/dev/server.go (+1/-1)
server/runner_http.go (+8/-4)
server/runner_test.go (+10/-1)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/server-tweaks
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+212944@code.launchpad.net

Commit message

let HTTPServeRunner adopt a listener optionally; capture kill function that can send any signal in acceptance tests

Description of the change

* let HTTPServeRunner adopt a listener optionally
* capture kill function that can send any signal in acceptance tests

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'server/acceptance/suites/helpers.go'
2--- server/acceptance/suites/helpers.go 2014-03-03 16:55:55 +0000
3+++ server/acceptance/suites/helpers.go 2014-03-26 20:10:16 +0000
4@@ -81,7 +81,7 @@
5
6 // RunAndObserve runs cmdName and returns a channel that will receive
7 // cmdName stderr logging and a function to kill the process.
8-func RunAndObserve(c *C, cmdName string, arg ...string) (<-chan string, func()) {
9+func RunAndObserve(c *C, cmdName string, arg ...string) (<-chan string, func(os.Signal)) {
10 cmd := exec.Command(cmdName, arg...)
11 stderr, err := cmd.StderrPipe()
12 if err != nil {
13@@ -127,7 +127,7 @@
14 logs <- info
15 }
16 }()
17- return logs, func() { cmd.Process.Kill() }
18+ return logs, func(sig os.Signal) { cmd.Process.Signal(sig) }
19 }
20
21 const (
22
23=== modified file 'server/acceptance/suites/suite.go'
24--- server/acceptance/suites/suite.go 2014-03-05 17:37:12 +0000
25+++ server/acceptance/suites/suite.go 2014-03-26 20:10:16 +0000
26@@ -25,6 +25,7 @@
27 "io/ioutil"
28 "net"
29 "net/http"
30+ "os"
31 "runtime"
32 "time"
33
34@@ -77,7 +78,7 @@
35 ServerAPIURL string
36 // KillGroup should be populated by StartServer with functions
37 // to kill the server process
38- KillGroup map[string]func()
39+ KillGroup map[string]func(os.Signal)
40 // hook to adjust requests
41 MassageRequest func(req *http.Request) *http.Request
42 // other state
43@@ -86,7 +87,7 @@
44
45 // Start a new server for each test.
46 func (s *AcceptanceSuite) SetUpTest(c *C) {
47- s.KillGroup = make(map[string]func())
48+ s.KillGroup = make(map[string]func(os.Signal))
49 s.StartServer(c, s, &s.ServerHandle)
50 c.Assert(s.ServerHandle.ServerEvents, NotNil)
51 c.Assert(s.ServerHandle.ServerAddr, Not(Equals), "")
52@@ -96,7 +97,7 @@
53
54 func (s *AcceptanceSuite) TearDownTest(c *C) {
55 for _, f := range s.KillGroup {
56- f()
57+ f(os.Kill)
58 }
59 }
60
61
62=== modified file 'server/dev/server.go'
63--- server/dev/server.go 2014-03-06 19:21:44 +0000
64+++ server/dev/server.go 2014-03-26 20:10:16 +0000
65@@ -62,7 +62,7 @@
66 }
67 mux := api.MakeHandlersMux(storeForRequest, broker, logger)
68 handler := api.PanicTo500Handler(mux, logger)
69- go server.HTTPServeRunner(handler, &cfg.HTTPServeParsedConfig)()
70+ go server.HTTPServeRunner(nil, handler, &cfg.HTTPServeParsedConfig)()
71 // listen for device connections
72 server.DevicesRunner(nil, func(conn net.Conn) error {
73 track := session.NewTracker(logger)
74
75=== modified file 'server/runner_http.go'
76--- server/runner_http.go 2014-02-10 23:19:08 +0000
77+++ server/runner_http.go 2014-03-26 20:10:16 +0000
78@@ -31,10 +31,14 @@
79 }
80
81 // HTTPServeRunner returns a function to serve HTTP requests.
82-func HTTPServeRunner(h http.Handler, parsedCfg *HTTPServeParsedConfig) func() {
83- httpLst, err := net.Listen("tcp", parsedCfg.ParsedHTTPAddr.HostPort())
84- if err != nil {
85- BootLogFatalf("start http listening: %v", err)
86+// If httpLst is not nil it will be used as the underlying listener.
87+func HTTPServeRunner(httpLst net.Listener, h http.Handler, parsedCfg *HTTPServeParsedConfig) func() {
88+ if httpLst == nil {
89+ var err error
90+ httpLst, err = net.Listen("tcp", parsedCfg.ParsedHTTPAddr.HostPort())
91+ if err != nil {
92+ BootLogFatalf("start http listening: %v", err)
93+ }
94 }
95 BootLogListener("http", httpLst)
96 srv := &http.Server{
97
98=== modified file 'server/runner_test.go'
99--- server/runner_test.go 2014-03-06 19:21:44 +0000
100+++ server/runner_test.go 2014-03-26 20:10:16 +0000
101@@ -68,7 +68,7 @@
102 func (s *runnerSuite) TestHTTPServeRunner(c *C) {
103 errCh := make(chan interface{}, 1)
104 h := http.HandlerFunc(testHandle)
105- runner := HTTPServeRunner(h, &testHTTPServeParsedConfig)
106+ runner := HTTPServeRunner(nil, h, &testHTTPServeParsedConfig)
107 c.Assert(s.lst, Not(IsNil))
108 defer s.lst.Close()
109 c.Check(s.kind, Equals, "http")
110@@ -130,3 +130,12 @@
111 c.Check(s.lst.Addr().String(), Equals, lst0.Addr().String())
112 s.lst.Close()
113 }
114+
115+func (s *runnerSuite) TestHTTPServeRunnerAdoptListener(c *C) {
116+ lst0, err := net.Listen("tcp", "127.0.0.1:0")
117+ c.Assert(err, IsNil)
118+ defer lst0.Close()
119+ HTTPServeRunner(lst0, nil, &testHTTPServeParsedConfig)
120+ c.Assert(s.lst, Equals, lst0)
121+ c.Check(s.kind, Equals, "http")
122+}

Subscribers

People subscribed via source and target branches