-
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
When a peer disconnects gracefully from the server and immediately connects back, then the server will clean up an incorrect peer instance from the in-memory store. In this fix the store checks the peers instance before deleting it.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package server | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestStore_DeletePeer(t *testing.T) { | ||
s := NewStore() | ||
p := NewPeer([]byte("peer_one"), nil, nil) | ||
Check failure on line 9 in relay/server/store_test.go GitHub Actions / test (sqlite)
Check failure on line 9 in relay/server/store_test.go GitHub Actions / lint (macos-latest)
Check failure on line 9 in relay/server/store_test.go GitHub Actions / lint (ubuntu-latest)
Check failure on line 9 in relay/server/store_test.go GitHub Actions / test (amd64, sqlite)
Check failure on line 9 in relay/server/store_test.go GitHub Actions / test (386, sqlite)
|
||
s.AddPeer(p) | ||
s.DeletePeer(p) | ||
if _, ok := s.Peer(p.String()); ok { | ||
t.Errorf("peer was not deleted") | ||
} | ||
} | ||
|
||
func TestStore_DeleteDeprecatedPeer(t *testing.T) { | ||
s := NewStore() | ||
|
||
p1 := NewPeer([]byte("peer_id"), nil, nil) | ||
Check failure on line 20 in relay/server/store_test.go GitHub Actions / test (sqlite)
Check failure on line 20 in relay/server/store_test.go GitHub Actions / lint (macos-latest)
Check failure on line 20 in relay/server/store_test.go GitHub Actions / lint (ubuntu-latest)
Check failure on line 20 in relay/server/store_test.go GitHub Actions / test (amd64, sqlite)
Check failure on line 20 in relay/server/store_test.go GitHub Actions / test (386, sqlite)
|
||
p2 := NewPeer([]byte("peer_id"), nil, nil) | ||
Check failure on line 21 in relay/server/store_test.go GitHub Actions / test (sqlite)
Check failure on line 21 in relay/server/store_test.go GitHub Actions / lint (macos-latest)
Check failure on line 21 in relay/server/store_test.go GitHub Actions / lint (ubuntu-latest)
Check failure on line 21 in relay/server/store_test.go GitHub Actions / test (amd64, sqlite)
Check failure on line 21 in relay/server/store_test.go GitHub Actions / test (386, sqlite)
|
||
|
||
s.AddPeer(p1) | ||
s.AddPeer(p2) | ||
s.DeletePeer(p1) | ||
|
||
if _, ok := s.Peer(p2.String()); !ok { | ||
t.Errorf("second peer was deleted") | ||
} | ||
} |