Skip to content

Commit 471a828

Browse files
committed
add additional expect to check output
1 parent da5fe33 commit 471a828

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

hset_benchmark_test.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,36 @@ func benchmarkHSETOperationsConcurrent(b *testing.B, rdb *redis.Client, ctx cont
127127
// Perform the specified number of HSET operations
128128

129129
wg := sync.WaitGroup{}
130-
wg.Add(operations)
131130
timesCh := make(chan time.Duration, operations)
131+
errCh := make(chan error, operations)
132+
132133
for j := 0; j < operations; j++ {
134+
wg.Add(1)
133135
go func(j int) {
134136
defer wg.Done()
135137
field := fmt.Sprintf("field_%d", j)
136138
value := fmt.Sprintf("value_%d", j)
137139

138140
err := rdb.HSet(ctx, hashKey, field, value).Err()
139141
if err != nil {
140-
b.Fatalf("HSET operation failed: %v", err)
142+
errCh <- err
143+
return
141144
}
142145
timesCh <- time.Since(startTime)
143146
}(j)
144-
wg.Wait()
145-
close(timesCh)
146-
for d := range timesCh {
147-
totalTimes = append(totalTimes, d)
148-
}
147+
}
148+
149+
wg.Wait()
150+
close(timesCh)
151+
close(errCh)
152+
153+
// Check for errors
154+
for err := range errCh {
155+
b.Errorf("HSET operation failed: %v", err)
156+
}
157+
158+
for d := range timesCh {
159+
totalTimes = append(totalTimes, d)
149160
}
150161
}
151162

@@ -206,7 +217,7 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
206217
rdb := redis.NewClient(&redis.Options{
207218
Addr: "localhost:6379",
208219
DB: 0,
209-
PoolSize: 1000,
220+
PoolSize: 100,
210221
})
211222
defer rdb.Close()
212223

@@ -220,7 +231,8 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
220231
rdb.FlushDB(ctx)
221232
}()
222233

223-
scales := []int{1, 10, 100, 1000, 10000, 100000}
234+
// Reduced scales to avoid overwhelming the system with too many concurrent goroutines
235+
scales := []int{1, 10, 100, 1000}
224236

225237
for _, scale := range scales {
226238
b.Run(fmt.Sprintf("HSET_%d_operations_concurrent", scale), func(b *testing.B) {

redis_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ var _ = Describe("Client", func() {
323323
cn, err = client.Pool().Get(context.Background())
324324
Expect(err).NotTo(HaveOccurred())
325325
Expect(cn).NotTo(BeNil())
326+
Expect(cn.UsedAt().UnixNano()).To(BeNumerically(">", createdAt.UnixNano()))
326327
Expect(cn.UsedAt().After(createdAt)).To(BeTrue())
327328
})
328329

0 commit comments

Comments
 (0)