Skip to content
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

Improve logging and error handling, #5

Merged
merged 5 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
11 changes: 6 additions & 5 deletions cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zk

import (
"log/slog"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -112,10 +113,10 @@ func TestNoQuorum(t *testing.T) {
t.Fatalf("Failed to connect and get session")
}
initialSessionID := zk.sessionID
DefaultLogger.Printf(" Session established: id=%d, timeout=%d", zk.sessionID, zk.sessionTimeoutMs)
t.Logf("Session established: id=%d, timeout=%d", zk.sessionID, zk.sessionTimeout)

// Kill the ZooKeeper leader and wait for the session to reconnect.
DefaultLogger.Printf(" Kill the leader")
t.Logf("Kill the leader")
disconnectWatcher1 := sl.NewWatcher(sessionStateMatcher(StateDisconnected))
hasSessionWatcher2 := sl.NewWatcher(sessionStateMatcher(StateHasSession))
tc.StopServer(hasSessionEvent1.Server)
Expand All @@ -135,7 +136,7 @@ func TestNoQuorum(t *testing.T) {
}

// Kill the ZooKeeper leader leaving the cluster without quorum.
DefaultLogger.Printf(" Kill the leader")
t.Logf("Kill the leader")
disconnectWatcher2 := sl.NewWatcher(sessionStateMatcher(StateDisconnected))
tc.StopServer(hasSessionEvent2.Server)

Expand All @@ -151,7 +152,7 @@ func TestNoQuorum(t *testing.T) {
// Make sure that we keep retrying connecting to the only remaining
// ZooKeeper server, but the attempts are being dropped because there is
// no quorum.
DefaultLogger.Printf(" Retrying no luck...")
t.Logf("Retrying no luck...")
var firstDisconnect *Event
begin := time.Now()
for time.Now().Sub(begin) < 6*time.Second {
Expand Down Expand Up @@ -269,7 +270,7 @@ func NewStateLogger(eventCh <-chan Event) *EventLogger {
sw.matchCh <- event
}
}
DefaultLogger.Printf(" event received: %v\n", event)
slog.Info("event received", "event", event)
el.events = append(el.events, event)
el.lock.Unlock()
}
Expand Down
Loading