@@ -201,6 +201,64 @@ func TestSMigratedNotificationHandler(t *testing.T) {
201201 }
202202 })
203203
204+ t .Run ("SMigratedNotification_Deduplication" , func (t * testing.T ) {
205+ // Track callback invocations
206+ var callbackCount atomic.Int32
207+
208+ // Create a mock manager with callback
209+ manager := & Manager {
210+ clusterStateReloadCallback : func (ctx context.Context , hostPort string , slotRanges []string ) {
211+ callbackCount .Add (1 )
212+ },
213+ }
214+
215+ // Create notification handler
216+ handler := & NotificationHandler {
217+ manager : manager ,
218+ operationsManager : manager ,
219+ }
220+
221+ // Create SMIGRATED notification with SeqID 456
222+ notification := []interface {}{"SMIGRATED" , int64 (456 ), "127.0.0.1:6379" , "1234" }
223+
224+ ctx := context .Background ()
225+ handlerCtx := push.NotificationHandlerContext {}
226+
227+ // Handle the notification first time
228+ err := handler .handleSMigrated (ctx , handlerCtx , notification )
229+ if err != nil {
230+ t .Errorf ("handleSMigrated should not error on first call: %v" , err )
231+ }
232+
233+ // Verify callback was called once
234+ if callbackCount .Load () != 1 {
235+ t .Errorf ("Expected callback to be called once, got %d" , callbackCount .Load ())
236+ }
237+
238+ // Handle the same notification again (simulating multiple connections)
239+ err = handler .handleSMigrated (ctx , handlerCtx , notification )
240+ if err != nil {
241+ t .Errorf ("handleSMigrated should not error on second call: %v" , err )
242+ }
243+
244+ // Verify callback was NOT called again (still 1)
245+ if callbackCount .Load () != 1 {
246+ t .Errorf ("Expected callback to be called only once (deduplication), got %d" , callbackCount .Load ())
247+ }
248+
249+ // Handle a different notification with different SeqID
250+ notification2 := []interface {}{"SMIGRATED" , int64 (789 ), "127.0.0.1:6380" , "5678" }
251+ err = handler .handleSMigrated (ctx , handlerCtx , notification2 )
252+ if err != nil {
253+ t .Errorf ("handleSMigrated should not error on third call: %v" , err )
254+ }
255+
256+ // Verify callback was called again (now 2)
257+ if callbackCount .Load () != 2 {
258+ t .Errorf ("Expected callback to be called twice (different SeqID), got %d" , callbackCount .Load ())
259+ }
260+ })
261+
204262 t .Run ("InvalidSMigratedNotification_TooShort" , func (t * testing.T ) {
205263 manager := & Manager {}
206264 handler := & NotificationHandler {
0 commit comments