Skip to content

Commit

Permalink
chore: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed May 10, 2024
1 parent 632f5b0 commit f0b7b01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
29 changes: 17 additions & 12 deletions waku/v2/api/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ func (apiSub *Sub) cleanup() {
}()

for _, s := range apiSub.subs {
apiSub.wf.UnsubscribeWithSubscription(apiSub.ctx, s)
_, err := apiSub.wf.UnsubscribeWithSubscription(apiSub.ctx, s)
if err != nil {
//Logging with info as this is part of cleanup
apiSub.log.Info("failed to unsubscribe filter", zap.Error(err))
}
}
close(apiSub.DataCh)

Expand All @@ -107,13 +111,14 @@ func (apiSub *Sub) getTopicCounts() map[string]int {

// Run pings asynchronously
for _, s := range apiSub.subs {
go func() {
ctx, _ := context.WithTimeout(apiSub.ctx, 5*time.Second)
err := apiSub.wf.IsSubscriptionAlive(ctx, s)

apiSub.log.Info("Check result:", zap.Any("subID", s.ID), zap.Bool("result", err == nil))
checkResults <- CheckResult{s, err == nil}
}()
go func(sub *subscription.SubscriptionDetails) {
ctx, cancelFunc := context.WithTimeout(apiSub.ctx, 5*time.Second)
defer cancelFunc()
err := apiSub.wf.IsSubscriptionAlive(ctx, sub)

apiSub.log.Info("Check result:", zap.Any("subID", sub.ID), zap.Bool("result", err == nil))
checkResults <- CheckResult{sub, err == nil}
}(s)
}

// Collect healthy topic counts
Expand Down Expand Up @@ -168,11 +173,11 @@ func (apiSub *Sub) resubscribe(topicCounts map[string]int) {
newSubs := make(chan []*subscription.SubscriptionDetails)

for t, cnt := range topicCounts {
cFilter := protocol.ContentFilter{t, apiSub.ContentFilter.ContentTopics}
go func() {
subs, _ := apiSub.subscribe(cFilter, apiSub.Config.MaxPeers-cnt)
cFilter := protocol.ContentFilter{PubsubTopic: t, ContentTopics: apiSub.ContentFilter.ContentTopics}
go func(count int) {
subs, _ := apiSub.subscribe(cFilter, apiSub.Config.MaxPeers-count)
newSubs <- subs
}()
}(cnt)
}

cnt := 0
Expand Down
4 changes: 2 additions & 2 deletions waku/v2/api/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *FilterApiTestSuite) TestSubscribe() {
}
s.Require().True(maps.Keys(apiSub.subs)[0] != maps.Keys(apiSub.subs)[1])
// Publish msg and confirm it's received twice because of multiplexing
s.PublishMsg(&filter.WakuMsg{s.TestTopic, s.TestContentTopic, "Test msg"})
s.PublishMsg(&filter.WakuMsg{PubSubTopic: s.TestTopic, ContentTopic: s.TestContentTopic, Payload: "Test msg"})
cnt := 0
for msg := range apiSub.DataCh {
s.Log.Info("Received msg:", zap.Int("cnt", cnt), zap.String("payload", string(msg.Message().Payload)))
Expand All @@ -69,7 +69,7 @@ func (s *FilterApiTestSuite) TestSubscribe() {

time.Sleep(20 * time.Second)
apiSub.Unsubscribe()
for _ = range apiSub.DataCh {
for range apiSub.DataCh {
}
s.Log.Info("DataCh is closed")

Expand Down

0 comments on commit f0b7b01

Please sign in to comment.