mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
It was a good decision in hindsight to keep the public module as 0.x because this would have been a breaking change again. https://mattermost.atlassian.net/browse/MM-53032 ```release-note Changed the Go module path from github.com/mattermost/mattermost-server/server/v8 to github.com/mattermost/mattermost/server/v8. For the public facing module, it's path is also changed from github.com/mattermost/mattermost-server/server/public to github.com/mattermost/mattermost/server/public ```
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
|
)
|
|
|
|
func Test_newChangeNotifier(t *testing.T) {
|
|
logger := mlog.CreateConsoleTestLogger(false, mlog.LvlDebug)
|
|
|
|
t.Run("startup, shutdown", func(t *testing.T) {
|
|
cn := NewCallbackQueue("test1", 100, 5, logger)
|
|
|
|
var callbackCount int32
|
|
callback := func() error {
|
|
atomic.AddInt32(&callbackCount, 1)
|
|
return nil
|
|
}
|
|
|
|
const loops = 500
|
|
for i := 0; i < loops; i++ {
|
|
cn.Enqueue(callback)
|
|
// don't peg the cpu
|
|
if i%20 == 0 {
|
|
time.Sleep(time.Millisecond * 1)
|
|
}
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
defer cancel()
|
|
ok := cn.Shutdown(ctx)
|
|
assert.True(t, ok, "shutdown should return true (no timeout)")
|
|
|
|
assert.Equal(t, int32(loops), atomic.LoadInt32(&callbackCount))
|
|
})
|
|
|
|
t.Run("handle panic", func(t *testing.T) {
|
|
cn := NewCallbackQueue("test2", 100, 5, logger)
|
|
|
|
var callbackCount int32
|
|
callback := func() error {
|
|
atomic.AddInt32(&callbackCount, 1)
|
|
panic("oh no!")
|
|
}
|
|
|
|
const loops = 5
|
|
for i := 0; i < loops; i++ {
|
|
cn.Enqueue(callback)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
defer cancel()
|
|
ok := cn.Shutdown(ctx)
|
|
assert.True(t, ok, "shutdown should return true (no timeout)")
|
|
|
|
assert.Equal(t, int32(loops), atomic.LoadInt32(&callbackCount))
|
|
})
|
|
}
|