summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-11-13 13:59:51 -0600
committerChristopher Speller <crspeller@gmail.com>2017-11-13 11:59:51 -0800
commit865f9f83a7cf2f9eb1fe2735b6bd498f56486f50 (patch)
tree2554279f7682599ca69370557194dfa984557db3 /app
parent1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (diff)
downloadchat-865f9f83a7cf2f9eb1fe2735b6bd498f56486f50.tar.gz
chat-865f9f83a7cf2f9eb1fe2735b6bd498f56486f50.tar.bz2
chat-865f9f83a7cf2f9eb1fe2735b6bd498f56486f50.zip
Improve test coverage reporting / accuracy (#7819)
* improve test coverage reporting / accuracy * handle absolute coverpaths * move tests into multiple files * rename codecov.yml (https://github.com/codecov/support/issues/426)
Diffstat (limited to 'app')
-rw-r--r--app/app_test.go1
-rw-r--r--app/web_hub.go4
-rw-r--r--app/web_hub_test.go60
3 files changed, 63 insertions, 2 deletions
diff --git a/app/app_test.go b/app/app_test.go
index 17189956d..2058ddd79 100644
--- a/app/app_test.go
+++ b/app/app_test.go
@@ -48,6 +48,7 @@ func TestMain(m *testing.M) {
func TestAppRace(t *testing.T) {
for i := 0; i < 10; i++ {
a := New()
+ a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
a.StartServer()
a.Shutdown()
}
diff --git a/app/web_hub.go b/app/web_hub.go
index c8c650246..eeae13e09 100644
--- a/app/web_hub.go
+++ b/app/web_hub.go
@@ -50,7 +50,7 @@ func (a *App) NewWebHub() *Hub {
connections: make([]*WebConn, 0, model.SESSION_CACHE_SIZE),
broadcast: make(chan *model.WebSocketEvent, BROADCAST_QUEUE_SIZE),
stop: make(chan struct{}),
- didStop: make(chan struct{}, 1),
+ didStop: make(chan struct{}),
invalidateUser: make(chan string),
ExplicitStop: false,
}
@@ -446,7 +446,7 @@ func (h *Hub) Start() {
h.connections = make([]*WebConn, 0, model.SESSION_CACHE_SIZE)
h.ExplicitStop = true
- h.didStop <- struct{}{}
+ close(h.didStop)
return
}
diff --git a/app/web_hub_test.go b/app/web_hub_test.go
new file mode 100644
index 000000000..62c2552de
--- /dev/null
+++ b/app/web_hub_test.go
@@ -0,0 +1,60 @@
+package app
+
+import (
+ "net"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/gorilla/websocket"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
+ "github.com/stretchr/testify/require"
+
+ "github.com/mattermost/mattermost-server/model"
+)
+
+func dummyWebsocketHandler(t *testing.T) http.HandlerFunc {
+ return func(w http.ResponseWriter, req *http.Request) {
+ upgrader := &websocket.Upgrader{
+ ReadBufferSize: 1024,
+ WriteBufferSize: 1024,
+ }
+ conn, err := upgrader.Upgrade(w, req, nil)
+ for err == nil {
+ _, _, err = conn.ReadMessage()
+ }
+ if _, ok := err.(*websocket.CloseError); !ok {
+ require.NoError(t, err)
+ }
+ }
+}
+
+func registerDummyWebConn(t *testing.T, a *App, addr net.Addr, userId string) *WebConn {
+ session, appErr := a.CreateSession(&model.Session{
+ UserId: userId,
+ })
+ require.Nil(t, appErr)
+
+ d := websocket.Dialer{}
+ c, _, err := d.Dial("ws://"+addr.String()+"/ws", nil)
+ require.NoError(t, err)
+
+ wc := a.NewWebConn(c, *session, goi18n.IdentityTfunc(), "en")
+ a.HubRegister(wc)
+ go wc.Pump()
+ return wc
+}
+
+func TestHubStopWithMultipleConnections(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ s := httptest.NewServer(http.HandlerFunc(dummyWebsocketHandler(t)))
+ defer s.Close()
+
+ th.App.HubStart()
+ registerDummyWebConn(t, th.App, s.Listener.Addr(), th.BasicUser.Id)
+ registerDummyWebConn(t, th.App, s.Listener.Addr(), th.BasicUser.Id)
+ registerDummyWebConn(t, th.App, s.Listener.Addr(), th.BasicUser.Id)
+ th.App.HubStop()
+}