1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 16:07:42 +08:00

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

Remove failing blockstore with context test
This commit is contained in:
Jeromy Johnson
2016-06-16 10:44:45 -07:00
committed by GitHub

View File

@ -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. // make sure it's waiting.
<-started <-started
<-resultsmu <-resultsmu
select { select {
case <-done: case <-done:
t.Fatal("sync is wrong") t.Fatal("sync is wrong")
case <-results.Process().Closing(): case <-results.Process().Closing():
t.Fatal("should not be closing") t.Fatal("should not be closing")
case <-results.Process().Closed(): case <-results.Process().Closed():
t.Fatal("should not be closed") t.Fatal("should not be closed")
default: default:
}
e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()}
resultChan <- dsq.Result{Entry: e} // let it go.
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)
}
} }
// Once with e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()}
{ resultChan <- dsq.Result{Entry: e} // let it go.
var results dsq.Results close(resultChan)
var resultsmu = make(chan struct{}) <-done // should be done now.
resultChan := make(chan dsq.Result) <-results.Process().Closed() // should be closed now
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()) // print any errors
go getKeys(ctx) for err := range errors {
if err == nil {
// make sure it's waiting. break
<-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)
} }
} }