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
|
// encoder to revid's encoder slice, and give this encoder the mtsSenders
|
||||||
// as a destination.
|
// as a destination.
|
||||||
if len(mtsSenders) != 0 {
|
if len(mtsSenders) != 0 {
|
||||||
ms, _ := newMultiSender(mtsSenders, r.IsRunning)
|
ms := newMultiSender(mtsSenders, r.IsRunning)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// encoder to revid's encoder slice, and give this encoder the flvSenders
|
||||||
// as a destination.
|
// as a destination.
|
||||||
if len(flvSenders) != 0 {
|
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))
|
e, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -63,15 +63,15 @@ type multiSender struct {
|
||||||
// newMultiSender returns a pointer to a new multiSender. active is a function
|
// 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
|
// to indicate the state of the multiSenders owner i.e. whether it is running
|
||||||
// or not.
|
// or not.
|
||||||
func newMultiSender(senders []loadSender, active func() bool) (*multiSender, error) {
|
func newMultiSender(senders []loadSender, active func() bool) *multiSender {
|
||||||
if active == nil {
|
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{
|
s := &multiSender{
|
||||||
senders: senders,
|
senders: senders,
|
||||||
active: active,
|
active: active,
|
||||||
}
|
}
|
||||||
return s, nil
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write implements io.Writer. The written slice will be sent to each loadSender
|
// 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
|
// dummyLoadSender is a loadSender implementation that allows us to simulate
|
||||||
// the behaviour of a loadSender and check that it performas as expected.
|
// the behaviour of a loadSender and check that it performas as expected.
|
||||||
type dummyLoadSender struct {
|
type dummyLoadSender struct {
|
||||||
|
@ -337,10 +321,7 @@ func TestMultiSenderWrite(t *testing.T) {
|
||||||
newDummyLoadSender(false, false),
|
newDummyLoadSender(false, false),
|
||||||
newDummyLoadSender(false, false),
|
newDummyLoadSender(false, false),
|
||||||
}
|
}
|
||||||
ms, err := newMultiSender(senders, func() bool { return true })
|
ms := newMultiSender(senders, func() bool { return true })
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform some multiSender writes.
|
// Perform some multiSender writes.
|
||||||
const noOfWrites = 5
|
const noOfWrites = 5
|
||||||
|
@ -376,10 +357,7 @@ func TestMultiSenderNotActiveNoRetry(t *testing.T) {
|
||||||
return active
|
return active
|
||||||
}
|
}
|
||||||
|
|
||||||
ms, err := newMultiSender(senders, activeFunc)
|
ms := newMultiSender(senders, activeFunc)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We will perform two writes. We expect the second write not to be complete,
|
// 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.
|
// i.e. the senders should not send anything on this write.
|
||||||
|
@ -418,10 +396,7 @@ func TestMultiSenderNotActiveRetry(t *testing.T) {
|
||||||
return active
|
return active
|
||||||
}
|
}
|
||||||
|
|
||||||
ms, err := newMultiSender(senders, activeFunc)
|
ms := newMultiSender(senders, activeFunc)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We run this in background so that we can change running state during the
|
// 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.
|
// 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),
|
newDummyLoadSender(false, false),
|
||||||
}
|
}
|
||||||
|
|
||||||
ms, err := newMultiSender(senders, func() bool { return true })
|
ms := newMultiSender(senders, func() bool { return true })
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We will perform two writes. We expect the second write not to be complete,
|
// 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.
|
// 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) {
|
func TestMultiSenderFailRetry(t *testing.T) {
|
||||||
// NB: This is only being tested with one sender - this is AusOcean's use case.
|
// NB: This is only being tested with one sender - this is AusOcean's use case.
|
||||||
senders := []loadSender{newDummyLoadSender(false, true)}
|
senders := []loadSender{newDummyLoadSender(false, true)}
|
||||||
ms, err := newMultiSender(senders, func() bool { return true })
|
ms := newMultiSender(senders, func() bool { return true })
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform one write with successful send.
|
// Perform one write with successful send.
|
||||||
ms.Write([]byte{0x00})
|
ms.Write([]byte{0x00})
|
||||||
|
|
Loading…
Reference in New Issue