Skip to content

Commit

Permalink
Merge pull request #2857 from ipfs/feature/test-race-blockstore
Browse files Browse the repository at this point in the history
Remove failing blockstore with context test
  • Loading branch information
whyrusleeping authored Jun 16, 2016
2 parents a4801ed + 5a08e9e commit 868a1e3
Showing 1 changed file with 35 additions and 90 deletions.
125 changes: 35 additions & 90 deletions blocks/blockstore/blockstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,97 +117,42 @@ func TestAllKeysRespectsContext(t *testing.T) {
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{})
resultChan := make(chan dsq.Result)
d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
results = dsq.ResultsWithChan(q, resultChan)
resultsmu <- struct{}{}
return results, nil
})

go getKeys(context.Background())

// 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:
}

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
{
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)
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
})

go getKeys(context.Background())

// 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:
}

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)
}

}
Expand Down

0 comments on commit 868a1e3

Please sign in to comment.