Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
kc: fix data race in AsyncApply test
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Oct 8, 2012
1 parent 596d156 commit 604cceb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kc/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,21 @@ func TestShouldBeAbleToAsynchronouslyApplyAFunctionToAllRecordsInTheDatabase(t *
for k, v := range urls {
db.Set(k, v)
}
applied := map[string]string{}
applied := make(map[string]string)
type pair struct {
key, value string
}
pairs := make(chan pair)
go func() {
for pair := range pairs {
applied[pair.key] = pair.value
}
}()
r := db.AsyncApply(func(key string, value interface{}, args ...interface{}) {
applied[key] = value.(string)
pairs <- pair{key, value.(string)}
})
r.Wait()
close(pairs)
if !areStringMapsEqual(urls, applied) {
t.Errorf("Should apply the function")
}
Expand Down

0 comments on commit 604cceb

Please sign in to comment.