From f3be7efa68e7c9959e8715bcf5328f11ecd0b94e Mon Sep 17 00:00:00 2001 From: Lucas Merquior Date: Sat, 15 Jun 2024 12:10:19 -0300 Subject: [PATCH] Fix range variables Range variables were being reused in some loops in the tests --- driver/test/db_main.go | 6 ++++-- sdb/db_bench_test.go | 4 ++-- sdb/db_main_test.go | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/driver/test/db_main.go b/driver/test/db_main.go index 4ffa4c2..4615990 100644 --- a/driver/test/db_main.go +++ b/driver/test/db_main.go @@ -278,7 +278,8 @@ func (T *DBTests) TestPut(t *testing.T) { // Act var wg sync.WaitGroup - for key, value := range seed { + for k, v := range seed { + key, value := k, v // Capture wg.Add(1) go func() { defer wg.Done() @@ -364,7 +365,8 @@ func (T *DBTests) TestDelete(t *testing.T) { // Act var wg sync.WaitGroup - for key, _ := range seed { + for k, _ := range seed { + key := k // Capture wg.Add(1) go func() { defer wg.Done() diff --git a/sdb/db_bench_test.go b/sdb/db_bench_test.go index e4ca4ce..5578659 100644 --- a/sdb/db_bench_test.go +++ b/sdb/db_bench_test.go @@ -98,7 +98,7 @@ func BenchmarkDB_Put_Concurrent(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { ch <- 1 - go func() { + go func(i int) { wg.Add(1) defer wg.Done() defer func() { <-ch }() @@ -106,7 +106,7 @@ func BenchmarkDB_Put_Concurrent(b *testing.B) { if err != nil { b.Fatalf("put: %s", err) } - }() + }(i) inserted++ } wg.Wait() diff --git a/sdb/db_main_test.go b/sdb/db_main_test.go index c344ffb..22060da 100644 --- a/sdb/db_main_test.go +++ b/sdb/db_main_test.go @@ -278,7 +278,8 @@ func (T *DBTests) TestPut(t *testing.T) { // Act var wg sync.WaitGroup - for key, value := range seed { + for k, v := range seed { + key, value := k, v // Capture wg.Add(1) go func() { defer wg.Done() @@ -364,7 +365,8 @@ func (T *DBTests) TestDelete(t *testing.T) { // Act var wg sync.WaitGroup - for key, _ := range seed { + for k, _ := range seed { + key := k // Capture wg.Add(1) go func() { defer wg.Done()