81 lines
1.4 KiB
Go
81 lines
1.4 KiB
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLockConcurrency(t *testing.T) {
|
|
config := RedisConfig{
|
|
RedisDB: "2",
|
|
RedisAddr: "127.0.0.1:6379",
|
|
RedisPw: "",
|
|
RedisDbName: "2",
|
|
}
|
|
|
|
LoadRedis(config)
|
|
|
|
type args struct {
|
|
key string
|
|
value string
|
|
ms time.Duration
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
{args: args{key: "a:b:c", value: "1", ms: 10000 * time.Millisecond}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got, _ := LockConcurrency(tt.args.key, tt.args.value, tt.args.ms); got != tt.want {
|
|
t.Errorf("LockConcurrency() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRelease(t *testing.T) {
|
|
|
|
config := RedisConfig{
|
|
RedisDB: "2",
|
|
RedisAddr: "127.0.0.1:6379",
|
|
RedisPw: "",
|
|
RedisDbName: "2",
|
|
}
|
|
|
|
LoadRedis(config)
|
|
|
|
key := "abe"
|
|
concurrency, err := LockConcurrency(key, "1", 10*time.Second)
|
|
fmt.Println(concurrency, err)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = Release(key, "2")
|
|
fmt.Println(err)
|
|
|
|
type args struct {
|
|
key string
|
|
value string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := Release(tt.args.key, tt.args.value); (err != nil) != tt.wantErr {
|
|
t.Errorf("Release() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|