Skip to content

Commit

Permalink
Merge pull request #309 from rmohr/console_tests
Browse files Browse the repository at this point in the history
tests: Wait until console handler is done before checking mocks
  • Loading branch information
stu-gott committed Jul 11, 2017
2 parents d6760ca + 5a5b756 commit 7050566
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/virt-handler/rest/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var _ = Describe("Console", func() {
var mockRecorder *record.FakeRecorder
var server *httptest.Server
var wsUrl *url.URL
var serverDone chan bool

logging.DefaultLogger().SetIOWriter(GinkgoWriter)

Expand Down Expand Up @@ -79,7 +80,14 @@ var _ = Describe("Console", func() {
ws := new(restful.WebService)
handler = http.Handler(restful.NewContainer().Add(ws))

ws.Route(ws.GET("/api/v1/console/{name}").To(NewConsoleResource(mockConn).Console))
// Give us a chance to detect when the request is done. Otherwise we
// don't know when to check mock invokations
serverDone = make(chan bool)
waiter := func(request *restful.Request, response *restful.Response) {
NewConsoleResource(mockConn).Console(request, response)
close(serverDone)
}
ws.Route(ws.GET("/api/v1/console/{name}").To(waiter))
server = httptest.NewServer(handler)
wsUrl, err = url.Parse(server.URL)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -174,8 +182,9 @@ var _ = Describe("Console", func() {

})
AfterEach(func() {
ctrl.Finish()
server.Close()
<-serverDone
ctrl.Finish()
})
})

Expand Down

0 comments on commit 7050566

Please sign in to comment.