mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
72 lines
1015 B
Go
72 lines
1015 B
Go
package asyncprocessor
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCloseBeforeStart(_ *testing.T) {
|
|
p := &Processor{
|
|
BufferSize: 8,
|
|
}
|
|
p.Initialize()
|
|
defer p.Close()
|
|
}
|
|
|
|
func TestCloseAfterError(t *testing.T) {
|
|
done := make(chan struct{})
|
|
|
|
p := &Processor{
|
|
BufferSize: 8,
|
|
OnError: func(_ context.Context, err error) {
|
|
require.EqualError(t, err, "ok")
|
|
close(done)
|
|
},
|
|
}
|
|
p.Initialize()
|
|
defer p.Close()
|
|
|
|
p.Push(func() error {
|
|
return fmt.Errorf("ok")
|
|
})
|
|
|
|
p.Start()
|
|
|
|
<-done
|
|
}
|
|
|
|
func TestCloseBeforeError(_ *testing.T) {
|
|
p := &Processor{
|
|
BufferSize: 8,
|
|
OnError: func(_ context.Context, _ error) {},
|
|
}
|
|
p.Initialize()
|
|
defer p.Close()
|
|
|
|
p.Push(func() error {
|
|
return nil
|
|
})
|
|
|
|
p.Start()
|
|
}
|
|
|
|
func TestCloseDuringError(_ *testing.T) {
|
|
p := &Processor{
|
|
BufferSize: 8,
|
|
OnError: func(ctx context.Context, _ error) {
|
|
<-ctx.Done()
|
|
},
|
|
}
|
|
p.Initialize()
|
|
defer p.Close()
|
|
|
|
p.Push(func() error {
|
|
return fmt.Errorf("ok")
|
|
})
|
|
|
|
p.Start()
|
|
}
|