Skip to content

Commit

Permalink
fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
sakoush committed Nov 1, 2024
1 parent 520ba61 commit b7a70b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
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

0 comments on commit b7a70b6

Please sign in to comment.