Skip to content

fix(ci): fix flaky test #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 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,17 +1043,20 @@ 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)

g.Expect(len(server.agents)).To(Equal(test.expectedAgentsCount))
for len(server.agents) != test.expectedAgentsCount {
time.Sleep(100 * time.Millisecond)
}

for idx, s := range streams {
go func(idx int, s *grpc.ClientConn) {
Expand All @@ -1062,9 +1066,9 @@ func TestSubscribe(t *testing.T) {
}(idx, s)
}

time.Sleep(10 * time.Second)

g.Expect(len(server.agents)).To(Equal(test.expectedAgentsCountAfterClose))
for len(server.agents) != test.expectedAgentsCountAfterClose {
time.Sleep(100 * time.Millisecond)
}

server.StopAgentStreams()
})
Expand Down
18 changes: 10 additions & 8 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 @@ -638,8 +639,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,17 +728,20 @@ 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)

g.Expect(len(s.streams)).To(Equal(test.expectedAgentsCount))
for len(s.streams) != test.expectedAgentsCount {
time.Sleep(100 * time.Millisecond)
}

for idx, s := range streams {
go func(idx int, s *grpc.ClientConn) {
Expand All @@ -749,9 +751,9 @@ func TestPipelineSubscribe(t *testing.T) {
}(idx, s)
}

time.Sleep(10 * time.Second)

g.Expect(len(s.streams)).To(Equal(test.expectedAgentsCountAfterClose))
for len(s.streams) != test.expectedAgentsCountAfterClose {
time.Sleep(100 * time.Millisecond)
}

s.StopSendPipelineEvents()
})
Expand Down
Loading