Skip to content

Commit

Permalink
fix(ci): fix flaky test (#6022)
Browse files Browse the repository at this point in the history
* fix flaky test

* cap execution of test in case of failures
  • Loading branch information
sakoush authored Nov 1, 2024
1 parent 520ba61 commit cb5cfbd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
19 changes: 15 additions & 4 deletions scheduler/pkg/agent/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package agent
import (
"context"
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -1042,16 +1043,23 @@ func TestSubscribe(t *testing.T) {
}
time.Sleep(100 * time.Millisecond)

mu := sync.Mutex{}
streams := make([]*grpc.ClientConn, 0)
for _, a := range test.agents {
go func(id uint32) {
conn := getStream(id, context.Background(), port)
mu.Lock()
streams = append(streams, conn)
mu.Unlock()
}(a.id)
}

time.Sleep(500 * time.Millisecond)

maxCount := 10
count := 0
for len(server.agents) != test.expectedAgentsCount && count < maxCount {
time.Sleep(100 * time.Millisecond)
count++
}
g.Expect(len(server.agents)).To(Equal(test.expectedAgentsCount))

for idx, s := range streams {
Expand All @@ -1062,8 +1070,11 @@ func TestSubscribe(t *testing.T) {
}(idx, s)
}

time.Sleep(10 * time.Second)

count = 0
for len(server.agents) != test.expectedAgentsCountAfterClose && count < maxCount {
time.Sleep(100 * time.Millisecond)
count++
}
g.Expect(len(server.agents)).To(Equal(test.expectedAgentsCountAfterClose))

server.StopAgentStreams()
Expand Down
20 changes: 15 additions & 5 deletions scheduler/pkg/kafka/dataflow/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"context"
"fmt"
"os"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -639,7 +640,6 @@ func TestPipelineRebalance(t *testing.T) {

func TestPipelineSubscribe(t *testing.T) {
g := NewGomegaWithT(t)

type ag struct {
id uint32
doClose bool
Expand Down Expand Up @@ -729,16 +729,23 @@ func TestPipelineSubscribe(t *testing.T) {

time.Sleep(100 * time.Millisecond)

mu := sync.Mutex{}
streams := make([]*grpc.ClientConn, 0)
for _, a := range test.agents {
go func(id uint32) {
conn := getStream(id, context.Background(), port)
mu.Lock()
streams = append(streams, conn)
mu.Unlock()
}(a.id)
}

time.Sleep(700 * time.Millisecond)

maxCount := 10
count := 0
for len(s.streams) != test.expectedAgentsCount && count < maxCount {
time.Sleep(100 * time.Millisecond)
count++
}
g.Expect(len(s.streams)).To(Equal(test.expectedAgentsCount))

for idx, s := range streams {
Expand All @@ -749,8 +756,11 @@ func TestPipelineSubscribe(t *testing.T) {
}(idx, s)
}

time.Sleep(10 * time.Second)

count = 0
for len(s.streams) != test.expectedAgentsCountAfterClose && count < maxCount {
time.Sleep(100 * time.Millisecond)
count++
}
g.Expect(len(s.streams)).To(Equal(test.expectedAgentsCountAfterClose))

s.StopSendPipelineEvents()
Expand Down

0 comments on commit cb5cfbd

Please sign in to comment.