mattermost/server/channels/store/sqlstore/context_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

63 lines
1.6 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package sqlstore
import (
"context"
"testing"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/stretchr/testify/assert"
)
func TestContextMaster(t *testing.T) {
if enableFullyParallelTests {
t.Parallel()
}
ctx := context.Background()
m := WithMaster(ctx)
assert.True(t, HasMaster(m))
}
func TestRequestContextWithMaster(t *testing.T) {
if enableFullyParallelTests {
t.Parallel()
}
t.Run("set and get", func(t *testing.T) {
var rctx request.CTX = request.TestContext(t)
rctx = RequestContextWithMaster(rctx)
assert.True(t, HasMaster(rctx.Context()))
})
t.Run("values get copied from original context", func(t *testing.T) {
var rctx request.CTX = request.TestContext(t)
rctx = RequestContextWithMaster(rctx)
rctxCopy := rctx
assert.True(t, HasMaster(rctx.Context()))
assert.True(t, HasMaster(rctxCopy.Context()))
})
t.Run("directly assigning does not cause the copy to alter the original context", func(t *testing.T) {
var rctx request.CTX = request.TestContext(t)
rctxCopy := rctx
rctxCopy = RequestContextWithMaster(rctxCopy)
assert.False(t, HasMaster(rctx.Context()))
assert.True(t, HasMaster(rctxCopy.Context()))
})
t.Run("directly assigning does not cause the original context to alter the copy", func(t *testing.T) {
var rctx request.CTX = request.TestContext(t)
rctxCopy := rctx
rctx = RequestContextWithMaster(rctx)
assert.True(t, HasMaster(rctx.Context()))
assert.False(t, HasMaster(rctxCopy.Context()))
})
}