1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00
focalboard/server/utils/callbackqueue_test.go
Rajat Dabade c8e729b6fe
[Refactor]: updated dependency for focalboard server (#5009)
* refactor: updated dependency for focalboard server

* chore: more dependency fixes

* refactor: removed the unless code

* refactor: added ctx for login and removed unnessary code

* refactor: bump up go version

* refactor: removed the commented code

* chore: upgraded golinter version

* fix: linter issue

* refactor: removed feature flg fix golinter

* refactor: removed feature flag from code

* revert: statistic and it's function

* refactor: removed ProductLimit related code

* refactor: removed isWithinViewsLimit implementation

* refactor: moved function GetUsedCardsCount to statistics.go from cloud.go

* refactor: removed insight code board

* refactor: removed limit dialog

* refactor: updated dependencies for linux

* chore: golinter fix

* chore: updated helper test function to use newLogger

* fix: go test

* refactor: db ping attempts from config

* revert: feature in action

* revert: feature flag in action

* revert: boardsEditor setting

---------

Co-authored-by: Rajat Dabade <rajat@Rajats-MacBook-Pro.local>
2024-06-07 23:30:08 +05:30

65 lines
1.4 KiB
Go

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(t)
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))
})
}