Skip to content

Commit

Permalink
[TEST] improve webserver with panic
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Oct 11, 2017
1 parent 557a440 commit 5ed98f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
4 changes: 3 additions & 1 deletion webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func New(bindAddr, webroot string) *http.Server {
func Start(srv *http.Server) {
// service connections
if err := srv.ListenAndServe(); err != nil {
panic(err)
if err != http.ErrServerClosed {
panic(err)
}
}
}
13 changes: 1 addition & 12 deletions webserver/webserver_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package webserver

import (
"fmt"
"testing"
"time"

Expand All @@ -14,17 +13,7 @@ func TestWebserver(t *testing.T) {
srv := New(":8080", "/tmp")
assert.NotNil(srv)

go func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("catch valid panic")
assert.Equal("http: Server closed", r)
}
}()

Start(srv)

}()
go Start(srv)

time.Sleep(time.Millisecond * 200)

Expand Down

0 comments on commit 5ed98f3

Please sign in to comment.