Skip to content

Commit

Permalink
Fix range variables
Browse files Browse the repository at this point in the history
Range variables were being reused in some loops in the tests
  • Loading branch information
lucmq committed Jun 15, 2024
1 parent 35ad4b5 commit f3be7ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions driver/test/db_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sdb/db_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ 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 }()
err := db.Put(items[i%N][0], items[i%N][1])
if err != nil {
b.Fatalf("put: %s", err)
}
}()
}(i)
inserted++
}
wg.Wait()
Expand Down
6 changes: 4 additions & 2 deletions sdb/db_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f3be7ef

Please sign in to comment.