1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-02 06:22:31 +03:00

add additional expect to check output

This commit is contained in:
Nedyalko Dyakov
2025-10-27 08:15:41 +02:00
parent da5fe33cdf
commit 471a828ab1
2 changed files with 22 additions and 9 deletions

View File

@@ -127,9 +127,11 @@ func benchmarkHSETOperationsConcurrent(b *testing.B, rdb *redis.Client, ctx cont
// Perform the specified number of HSET operations // Perform the specified number of HSET operations
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(operations)
timesCh := make(chan time.Duration, operations) timesCh := make(chan time.Duration, operations)
errCh := make(chan error, operations)
for j := 0; j < operations; j++ { for j := 0; j < operations; j++ {
wg.Add(1)
go func(j int) { go func(j int) {
defer wg.Done() defer wg.Done()
field := fmt.Sprintf("field_%d", j) field := fmt.Sprintf("field_%d", j)
@@ -137,15 +139,24 @@ func benchmarkHSETOperationsConcurrent(b *testing.B, rdb *redis.Client, ctx cont
err := rdb.HSet(ctx, hashKey, field, value).Err() err := rdb.HSet(ctx, hashKey, field, value).Err()
if err != nil { if err != nil {
b.Fatalf("HSET operation failed: %v", err) errCh <- err
return
} }
timesCh <- time.Since(startTime) timesCh <- time.Since(startTime)
}(j) }(j)
wg.Wait() }
close(timesCh)
for d := range timesCh { wg.Wait()
totalTimes = append(totalTimes, d) close(timesCh)
} close(errCh)
// Check for errors
for err := range errCh {
b.Errorf("HSET operation failed: %v", err)
}
for d := range timesCh {
totalTimes = append(totalTimes, d)
} }
} }
@@ -206,7 +217,7 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
rdb := redis.NewClient(&redis.Options{ rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379", Addr: "localhost:6379",
DB: 0, DB: 0,
PoolSize: 1000, PoolSize: 100,
}) })
defer rdb.Close() defer rdb.Close()
@@ -220,7 +231,8 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
rdb.FlushDB(ctx) rdb.FlushDB(ctx)
}() }()
scales := []int{1, 10, 100, 1000, 10000, 100000} // Reduced scales to avoid overwhelming the system with too many concurrent goroutines
scales := []int{1, 10, 100, 1000}
for _, scale := range scales { for _, scale := range scales {
b.Run(fmt.Sprintf("HSET_%d_operations_concurrent", scale), func(b *testing.B) { b.Run(fmt.Sprintf("HSET_%d_operations_concurrent", scale), func(b *testing.B) {

View File

@@ -323,6 +323,7 @@ var _ = Describe("Client", func() {
cn, err = client.Pool().Get(context.Background()) cn, err = client.Pool().Get(context.Background())
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(cn).NotTo(BeNil()) Expect(cn).NotTo(BeNil())
Expect(cn.UsedAt().UnixNano()).To(BeNumerically(">", createdAt.UnixNano()))
Expect(cn.UsedAt().After(createdAt)).To(BeTrue()) Expect(cn.UsedAt().After(createdAt)).To(BeTrue())
}) })