Skip to content

Commit

Permalink
feat: add context for api
Browse files Browse the repository at this point in the history
  • Loading branch information
Somiacao authored and zhenghaoz committed Oct 30, 2022
1 parent 17f75d9 commit 3c80d03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions base/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ package log
import (
"github.com/stretchr/testify/assert"
"os"
"runtime"
"testing"
)

func TestSetDevelopmentLogger(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip()
}
temp, err := os.MkdirTemp("", "test_gorse")
assert.NoError(t, err)
// set existed path
Expand All @@ -41,6 +45,9 @@ func TestSetDevelopmentLogger(t *testing.T) {
}

func TestSetProductionLogger(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip()
}
temp, err := os.MkdirTemp("", "test_gorse")
assert.NoError(t, err)
// set existed path
Expand Down
12 changes: 7 additions & 5 deletions server/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ func BenchmarkGetRecommendCache(b *testing.B) {
s := newBenchServer(b)
defer s.Close(b)

ctx := context.Background()
for batchSize := 10; batchSize <= 1000; batchSize *= 10 {
b.Run(strconv.Itoa(batchSize), func(b *testing.B) {
scores := make([]cache.Scored, batchSize*2)
Expand All @@ -809,7 +810,7 @@ func BenchmarkGetRecommendCache(b *testing.B) {
}
lo.Reverse(scores)
lo.Reverse(expects)
err := s.CacheClient.SetSorted(cache.PopularItems, scores)
err := s.CacheClient.SetSorted(ctx, cache.PopularItems, scores)
require.NoError(b, err)
s.Config.Recommend.CacheSize = len(scores)

Expand Down Expand Up @@ -838,6 +839,7 @@ func BenchmarkRecommendFromOfflineCache(b *testing.B) {
s := newBenchServer(b)
defer s.Close(b)

ctx := context.Background()
for batchSize := 10; batchSize <= 1000; batchSize *= 10 {
b.Run(strconv.Itoa(batchSize), func(b *testing.B) {
scores := make([]cache.Scored, batchSize*2)
Expand All @@ -848,13 +850,13 @@ func BenchmarkRecommendFromOfflineCache(b *testing.B) {
if i%2 == 0 {
expects[i/2] = scores[i].Id
} else {
err := s.CacheClient.AddSorted(cache.Sorted(cache.Key(cache.IgnoreItems, "init_user_1"), []cache.Scored{{scores[i].Id, 0}}))
err := s.CacheClient.AddSorted(ctx, cache.Sorted(cache.Key(cache.IgnoreItems, "init_user_1"), []cache.Scored{{scores[i].Id, 0}}))
require.NoError(b, err)
}
}
lo.Reverse(scores)
lo.Reverse(expects)
err := s.CacheClient.SetSorted(cache.Key(cache.OfflineRecommend, "init_user_1"), scores)
err := s.CacheClient.SetSorted(ctx, cache.Key(cache.OfflineRecommend, "init_user_1"), scores)
require.NoError(b, err)
s.Config.Recommend.CacheSize = len(scores)

Expand Down Expand Up @@ -906,7 +908,7 @@ func BenchmarkRecommendFromLatest(b *testing.B) {
}
lo.Reverse(scores)
lo.Reverse(expects)
err := s.CacheClient.SetSorted(cache.LatestItems, scores)
err := s.CacheClient.SetSorted(ctx, cache.LatestItems, scores)
require.NoError(b, err)
s.Config.Recommend.CacheSize = len(scores)

Expand Down Expand Up @@ -958,7 +960,7 @@ func BenchmarkRecommendFromItemBased(b *testing.B) {

// insert user neighbors
for i := 0; i < s.Config.Recommend.Online.NumFeedbackFallbackItemBased; i++ {
err := s.CacheClient.SetSorted(cache.Key(cache.ItemNeighbors, fmt.Sprintf("init_item_%d", i)), scores)
err := s.CacheClient.SetSorted(ctx, cache.Key(cache.ItemNeighbors, fmt.Sprintf("init_item_%d", i)), scores)
require.NoError(b, err)
}

Expand Down

0 comments on commit 3c80d03

Please sign in to comment.