mirror of https://bitbucket.org/ausocean/av.git
revid: newMultiSender panics if active function is not provided
This commit is contained in:
parent
5b19c955f2
commit
2e49de5fa0
|
@ -216,7 +216,7 @@ func (r *Revid) reset(config Config) error {
|
|||
// encoder to revid's encoder slice, and give this encoder the mtsSenders
|
||||
// as a destination.
|
||||
if len(mtsSenders) != 0 {
|
||||
ms, _ := newMultiSender(mtsSenders, r.IsRunning)
|
||||
ms := newMultiSender(mtsSenders, r.IsRunning)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ func (r *Revid) reset(config Config) error {
|
|||
// encoder to revid's encoder slice, and give this encoder the flvSenders
|
||||
// as a destination.
|
||||
if len(flvSenders) != 0 {
|
||||
ms, _ := newMultiSender(flvSenders, r.IsRunning)
|
||||
ms := newMultiSender(flvSenders, r.IsRunning)
|
||||
e, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -63,15 +63,15 @@ type multiSender struct {
|
|||
// newMultiSender returns a pointer to a new multiSender. active is a function
|
||||
// to indicate the state of the multiSenders owner i.e. whether it is running
|
||||
// or not.
|
||||
func newMultiSender(senders []loadSender, active func() bool) (*multiSender, error) {
|
||||
func newMultiSender(senders []loadSender, active func() bool) *multiSender {
|
||||
if active == nil {
|
||||
return nil, errors.New("multi sender requires that active func is provided")
|
||||
panic("multi sender requires that active func is provided")
|
||||
}
|
||||
s := &multiSender{
|
||||
senders: senders,
|
||||
active: active,
|
||||
}
|
||||
return s, nil
|
||||
return s
|
||||
}
|
||||
|
||||
// Write implements io.Writer. The written slice will be sent to each loadSender
|
||||
|
|
|
@ -256,22 +256,6 @@ func TestMtsSenderDiscontinuity(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestNewMultiSender checks that newMultiSender performs as expected when an
|
||||
// active function is not provided, and when an active function is provided.
|
||||
func TestNewMultiSender(t *testing.T) {
|
||||
// First test without giving an 'active' function.
|
||||
_, err := newMultiSender(nil, nil)
|
||||
if err == nil {
|
||||
t.Fatal("did not get expected error")
|
||||
}
|
||||
|
||||
// Now test with providing an active function.
|
||||
_, err = newMultiSender(nil, func() bool { return true })
|
||||
if err != nil {
|
||||
t.Fatalf("unespected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// dummyLoadSender is a loadSender implementation that allows us to simulate
|
||||
// the behaviour of a loadSender and check that it performas as expected.
|
||||
type dummyLoadSender struct {
|
||||
|
@ -337,10 +321,7 @@ func TestMultiSenderWrite(t *testing.T) {
|
|||
newDummyLoadSender(false, false),
|
||||
newDummyLoadSender(false, false),
|
||||
}
|
||||
ms, err := newMultiSender(senders, func() bool { return true })
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
ms := newMultiSender(senders, func() bool { return true })
|
||||
|
||||
// Perform some multiSender writes.
|
||||
const noOfWrites = 5
|
||||
|
@ -376,10 +357,7 @@ func TestMultiSenderNotActiveNoRetry(t *testing.T) {
|
|||
return active
|
||||
}
|
||||
|
||||
ms, err := newMultiSender(senders, activeFunc)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
ms := newMultiSender(senders, activeFunc)
|
||||
|
||||
// We will perform two writes. We expect the second write not to be complete,
|
||||
// i.e. the senders should not send anything on this write.
|
||||
|
@ -418,10 +396,7 @@ func TestMultiSenderNotActiveRetry(t *testing.T) {
|
|||
return active
|
||||
}
|
||||
|
||||
ms, err := newMultiSender(senders, activeFunc)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
ms := newMultiSender(senders, activeFunc)
|
||||
|
||||
// We run this in background so that we can change running state during the
|
||||
// the write. We then expect done to be true after some period of time.
|
||||
|
@ -453,10 +428,7 @@ func TestMultiSenderFailNoRetry(t *testing.T) {
|
|||
newDummyLoadSender(false, false),
|
||||
}
|
||||
|
||||
ms, err := newMultiSender(senders, func() bool { return true })
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
ms := newMultiSender(senders, func() bool { return true })
|
||||
|
||||
// We will perform two writes. We expect the second write not to be complete,
|
||||
// i.e. the senders should not send anything on this write.
|
||||
|
@ -507,10 +479,7 @@ func TestMultiSenderFailNoRetry(t *testing.T) {
|
|||
func TestMultiSenderFailRetry(t *testing.T) {
|
||||
// NB: This is only being tested with one sender - this is AusOcean's use case.
|
||||
senders := []loadSender{newDummyLoadSender(false, true)}
|
||||
ms, err := newMultiSender(senders, func() bool { return true })
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
ms := newMultiSender(senders, func() bool { return true })
|
||||
|
||||
// Perform one write with successful send.
|
||||
ms.Write([]byte{0x00})
|
||||
|
|
Loading…
Reference in New Issue