Keep same-second unread events and bound idle push connections

This commit is contained in:
GPT on behalf of DHH
2026-10-07 11:00:47 +02:00
parent 14a2f8f550
commit 27065ef489
7 changed files with 41 additions and 7 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ class PresenceChannelTest < ActionCable::Channel::TestCase
membership = users(:david).memberships.first
freeze_time do
assert_broadcast_on "user_#{users(:david).id}_reads", { room_id: membership.room_id, at: Time.current.to_fs(:epoch) } do
assert_broadcast_on "user_#{users(:david).id}_reads", { room_id: membership.room_id, at: Time.current.to_f } do
subscribe room_id: membership.room_id
end
end
+1 -1
View File
@@ -35,7 +35,7 @@ class UnreadRoomsChannelTest < ActionCable::Channel::TestCase
end
end
assert_equal [ { "roomId" => direct.id, "at" => message.created_at.to_fs(:epoch) } ], broadcasts
assert_equal [ { "roomId" => direct.id, "at" => message.created_at.to_f } ], broadcasts
end
private
+18
View File
@@ -135,6 +135,24 @@ class WebPush::ConnectionsTest < ActiveSupport::TestCase
end
end
test "the idle pool closes connections beyond its bound" do
connections = WebPush::Connections.new(max_idle: 1)
with_push_service do |server|
other = Server.new
connections.request(pinned_connection(server), push_request)
connections.request(pinned_connection(other), push_request)
assert other.hung_up?
assert_not server.hung_up?(within: 0.1)
connections.request(pinned_connection(server), push_request)
assert_equal 1, server.connections
ensure
connections.shutdown
other&.stop
end
end
test "idle connections are closed after the keep-alive timeout and on shutdown" do
connections = WebPush::Connections.new(keep_alive_timeout: 0)
+16 -1
View File
@@ -55,8 +55,23 @@ class UnreadRoomsTest < ApplicationSystemTestCase
end
end
test "a message after a read in the same second marks the room unread" do
room = rooms(:designers)
user = users(:jz)
join_room rooms(:hq)
read_at = Time.current.change(usec: 100_000)
broadcast_unread_notice room, to: user, at: read_at - 1
assert_room_unread room
ActionCable.server.broadcast "user_#{user.id}_reads", { room_id: room.id, at: read_at.to_f }
assert_room_read room
broadcast_unread_notice room, to: user, at: read_at + 0.2
assert_room_unread room
end
private
def broadcast_unread_notice(room, to:, at:)
ActionCable.server.broadcast UnreadRoomsChannel.stream_name_for(to.id), { roomId: room.id, at: at.to_fs(:epoch) }
ActionCable.server.broadcast UnreadRoomsChannel.stream_name_for(to.id), { roomId: room.id, at: at.to_f }
end
end