mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-18 18:18:23 -05:00
MM-26167: improve CreatePostCheckOnlineStatus (#14827)
* Improve CreatePostCheckOnlineStatus We improve the flakyness of the test by making the websocket status checks synchronous after making each request. This makes the status responses more reliable because in very busy CI environments the goroutine scheduler can indeed send the response which is made by a later HTTP request before the first one. * Update api4/post_test.go Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
This commit is contained in:
parent
66597d0fcb
commit
c58edbf622
1 changed files with 10 additions and 23 deletions
|
|
@ -12,7 +12,6 @@ import (
|
|||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -598,40 +597,26 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
|||
_, loginResp := cli.Login(th.BasicUser2.Username, th.BasicUser2.Password)
|
||||
require.Nil(t, loginResp.Error)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wsClient, err := th.CreateWebSocketClientWithClient(cli)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
wg.Wait()
|
||||
wsClient.Close()
|
||||
}()
|
||||
defer wsClient.Close()
|
||||
|
||||
wsClient.Listen()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
timeout := time.After(2 * time.Second)
|
||||
cnt := true
|
||||
i := 0
|
||||
for cnt {
|
||||
waitForEvent := func(isSetOnline bool) {
|
||||
timeout := time.After(5 * time.Second)
|
||||
for {
|
||||
select {
|
||||
case ev := <-wsClient.EventChannel:
|
||||
if ev.EventType() == model.WEBSOCKET_EVENT_POSTED {
|
||||
if i == 0 {
|
||||
assert.False(t, ev.GetData()["set_online"].(bool))
|
||||
} else {
|
||||
assert.True(t, ev.GetData()["set_online"].(bool))
|
||||
}
|
||||
i++
|
||||
assert.True(t, ev.GetData()["set_online"].(bool) == isSetOnline)
|
||||
return
|
||||
}
|
||||
cnt = i != 2
|
||||
case <-timeout:
|
||||
cnt = false
|
||||
require.Fail(t, "timed out waiting for event")
|
||||
}
|
||||
}
|
||||
assert.Equal(t, 2, i, "unexpected number of posted events")
|
||||
}()
|
||||
}
|
||||
|
||||
handler := api.ApiHandler(createPost)
|
||||
resp := httptest.NewRecorder()
|
||||
|
|
@ -645,6 +630,7 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
|||
|
||||
handler.ServeHTTP(resp, req)
|
||||
assert.Equal(t, http.StatusCreated, resp.Code)
|
||||
waitForEvent(false)
|
||||
|
||||
_, err = th.App.GetStatus(th.BasicUser.Id)
|
||||
require.NotNil(t, err)
|
||||
|
|
@ -655,6 +641,7 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
|||
|
||||
handler.ServeHTTP(resp, req)
|
||||
assert.Equal(t, http.StatusCreated, resp.Code)
|
||||
waitForEvent(true)
|
||||
|
||||
st, err := th.App.GetStatus(th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue