mattermost/server/channels/jobs/base_workers_test.go
Claudio Costa 611b2a8e79
[MM-62408] Server Code Coverage with Fully Parallel Tests (#30078)
* TestPool

* Store infra

* Store tests updates

* Bump maximum concurrent postgres connections

* More infra

* channels/jobs

* channels/app

* channels/api4

* Protect i18n from concurrent access

* Replace some use of os.Setenv

* Remove debug

* Lint fixes

* Fix more linting

* Fix test

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix merge

* [MM-62408] Add CI job to generate test coverage (#30284)

* Add CI job to generate test coverage

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix more Setenv usage

* Fix more potential flakyness

* Remove parallelism from flaky test

* Remove conflicting env var

* Fix

* Disable parallelism

* Test atomic covermode

* Disable parallelism

* Enable parallelism

* Add upload coverage step

* Fix codecov.yml

* Add codecov.yml

* Remove redundant workspace field

* Add Parallel() util methods and refactor

* Fix formatting

* More formatting fixes

* Fix reporting
2025-05-30 13:58:26 +02:00

47 lines
1.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package jobs
import (
"errors"
"os"
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestSimpleWorkerPanic(t *testing.T) {
if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" {
t.Parallel()
}
jobServer, mockStore, mockMetrics := makeJobServer(t)
job := &model.Job{
Id: "job_id",
Type: "job_type",
}
exec := func(_ mlog.LoggerIFace, _ *model.Job) error {
return nil
}
isEnabled := func(_ *model.Config) bool {
return true
}
mockStore.JobStore.On("UpdateStatusOptimistically", "job_id", model.JobStatusPending, model.JobStatusInProgress).Return(&model.Job{Id: "job_id", Type: "job_type"}, nil)
mockStore.JobStore.On("UpdateOptimistically", mock.AnythingOfType("*model.Job"), model.JobStatusInProgress).Return(true, nil)
mockStore.JobStore.On("UpdateStatus", "job_id", "success").Return(nil, errors.New("test"))
mockMetrics.On("IncrementJobActive", "job_type")
mockMetrics.On("DecrementJobActive", "job_type")
sWorker := NewSimpleWorker("test", jobServer, exec, isEnabled)
require.NotPanics(t, func() {
sWorker.DoJob(job)
})
}