@@ -11,6 +11,7 @@ import (
11
11
"time"
12
12
13
13
"github.com/google/uuid"
14
+ "github.com/stretchr/testify/assert"
14
15
"github.com/stretchr/testify/require"
15
16
"go.uber.org/mock/gomock"
16
17
"golang.org/x/xerrors"
@@ -33,9 +34,9 @@ import (
33
34
// make update-golden-files
34
35
var UpdateGoldenFiles = flag .Bool ("update" , false , "update .golden files" )
35
36
36
- // TestHeartbeat_Cleanup is internal so that we can overwrite the cleanup period and not wait an hour for the timed
37
+ // TestHeartbeats_Cleanup is internal so that we can overwrite the cleanup period and not wait an hour for the timed
37
38
// cleanup.
38
- func TestHeartbeat_Cleanup (t * testing.T ) {
39
+ func TestHeartbeats_Cleanup (t * testing.T ) {
39
40
t .Parallel ()
40
41
41
42
ctrl := gomock .NewController (t )
@@ -78,6 +79,41 @@ func TestHeartbeat_Cleanup(t *testing.T) {
78
79
close (waitForCleanup )
79
80
}
80
81
82
+ func TestHeartbeats_LostCoordinator_MarkLost (t * testing.T ) {
83
+ t .Parallel ()
84
+
85
+ ctrl := gomock .NewController (t )
86
+ mStore := dbmock .NewMockStore (ctrl )
87
+
88
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
89
+ defer cancel ()
90
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
91
+
92
+ uut := & heartbeats {
93
+ ctx : ctx ,
94
+ logger : logger ,
95
+ store : mStore ,
96
+ cleanupPeriod : time .Millisecond ,
97
+ coordinators : map [uuid.UUID ]time.Time {
98
+ uuid .New (): time .Now (),
99
+ },
100
+ }
101
+
102
+ mpngs := []mapping {{
103
+ peer : uuid .New (),
104
+ coordinator : uuid .New (),
105
+ updatedAt : time .Now (),
106
+ node : & proto.Node {},
107
+ kind : proto .CoordinateResponse_PeerUpdate_NODE ,
108
+ }}
109
+
110
+ // Filter should still return the mapping without a coordinator, but marked
111
+ // as LOST.
112
+ got := uut .filter (mpngs )
113
+ require .Len (t , got , 1 )
114
+ assert .Equal (t , proto .CoordinateResponse_PeerUpdate_LOST , got [0 ].kind )
115
+ }
116
+
81
117
// TestLostPeerCleanupQueries tests that our SQL queries to clean up lost peers do what we expect,
82
118
// that is, clean up peers and associated tunnels that have been lost for over 24 hours.
83
119
func TestLostPeerCleanupQueries (t * testing.T ) {
0 commit comments