forked from p93542168/wheat-cache
33 lines
806 B
Go
33 lines
806 B
Go
package lru
|
|
|
|
import (
|
|
"context"
|
|
"gitee.com/timedb/wheatCache/pkg/event"
|
|
"gitee.com/timedb/wheatCache/pkg/proto"
|
|
"gitee.com/timedb/wheatCache/pkg/structure/stringx"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWorker(t *testing.T) {
|
|
ctx := context.Background()
|
|
lru := NewLRUCache()
|
|
produce := event.NewProduce(lru.GetDriver())
|
|
workEvent := event.NewEvent(OptionEventName)
|
|
workEvent.SetValue(WorkFuncEventKey, event.EventWorkFunc(func() (interface{}, error) {
|
|
v1 := stringx.NewStringSingle()
|
|
key := proto.BaseKey{
|
|
Key: "v1",
|
|
}
|
|
res, _ := v1.Set("123")
|
|
lru.Add(&key, v1)
|
|
return res, nil
|
|
}))
|
|
workEvent.InitWaitEvent()
|
|
produce.Call(ctx, workEvent)
|
|
res, err := workEvent.StartWaitEvent(2 * time.Second)
|
|
require.NoError(t, err)
|
|
require.Equal(t, res, "123")
|
|
}
|