Refactor peer state change subscription mechanism

Because the code generated new channel for every single event, was easy to miss notification.
Use single channel.
This commit is contained in:
Zoltán Papp
2025-06-02 16:18:31 +02:00
parent f16f0c7831
commit 855d21c37e
3 changed files with 70 additions and 25 deletions

View File

@@ -86,8 +86,8 @@ func TestGetPeerStateChangeNotifierLogic(t *testing.T) {
status := NewRecorder("https://mgm")
_ = status.AddPeer(key, "abc.netbird", ip)
ch := status.GetPeerStateChangeNotifier(key)
assert.NotNil(t, ch, "channel shouldn't be nil")
sub := status.SubscribeToPeerStateChanges(key)
assert.NotNil(t, sub, "channel shouldn't be nil")
peerState := State{
PubKey: key,
@@ -100,7 +100,7 @@ func TestGetPeerStateChangeNotifierLogic(t *testing.T) {
assert.NoError(t, err, "shouldn't return error")
select {
case <-ch:
case <-sub.eventsChan:
default:
t.Errorf("channel wasn't closed after update")
}