mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 05:52:10 +00:00
d26fce3995
(cherry picked from commite1bbfa3619
) (cherry picked from commit91245ca917
) (cherry picked from commit705d0558be
) (cherry picked from commit9247594970
) (cherry picked from commit9db1158a48
) (cherry picked from commit3b36b77d87
) (cherry picked from commit162fa1d8ae
) (cherry picked from commitd03d0afbb5
) (cherry picked from commit7b8f92f787
) (cherry picked from commit035abca969
) (cherry picked from commita8fbf6bb56
) (cherry picked from commit 3be681d037b07880236cae1aa70245e5eb4d1497) (cherry picked from commit7e5d471c83
) (cherry picked from commit323801d935
) (cherry picked from commit3fdfe4bfea
) (cherry picked from commit58a07421a4
) (cherry picked from commitdbb71a4c85
) (cherry picked from commitd442113520
) (cherry picked from commitd3329f01f8
) (cherry picked from commit069a1d68b8
) (cherry picked from commit14919e609a
) (cherry picked from commit49b76be106
) (cherry picked from commit0fe9f257d2
) (cherry picked from commitb583bebeab
) (cherry picked from commit5c616e43a6
) (cherry picked from commit854bcea905
) (cherry picked from commitc2acb181c5
) (cherry picked from commit1cb07e71d1
) (cherry picked from commit5d3f09e635
) (cherry picked from commitf8bf1c8d42
) (cherry picked from commita471ed4576
) (cherry picked from commit95c755f4e3
) (cherry picked from commit1d8bc5215f
) (cherry picked from commit45c1e7b8d0
) (cherry picked from commit2eb4d93af7
) (cherry picked from commit98dbce5e14
) (cherry picked from commitfbe2fb5861
)
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package queue
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
"time"
|
|
|
|
"code.gitea.io/gitea/modules/nosql"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func waitRedisReady(conn string, dur time.Duration) (ready bool) {
|
|
ctxTimed, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
|
defer cancel()
|
|
for t := time.Now(); ; time.Sleep(50 * time.Millisecond) {
|
|
ret := nosql.GetManager().GetRedisClient(conn).Ping(ctxTimed)
|
|
if ret.Err() == nil {
|
|
return true
|
|
}
|
|
if time.Since(t) > dur {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
func redisServerCmd(t *testing.T) *exec.Cmd {
|
|
redisServerProg, err := exec.LookPath("redis-server")
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
c := &exec.Cmd{
|
|
Path: redisServerProg,
|
|
Args: []string{redisServerProg, "--bind", "127.0.0.1", "--port", "6379"},
|
|
Dir: t.TempDir(),
|
|
Stdin: os.Stdin,
|
|
Stdout: os.Stdout,
|
|
Stderr: os.Stderr,
|
|
}
|
|
return c
|
|
}
|
|
|
|
func TestBaseRedis(t *testing.T) {
|
|
var redisServer *exec.Cmd
|
|
defer func() {
|
|
if redisServer != nil {
|
|
_ = redisServer.Process.Signal(os.Interrupt)
|
|
_ = redisServer.Wait()
|
|
}
|
|
}()
|
|
if !waitRedisReady("redis://127.0.0.1:6379/0", 0) {
|
|
redisServer = redisServerCmd(t)
|
|
if true {
|
|
t.Skip("redis-server not found in Forgejo test yet")
|
|
return
|
|
}
|
|
assert.NoError(t, redisServer.Start())
|
|
if !assert.True(t, waitRedisReady("redis://127.0.0.1:6379/0", 5*time.Second), "start redis-server") {
|
|
return
|
|
}
|
|
}
|
|
|
|
testQueueBasic(t, newBaseRedisSimple, toBaseConfig("baseRedis", setting.QueueSettings{Length: 10}), false)
|
|
testQueueBasic(t, newBaseRedisUnique, toBaseConfig("baseRedisUnique", setting.QueueSettings{Length: 10}), true)
|
|
}
|