mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-12 03:03:38 +02:00
`modules/queue` tests are intended to be running against a redis server in the test-remote-cacher workflow action, but they are not running because the tests always try to start a redis server by running a `redis-server` subprocess. If that subprocess fails to start, the tests are skipped. This change forces the tests to execute whenever `TEST_REDIS_SERVER` is present, and removes the unnecessary Forgejo-managed redis server during testing. This change is tested manually; if `TEST_REDIS_SERVER` is set to an invalid value, the tests fail, when previously it could be set to any value and the tests would always be skipped. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10139 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package queue
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"forgejo.org/modules/setting"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type baseRedisWithServerTestSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func TestBaseRedisWithServer(t *testing.T) {
|
|
suite.Run(t, &baseRedisWithServerTestSuite{})
|
|
}
|
|
|
|
func (suite *baseRedisWithServerTestSuite) TestNormal() {
|
|
redisAddress := "redis://" + suite.testRedisHost() + "/0"
|
|
queueSettings := setting.QueueSettings{
|
|
Length: 10,
|
|
ConnStr: redisAddress,
|
|
}
|
|
|
|
testQueueBasic(suite.T(), newBaseRedisSimple, toBaseConfig("baseRedis", queueSettings), false)
|
|
testQueueBasic(suite.T(), newBaseRedisUnique, toBaseConfig("baseRedisUnique", queueSettings), true)
|
|
}
|
|
|
|
func (suite *baseRedisWithServerTestSuite) TestWithPrefix() {
|
|
redisAddress := "redis://" + suite.testRedisHost() + "/0?prefix=forgejo:queue:"
|
|
queueSettings := setting.QueueSettings{
|
|
Length: 10,
|
|
ConnStr: redisAddress,
|
|
}
|
|
|
|
testQueueBasic(suite.T(), newBaseRedisSimple, toBaseConfig("baseRedis", queueSettings), false)
|
|
testQueueBasic(suite.T(), newBaseRedisUnique, toBaseConfig("baseRedisUnique", queueSettings), true)
|
|
}
|
|
|
|
func (suite *baseRedisWithServerTestSuite) testRedisHost() string {
|
|
host := os.Getenv("TEST_REDIS_SERVER")
|
|
if host == "" {
|
|
suite.T().Skip("redis-server not found in Forgejo test yet")
|
|
}
|
|
return host
|
|
}
|