Skip to content

Commit

Permalink
fix: update based on feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 23, 2024
1 parent fb57a29 commit 36f8d1d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
5 changes: 5 additions & 0 deletions node/cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func main() {
ctx := context.Background()

go func() {
defer func() {
if r := recover(); r != nil {
log.Error().Any("panic", r).Msg("panic recovered from network checks")
}
}()
time.Sleep(5 * time.Second) // give some buffer until the app is ready
ping.Run(ctx)
os.Exit(1)
Expand Down
5 changes: 0 additions & 5 deletions node/pkg/checker/ping/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ping

import (
"context"
"sync"
"time"

probing "github.com/prometheus-community/pro-bing"
Expand Down Expand Up @@ -70,7 +69,6 @@ type App struct {
Endpoints []PingEndpoint
FailCount map[string]int
ResultsBuffer chan PingResult
mu sync.Mutex
}

func (pe *PingEndpoint) run() error {
Expand Down Expand Up @@ -157,7 +155,6 @@ func (app *App) Start(ctx context.Context) {
case <-ctx.Done():
return
case result := <-app.ResultsBuffer:
app.mu.Lock()
if result.Success && result.Delay < app.MaxDelay {
app.FailCount[result.Address] = 0
} else {
Expand All @@ -174,10 +171,8 @@ func (app *App) Start(ctx context.Context) {
// shuts down if all endpoints fails pinging 2 times in a row
if failedCount == len(app.Endpoints) {
log.Error().Msg("All pings failed, shutting down")
app.mu.Unlock()
return
}
app.mu.Unlock()
}
}

Expand Down
7 changes: 0 additions & 7 deletions node/pkg/checker/ping/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func TestApp_Start_SuccessfulPing(t *testing.T) {

app.Start(ctx)

app.mu.Lock()
defer app.mu.Unlock()
assert.Equal(t, 0, app.FailCount["8.8.8.8"])
}

Expand All @@ -69,8 +67,6 @@ func TestApp_Start_FailedPing(t *testing.T) {
app.Start(ctx)

// Ensure FailCount incremented due to failure
app.mu.Lock()
defer app.mu.Unlock()
assert.Equal(t, 1, app.FailCount["8.8.8.8"])
}

Expand All @@ -92,9 +88,6 @@ func TestApp_Start_ShutdownOnAllFailures(t *testing.T) {

app.Start(ctx)

app.mu.Lock()
defer app.mu.Unlock()

// Check that FailCount for all endpoints has reached DefaultMaxFails
for _, endpoint := range app.Endpoints {
assert.Equal(t, DefaultMaxFails, app.FailCount[endpoint.Address])
Expand Down

0 comments on commit 36f8d1d

Please sign in to comment.