@@ -1408,6 +1408,35 @@ public function test_awareness_updates_for_multiple_users() {
14081408 $ this ->assertContains ( 'client-2 ' , $ clients , 'Client 2 should be present in awareness state. ' );
14091409 }
14101410
1411+ /**
1412+ * Ensure awareness does not include out of date clients from cached results.
1413+ */
1414+ public function test_awareness_excludes_expired_clients_from_cached_results () {
1415+ $ storage = new WP_Collaboration_Table_Storage ();
1416+ $ cached_data = array (
1417+ array (
1418+ 'client_id ' => 'client-1 ' ,
1419+ 'state ' => array ( 'name ' => 'Client 1 ' ),
1420+ 'timestamp ' => time () - 120 , // Simulate expired client.
1421+ ),
1422+ array (
1423+ 'client_id ' => 'client-2 ' ,
1424+ 'state ' => array ( 'name ' => 'Client 2 ' ),
1425+ 'timestamp ' => time (), // Active client.
1426+ ),
1427+ );
1428+
1429+ // Manually set cached awareness data.
1430+ wp_cache_set ( 'awareness::test-room ' , $ cached_data , 'collaboration ' , HOUR_IN_SECONDS );
1431+
1432+ $ awareness = $ storage ->get_awareness_state ( 'test-room ' );
1433+ $ clients = wp_list_pluck ( $ awareness , 'client_id ' );
1434+
1435+ $ this ->assertNotContains ( 'client-1 ' , $ clients , 'Expired client should not be present in awareness state. ' );
1436+ $ this ->assertContains ( 'client-2 ' , $ clients , 'Active client should be present in awareness state. ' );
1437+ $ this ->assertCount ( 1 , $ awareness , 'Only one active client should be present in awareness state. ' );
1438+ }
1439+
14111440 /*
14121441 * Multiple rooms tests.
14131442 */
0 commit comments