Skip to content

Commit

Permalink
test: fix unit test of error keys
Browse files Browse the repository at this point in the history
  • Loading branch information
vie-serendipity committed Jul 11, 2024
1 parent e0ee396 commit fef58c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/yurthub/cachemanager/error_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ import (
"sync"
"time"

"github.com/openyurtio/openyurt/pkg/projectinfo"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"

"github.com/openyurtio/openyurt/pkg/projectinfo"
)

var (
AOFPrefix = "/var/lib/" + projectinfo.GetHubName()
)

var (
const (
CompressThresh = 20
)

Expand All @@ -53,7 +54,7 @@ func NewErrorKeys() *errorKeys {
keys: make(map[string]string),
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter(), "error-keys"),
}
err := os.MkdirAll(AOFPrefix, 0644)
err := os.MkdirAll(AOFPrefix, 0755)
if err != nil {
klog.Errorf("failed to create dir: %v", err)
return ek
Expand Down
9 changes: 7 additions & 2 deletions pkg/yurthub/cachemanager/error_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestRecover(t *testing.T) {
if err != nil {
t.Errorf("failed to marshal: %v", err)
}
AOFPrefix = "/tmp/errorkeys"
err = os.MkdirAll(AOFPrefix, 0755)
if err != nil {
t.Errorf("failed to create dir: %v", err)
Expand All @@ -112,7 +113,11 @@ func TestRecover(t *testing.T) {
}

func TestCompress(t *testing.T) {
os.MkdirAll(AOFPrefix, 0644)
AOFPrefix = "/tmp/errorkeys"
err := os.MkdirAll(AOFPrefix, 0755)
if err != nil {
t.Errorf("failed to create dir: %v", err)
}
keys := NewErrorKeys()
for i := 0; i < 50; i++ {
keys.put(fmt.Sprintf("key-%d", i), fmt.Sprintf("value-%d", i))
Expand All @@ -123,7 +128,7 @@ func TestCompress(t *testing.T) {
for i := 0; i < 25; i++ {
keys.put(fmt.Sprintf("key-%d", i), fmt.Sprintf("value-%d", i))
}
err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false,
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false,
func(ctx context.Context) (bool, error) {
if keys.count == 50 {
return true, nil
Expand Down

0 comments on commit fef58c3

Please sign in to comment.