Skip to content

Commit 84f48f5

Browse files
committed
fix grpc broker resync bugs
Signed-off-by: Wei Liu <liuweixa@redhat.com>
1 parent a2d4d1b commit 84f48f5

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

test/integration/cloudevents/manifestworkclients_reync_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var _ = ginkgo.Describe("ManifestWork Clients Test - Resync", func() {
3131
var clusterName string
3232
var workNamePrefix string
3333

34+
var work1UID, work2UID string
35+
var work1Name, work2Name string
36+
3437
ginkgo.BeforeEach(func() {
3538
ctx, cancel = context.WithCancel(context.Background())
3639
sourceID = fmt.Sprintf("mw-resync-%s", rand.String(5))
@@ -45,17 +48,17 @@ var _ = ginkgo.Describe("ManifestWork Clients Test - Resync", func() {
4548
<-time.After(time.Second)
4649

4750
// add two works in the agent cache
48-
work1Name := fmt.Sprintf("%s-1", workNamePrefix)
49-
work1UID := utils.UID(sourceID, common.ManifestWorkGR.String(), clusterName, work1Name)
51+
work1Name = fmt.Sprintf("%s-1", workNamePrefix)
52+
work1UID = utils.UID(sourceID, common.ManifestWorkGR.String(), clusterName, work1Name)
5053
work1 := util.NewManifestWorkWithStatus(clusterName, work1Name)
5154
work1.UID = apitypes.UID(work1UID)
5255
work1.Generation = 1
5356
work1.Labels = map[string]string{common.CloudEventsOriginalSourceLabelKey: sourceID}
5457
work1.Annotations = map[string]string{common.CloudEventsDataTypeAnnotationKey: payload.ManifestBundleEventDataType.String()}
5558
gomega.Expect(watchStore.Add(work1)).ToNot(gomega.HaveOccurred())
5659

57-
work2Name := fmt.Sprintf("%s-2", workNamePrefix)
58-
work2UID := utils.UID(sourceID, common.ManifestWorkGR.String(), clusterName, work2Name)
60+
work2Name = fmt.Sprintf("%s-2", workNamePrefix)
61+
work2UID = utils.UID(sourceID, common.ManifestWorkGR.String(), clusterName, work2Name)
5962
work2 := util.NewManifestWorkWithStatus(clusterName, work2Name)
6063
work2.UID = apitypes.UID(work2UID)
6164
work2.Generation = 1
@@ -77,12 +80,17 @@ var _ = ginkgo.Describe("ManifestWork Clients Test - Resync", func() {
7780
mqttOptions := util.NewMQTTSourceOptionsWithSourceBroadcast(mqttBrokerHost, sourceID)
7881

7982
// simulate a source client restart, recover two existed works
83+
ginkgo.By("start the source client with two works")
84+
work1 := util.NewManifestWork(clusterName, work1Name, true)
85+
work1.UID = apitypes.UID(work1UID)
86+
work2 := util.NewManifestWork(clusterName, work2Name, true)
87+
work2.UID = apitypes.UID(work2UID)
8088
sourceClientHolder, _, err := source.StartManifestWorkSourceClient(
8189
ctx,
8290
sourceID,
8391
mqttOptions,
84-
util.NewManifestWork(clusterName, fmt.Sprintf("%s-1", workNamePrefix), true),
85-
util.NewManifestWork(clusterName, fmt.Sprintf("%s-2", workNamePrefix), true),
92+
work1,
93+
work2,
8694
)
8795
gomega.Expect(err).ToNot(gomega.HaveOccurred())
8896

test/integration/cloudevents/source/client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ func StartManifestWorkSourceClient(
6565
informer := factory.Work().V1().ManifestWorks()
6666
watcherStore.SetInformer(informer.Informer())
6767

68+
go informer.Informer().Run(ctx.Done())
69+
6870
for _, work := range works {
69-
watcherStore.Add(work)
71+
if err := watcherStore.Add(work); err != nil {
72+
return nil, nil, err
73+
}
7074
}
7175

72-
go informer.Informer().Run(ctx.Done())
73-
7476
return clientHolder, informer, nil
7577
}

0 commit comments

Comments
 (0)