Skip to content

Commit

Permalink
Merge pull request #57 from calyptia/cosmo0920-organize-unit-tests
Browse files Browse the repository at this point in the history
cshared: test: Stabilize unstable tests
  • Loading branch information
niedbalski authored Oct 26, 2023
2 parents 8dbb935 + 96c0484 commit c26f5cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 6 additions & 0 deletions cshared.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ func FLBPluginInit(ptr unsafe.Pointer) int {
func flbPluginReset() {
theInputLock.Lock()
defer theInputLock.Unlock()
defer func() {
if ret := recover(); ret != nil {
fmt.Fprintf(os.Stderr, "Channel is already closed")
return
}
}()

once = sync.Once{}
close(theChannel)
Expand Down
13 changes: 4 additions & 9 deletions cshared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ func init() {
registerWG.Done()
}

func TestInputCallbackCtrlC(t *testing.T) {
func TestMain(m *testing.M) {
defer flbPluginReset()
m.Run()
}

func TestInputCallbackCtrlC(t *testing.T) {
theInputLock.Lock()
theInput = testPluginInputCallbackCtrlC{}
theInputLock.Unlock()
Expand Down Expand Up @@ -83,8 +86,6 @@ func (t testPluginInputCallbackDangle) Collect(ctx context.Context, ch chan<- Me
// Collect multiple times. This is inline with backward-compatible
// behavior.
func TestInputCallbackDangle(t *testing.T) {
defer flbPluginReset()

theInputLock.Lock()
theInput = testPluginInputCallbackDangle{}
theInputLock.Unlock()
Expand Down Expand Up @@ -158,8 +159,6 @@ func (t testPluginInputCallbackInfinite) Collect(ctx context.Context, ch chan<-
// TestInputCallbackInfinite is a test for the main method most plugins
// use where they do not return from the first invocation of collect.
func TestInputCallbackInfinite(t *testing.T) {
defer flbPluginReset()

theInputLock.Lock()
theInput = testPluginInputCallbackInfinite{}
theInputLock.Unlock()
Expand Down Expand Up @@ -246,8 +245,6 @@ func (t testPluginInputCallbackLatency) Collect(ctx context.Context, ch chan<- M
// TestInputCallbackInfiniteLatency is a test of the latency between
// messages.
func TestInputCallbackLatency(t *testing.T) {
defer flbPluginReset()

theInputLock.Lock()
theInput = testPluginInputCallbackLatency{}
theInputLock.Unlock()
Expand Down Expand Up @@ -377,8 +374,6 @@ func (t testInputCallbackInfiniteConcurrent) Collect(ctx context.Context, ch cha
// TestInputCallbackInfiniteConcurrent is meant to make sure we do not
// break anythin with respect to concurrent ingest.
func TestInputCallbackInfiniteConcurrent(t *testing.T) {
defer flbPluginReset()

theInputLock.Lock()
theInput = testInputCallbackInfiniteConcurrent{}
theInputLock.Unlock()
Expand Down

0 comments on commit c26f5cd

Please sign in to comment.