snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
74
modules/setting/global_lock_test.go
Normal file
74
modules/setting/global_lock_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package setting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLoadGlobalLockConfig(t *testing.T) {
|
||||
t.Run("DefaultGlobalLockConfig", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&Redis)()
|
||||
iniStr := ``
|
||||
cfg, err := NewConfigProviderFromData(iniStr)
|
||||
assert.NoError(t, err)
|
||||
loadRedisFrom(cfg)
|
||||
loadGlobalLockFrom(cfg)
|
||||
assert.Equal(t, "memory", GlobalLock.ServiceType)
|
||||
})
|
||||
|
||||
t.Run("RedisGlobalLockConfig", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&Redis)()
|
||||
iniStr := `
|
||||
[global_lock]
|
||||
SERVICE_TYPE = redis
|
||||
SERVICE_CONN_STR = addrs=127.0.0.1:6379 db=0
|
||||
`
|
||||
cfg, err := NewConfigProviderFromData(iniStr)
|
||||
assert.NoError(t, err)
|
||||
loadRedisFrom(cfg)
|
||||
loadGlobalLockFrom(cfg)
|
||||
assert.Equal(t, "redis", GlobalLock.ServiceType)
|
||||
assert.Equal(t, "addrs=127.0.0.1:6379 db=0", GlobalLock.ServiceConnStr)
|
||||
})
|
||||
|
||||
t.Run("RedisGlobalLockFallsBackToSharedRedis", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&Redis)()
|
||||
iniStr := `
|
||||
[redis]
|
||||
CONN_STR = redis://127.0.0.1:6379/0
|
||||
[global_lock]
|
||||
SERVICE_TYPE = redis
|
||||
`
|
||||
cfg, err := NewConfigProviderFromData(iniStr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
loadRedisFrom(cfg)
|
||||
loadGlobalLockFrom(cfg)
|
||||
assert.Equal(t, "redis", GlobalLock.ServiceType)
|
||||
assert.Equal(t, "redis://127.0.0.1:6379/0", GlobalLock.ServiceConnStr)
|
||||
})
|
||||
|
||||
t.Run("RedisGlobalLockOwnConnWinsOverSharedRedis", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&Redis)()
|
||||
iniStr := `
|
||||
[redis]
|
||||
CONN_STR = redis://127.0.0.1:6379/0
|
||||
[global_lock]
|
||||
SERVICE_TYPE = redis
|
||||
SERVICE_CONN_STR = redis://10.0.0.1:6379/1
|
||||
`
|
||||
cfg, err := NewConfigProviderFromData(iniStr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
loadRedisFrom(cfg)
|
||||
loadGlobalLockFrom(cfg)
|
||||
assert.Equal(t, "redis", GlobalLock.ServiceType)
|
||||
assert.Equal(t, "redis://10.0.0.1:6379/1", GlobalLock.ServiceConnStr)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user