Skip to content

Commit

Permalink
Wait goroutines to finish when testing race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Sanches committed Mar 1, 2018
1 parent de4d2fa commit d8d572f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.4.4] - 2018-03-01
### Fixed
- `TestRace` now waits all goroutines to finish.

## [0.4.3] - 2018-03-01
### Fixed
- Bounds out of range error when trying to get a node with placeholder.
Expand Down Expand Up @@ -108,6 +112,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- This package's source code, including examples and tests.
- Go dep files.

[0.4.4]: https://github.com/gbrlsnchs/radix/compare/v0.4.3...v0.4.4
[0.4.3]: https://github.com/gbrlsnchs/radix/compare/v0.4.2...v0.4.3
[0.4.2]: https://github.com/gbrlsnchs/radix/compare/v0.4.1...v0.4.2
[0.4.1]: https://github.com/gbrlsnchs/radix/compare/v0.4.0...v0.4.1
Expand Down
12 changes: 8 additions & 4 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package radix_test

import (
"strconv"
"sync"
"testing"
"time"

. "github.com/gbrlsnchs/radix"

Expand Down Expand Up @@ -350,11 +350,14 @@ func TestRace(t *testing.T) {
}
tree := New("TestRace")
tree.Safe = true
var wg sync.WaitGroup

wg.Add(len(list) * 2)

for i, n := range list {
go func(i int, n string) {
tree.Add(n, i)
time.Sleep(time.Second * 3)
wg.Done()
}(i, n)
}

Expand All @@ -366,8 +369,9 @@ func TestRace(t *testing.T) {

tree.Del(n)
tree.Add(n, v)

time.Sleep(time.Second * 3)
wg.Done()
}(n)
}

wg.Wait()
}

0 comments on commit d8d572f

Please sign in to comment.