提交 868a1e36 作者: Jeromy Johnson 提交者: GitHub

Merge pull request #2857 from ipfs/feature/test-race-blockstore

Remove failing blockstore with context test
...@@ -117,97 +117,42 @@ func TestAllKeysRespectsContext(t *testing.T) { ...@@ -117,97 +117,42 @@ func TestAllKeysRespectsContext(t *testing.T) {
errors <- nil // a nil one to signal break errors <- nil // a nil one to signal break
} }
// Once without context, to make sure it all works var results dsq.Results
{ var resultsmu = make(chan struct{})
var results dsq.Results resultChan := make(chan dsq.Result)
var resultsmu = make(chan struct{}) d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
resultChan := make(chan dsq.Result) results = dsq.ResultsWithChan(q, resultChan)
d.SetFunc(func(q dsq.Query) (dsq.Results, error) { resultsmu <- struct{}{}
results = dsq.ResultsWithChan(q, resultChan) return results, nil
resultsmu <- struct{}{} })
return results, nil
}) go getKeys(context.Background())
go getKeys(context.Background()) // make sure it's waiting.
<-started
// make sure it's waiting. <-resultsmu
<-started select {
<-resultsmu case <-done:
select { t.Fatal("sync is wrong")
case <-done: case <-results.Process().Closing():
t.Fatal("sync is wrong") t.Fatal("should not be closing")
case <-results.Process().Closing(): case <-results.Process().Closed():
t.Fatal("should not be closing") t.Fatal("should not be closed")
case <-results.Process().Closed(): default:
t.Fatal("should not be closed") }
default:
} e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()}
resultChan <- dsq.Result{Entry: e} // let it go.
e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()} close(resultChan)
resultChan <- dsq.Result{Entry: e} // let it go. <-done // should be done now.
close(resultChan) <-results.Process().Closed() // should be closed now
<-done // should be done now.
<-results.Process().Closed() // should be closed now // print any errors
for err := range errors {
// print any errors if err == nil {
for err := range errors { break
if err == nil {
break
}
t.Error(err)
}
}
// Once with
{
var results dsq.Results
var resultsmu = make(chan struct{})
resultChan := make(chan dsq.Result)
d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
results = dsq.ResultsWithChan(q, resultChan)
resultsmu <- struct{}{}
return results, nil
})
ctx, cancel := context.WithCancel(context.Background())
go getKeys(ctx)
// make sure it's waiting.
<-started
<-resultsmu
select {
case <-done:
t.Fatal("sync is wrong")
case <-results.Process().Closing():
t.Fatal("should not be closing")
case <-results.Process().Closed():
t.Fatal("should not be closed")
default:
}
cancel() // let it go.
select {
case <-done:
t.Fatal("sync is wrong")
case <-results.Process().Closed():
t.Fatal("should not be closed") // should not be closed yet.
case <-results.Process().Closing():
// should be closing now!
t.Log("closing correctly at this point.")
}
close(resultChan)
<-done // should be done now.
<-results.Process().Closed() // should be closed now
// print any errors
for err := range errors {
if err == nil {
break
}
t.Error(err)
} }
t.Error(err)
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论