mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
ensure view closes fragment on broadcast error
This commit is contained in:
parent
1706e9b4e1
commit
dbe4197871
2 changed files with 46 additions and 0 deletions
1
view.go
1
view.go
|
|
@ -228,6 +228,7 @@ func (v *view) createFragmentIfNotExists(shard uint64) (*fragment, error) {
|
|||
Field: v.field,
|
||||
Shard: shard,
|
||||
}); err != nil {
|
||||
frag.close()
|
||||
return nil, errors.Wrap(err, "sending createshard message")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ package pilosa
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// mustOpenView returns a new instance of View with a temporary path.
|
||||
|
|
@ -73,3 +76,45 @@ func TestView_DeleteFragment(t *testing.T) {
|
|||
t.Fatal("failed to create new fragment")
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure view closes fragment after failed shard broadcast.
|
||||
func TestView_CreateFragmentError(t *testing.T) {
|
||||
v := mustOpenView("i", "f", "v")
|
||||
defer v.close()
|
||||
|
||||
// Use a broadcaster which intentionally fails.
|
||||
v.broadcaster = errorBroadcaster{}
|
||||
|
||||
shard := uint64(0)
|
||||
|
||||
// Create fragment (with error on broadcast).
|
||||
fragment, err := v.CreateFragmentIfNotExists(shard)
|
||||
if !strings.Contains(err.Error(), "intentional error") {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if fragment == nil {
|
||||
t.Fatal("expected fragment")
|
||||
} else {
|
||||
t.Fatal("expected intentional error")
|
||||
}
|
||||
}
|
||||
|
||||
// Set the broadcaster back to no-op.
|
||||
v.broadcaster = nopBroadcaster{}
|
||||
|
||||
// Try to create the fragment again.
|
||||
_, err = v.CreateFragmentIfNotExists(shard)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// errorBroadcaster is a broadcaster which always returns an error.
|
||||
type errorBroadcaster struct {
|
||||
nopBroadcaster
|
||||
}
|
||||
|
||||
// SendSync is an implementation of Broadcaster SendSync which always returns an error.
|
||||
func (errorBroadcaster) SendSync(Message) error {
|
||||
return errors.New("intentional error")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue