Skip to content

Commit

Permalink
Better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 24, 2023
1 parent 129dea8 commit aec550f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sync3/connmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package sync3
import (
"context"
"fmt"
"reflect"
"sort"
"testing"
"time"

Expand Down Expand Up @@ -159,9 +161,10 @@ func TestConnMap_TTLExpiryStaggeredDevices(t *testing.T) {
cidToConn[cid] = conn
}

time.Sleep(510 * time.Millisecond) // all 'A' device conns must have expired
// all expiredCIDs should have expired, none from unexpiredCIDs
time.Sleep(510 * time.Millisecond)

// Destroy should have been called for all alice|A connections
// Destroy should have been called for all expiredCIDs connections
assertDestroyedConns(t, cidToConn, func(cid ConnID) bool {
for _, expCID := range expiredCIDs {
if expCID.String() == cid.String() {
Expand All @@ -173,10 +176,17 @@ func TestConnMap_TTLExpiryStaggeredDevices(t *testing.T) {

// double check this by querying connmap
conns := cm.Conns(alice, "A")
var gotIDs []string
for _, c := range conns {
t.Logf(c.String())
gotIDs = append(gotIDs, c.CID)
}
sort.Strings(gotIDs)
wantIDs := []string{"encryption", "notifications"}
must.Equal(t, len(conns), 2, "unexpected number of Conns for device")
if !reflect.DeepEqual(gotIDs, wantIDs) {
t.Fatalf("unexpected active conns: got %v want %v", gotIDs, wantIDs)
}
}

func assertDestroyedConns(t *testing.T, cidToConn map[ConnID]*Conn, isDestroyedFn func(cid ConnID) bool) {
Expand Down

0 comments on commit aec550f

Please sign in to comment.