提交 0b9bef1e 作者: Juan Batiz-Benet

blockstore: fixed data race

上级 5c4be751
...@@ -118,9 +118,11 @@ func TestAllKeysRespectsContext(t *testing.T) { ...@@ -118,9 +118,11 @@ func TestAllKeysRespectsContext(t *testing.T) {
// Once without context, to make sure it all works // Once without context, to make sure it all works
{ {
var results dsq.Results var results dsq.Results
var resultsmu = make(chan struct{})
resultChan := make(chan dsq.Result) resultChan := make(chan dsq.Result)
d.SetFunc(func(q dsq.Query) (dsq.Results, error) { d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
results = dsq.ResultsWithChan(q, resultChan) results = dsq.ResultsWithChan(q, resultChan)
resultsmu <- struct{}{}
return results, nil return results, nil
}) })
...@@ -128,6 +130,7 @@ func TestAllKeysRespectsContext(t *testing.T) { ...@@ -128,6 +130,7 @@ func TestAllKeysRespectsContext(t *testing.T) {
// make sure it's waiting. // make sure it's waiting.
<-started <-started
<-resultsmu
select { select {
case <-done: case <-done:
t.Fatal("sync is wrong") t.Fatal("sync is wrong")
...@@ -156,9 +159,11 @@ func TestAllKeysRespectsContext(t *testing.T) { ...@@ -156,9 +159,11 @@ func TestAllKeysRespectsContext(t *testing.T) {
// Once with // Once with
{ {
var results dsq.Results var results dsq.Results
var resultsmu = make(chan struct{})
resultChan := make(chan dsq.Result) resultChan := make(chan dsq.Result)
d.SetFunc(func(q dsq.Query) (dsq.Results, error) { d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
results = dsq.ResultsWithChan(q, resultChan) results = dsq.ResultsWithChan(q, resultChan)
resultsmu <- struct{}{}
return results, nil return results, nil
}) })
...@@ -167,6 +172,7 @@ func TestAllKeysRespectsContext(t *testing.T) { ...@@ -167,6 +172,7 @@ func TestAllKeysRespectsContext(t *testing.T) {
// make sure it's waiting. // make sure it's waiting.
<-started <-started
<-resultsmu
select { select {
case <-done: case <-done:
t.Fatal("sync is wrong") t.Fatal("sync is wrong")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论