Skip to content

Fix APNs P8 HTTP2 error recovery #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests.
  • Loading branch information
SixiS committed Jul 1, 2025
commit c8249abf09222ee8ab8a794c20daa9223c1c67f9
11 changes: 11 additions & 0 deletions spec/unit/daemon/apnsp8/delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,16 @@
end
end
end

context 'with an HTTP2 client that raises Errno::ECONNRESET' do
before do
allow(http2_client).to receive(:call_async).and_raise(Errno::ECONNRESET)
end

it 'marks the batch as retryable' do
expect(batch).to receive(:mark_all_retryable).with(anything, anything)
expect { delivery.perform }.to raise_error(Errno::ECONNRESET)
end
end
end
end
53 changes: 53 additions & 0 deletions spec/unit/daemon/dispatcher/apnsp8_http2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'unit_spec_helper'

describe Rpush::Daemon::Dispatcher::Apnsp8Http2 do
let(:app) { double(environment: "sandbox", apn_key: "my_key") }
let(:delivery_class) { double }
let(:notification) { double }
let(:batch) { double(mark_delivered: nil, all_processed: nil) }
let(:http2) { double(on: true) }
let!(:token_provider) { double }
let(:queue_payload) { Rpush::Daemon::QueuePayload.new(batch, notification) }
let(:dispatcher) { Rpush::Daemon::Dispatcher::Apnsp8Http2.new(app, delivery_class) }

it 'constructs a new persistent connection' do
expect(NetHttp2::Client).to receive(:new).and_call_original
described_class.new(app, delivery_class)
end

describe 'dispatch' do
before do
allow(NetHttp2::Client).to receive_messages(new: http2)
allow(Rpush::Daemon::Apnsp8::Token).to receive_messages(new: token_provider)
end
it 'delivers the notification' do
delivery = double
expect(delivery_class).to receive(:new).with(app, http2, token_provider, batch).and_return(delivery)
expect(delivery).to receive(:perform)
dispatcher.dispatch(queue_payload)
end
end

describe 'error catching' do
let(:dispatcher) { described_class.new(app, Rpush::Daemon::Apnsp8::Delivery) }
let(:client) { dispatcher.instance_variable_get("@client") }
let(:notification1) { double('Notification 1', data: {}, as_json: {}).as_null_object }

before do
allow(batch).to receive(:each_notification) do |&blk|
[notification1].each(&blk)
end
allow_any_instance_of(Rpush::Daemon::Apnsp8::Delivery).to receive(:prepare_headers).and_return({})
allow(client).to receive(:socket_loop).and_raise(Errno::ECONNRESET)
end

it 'records and raises errors' do
expect(batch).to receive(:mark_all_retryable)
expect(client).to receive(:record_error).with(Errno::ECONNRESET).and_call_original
payload = Rpush::Daemon::QueuePayload.new(batch, notification)
expect do
dispatcher.dispatch(payload)
end.to raise_error(Errno::ECONNRESET)
end
end
end
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy