Skip to content

Commit

Permalink
cshared: test: Fix failing cshared tests
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 6, 2023
1 parent 695576e commit e3578f7
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions cshared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ func TestInputCallbackCtrlC(t *testing.T) {

ptr := unsafe.Pointer(nil)

go func() {
go func(test *testing.T) {
// prepare channel for input explicitly.
err := prepareInputCollector()
if err != nil {
test.Fail()
return
}

FLBPluginInputCallback(&ptr, nil)
cdone <- true
}()
}(t)

select {
case <-cdone:
Expand Down Expand Up @@ -86,7 +93,13 @@ func TestInputCallbackDangle(t *testing.T) {
cdone := make(chan bool)
ptr := unsafe.Pointer(nil)

go func() {
// prepare channel for input explicitly.
err := prepareInputCollector()
if err != nil {
t.Fail()
}

go func(test *testing.T) {
t := time.NewTicker(collectInterval)
defer t.Stop()

Expand All @@ -99,7 +112,7 @@ func TestInputCallbackDangle(t *testing.T) {
return
}
}
}()
}(t)

timeout := time.NewTimer(5 * time.Second)

Expand Down Expand Up @@ -156,10 +169,17 @@ func TestInputCallbackInfinite(t *testing.T) {
cshutdown := make(chan bool)
ptr := unsafe.Pointer(nil)

go func() {
go func(test *testing.T) {
t := time.NewTicker(collectInterval)
defer t.Stop()

// prepare channel for input explicitly.
err := prepareInputCollector()
if err != nil {
test.Fail()
return
}

for {
select {
case <-t.C:
Expand All @@ -172,7 +192,7 @@ func TestInputCallbackInfinite(t *testing.T) {
return
}
}
}()
}(t)

timeout := time.NewTimer(10 * time.Second)
defer timeout.Stop()
Expand Down Expand Up @@ -237,10 +257,17 @@ func TestInputCallbackLatency(t *testing.T) {
cstarted := make(chan bool)
cmsg := make(chan []byte)

go func() {
go func(test *testing.T) {
t := time.NewTicker(collectInterval)
defer t.Stop()

// prepare channel for input explicitly.
err := prepareInputCollector()
if err != nil {
test.Fail()
return
}

buf, _ := testFLBPluginInputCallback()
if len(buf) > 0 {
cmsg <- buf
Expand All @@ -259,7 +286,7 @@ func TestInputCallbackLatency(t *testing.T) {
}
}
}
}()
}(t)

<-cstarted
fmt.Println("---- started")
Expand Down Expand Up @@ -363,6 +390,12 @@ func TestInputCallbackInfiniteConcurrent(t *testing.T) {

concurrentWait.Add(64)

// prepare channel for input explicitly.
err := prepareInputCollector()
if err != nil {
t.Fail()
}

go func(cstarted chan bool) {
ticker := time.NewTicker(time.Second * 1)
defer ticker.Stop()
Expand Down

0 comments on commit e3578f7

Please sign in to comment.