bug_bunny 5.1.1 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/AGENTS.md +3 -2
- data/CHANGELOG.md +32 -0
- data/CLAUDE.md +2 -2
- data/README.md +69 -3
- data/Rakefile +9 -1
- data/docs/behavior/behavior.md +60 -10
- data/docs/config/configuracion.md +67 -52
- data/docs/consumed/rabbitmq.md +4 -4
- data/docs/errors/errors.md +7 -5
- data/docs/release/release.md +13 -8
- data/docs/test/testing.md +28 -9
- data/lib/bug_bunny/configuration.rb +33 -2
- data/lib/bug_bunny/consumer.rb +184 -31
- data/lib/bug_bunny/consumer_middleware/rails_executor.rb +33 -0
- data/lib/bug_bunny/consumer_middleware.rb +13 -0
- data/lib/bug_bunny/drain_tracker.rb +54 -0
- data/lib/bug_bunny/railtie.rb +18 -2
- data/lib/bug_bunny/version.rb +1 -1
- data/lib/bug_bunny.rb +1 -0
- data/skill/SKILL.md +21 -8
- data/skill/references/consumer.md +36 -1
- data/skill/references/errores.md +1 -1
- data/skill/references/routing.md +1 -1
- data/skill/references/testing.md +4 -1
- data/spec/integration/drain_spec.rb +177 -0
- data/spec/rails/app.rb +70 -0
- data/spec/rails/consumer_rails_executor_spec.rb +165 -0
- data/spec/rails/rails_helper.rb +6 -0
- data/spec/unit/configuration_spec.rb +33 -1
- data/spec/unit/consumer_middleware_spec.rb +13 -0
- data/spec/unit/consumer_rails_executor_outside_rails_spec.rb +19 -0
- data/spec/unit/drain_tracker_spec.rb +37 -0
- metadata +54 -3
data/lib/bug_bunny.rb
CHANGED
|
@@ -16,6 +16,7 @@ require_relative 'bug_bunny/middleware/raise_error'
|
|
|
16
16
|
require_relative 'bug_bunny/middleware/json_response'
|
|
17
17
|
require_relative 'bug_bunny/client'
|
|
18
18
|
require_relative 'bug_bunny/session'
|
|
19
|
+
require_relative 'bug_bunny/drain_tracker'
|
|
19
20
|
require_relative 'bug_bunny/consumer'
|
|
20
21
|
require_relative 'bug_bunny/request'
|
|
21
22
|
require_relative 'bug_bunny/producer'
|
data/skill/SKILL.md
CHANGED
|
@@ -19,7 +19,11 @@ Gema Ruby: capa de routing RESTful sobre AMQP/RabbitMQ. Microservicios se comuni
|
|
|
19
19
|
|
|
20
20
|
## Contrato resumido (piso mínimo)
|
|
21
21
|
|
|
22
|
-
> Resume el contrato de **`bug_bunny` 5.
|
|
22
|
+
> Resume el contrato de **`bug_bunny` 5.3.0** (anclado a `v5.3.0`). Suficiente para el uso típico sin abrir el detalle; el detalle version-locked está en el **Índice de artefactos** de abajo. Antipatrones/API completa: más abajo (embebido interim, ver Cobertura y fronteras).
|
|
23
|
+
>
|
|
24
|
+
> **Si venís de 5.1.x, un cambio de conducta (5.2.0):** una entrega cuyo middleware —o `handle_fatal_error`— levanta **antes del ack** ahora se **rechaza sin requeue** (evento `consumer.delivery_failed`), en `subscribe` y en `drain`. Antes quedaba sin ack ni reject y trababa el consumidor. Si un middleware levantaba a propósito para que el mensaje se reintentara, ahora el mensaje se pierde: el reintento es tuyo. Detalle en [`docs/behavior/behavior.md`](../docs/behavior/behavior.md).
|
|
25
|
+
>
|
|
26
|
+
> **Si venís de 5.2.x, dos cambios de conducta dentro de Rails (5.3.0):** cada mensaje del Consumer corre dentro de `Rails.application.executor.wrap`. En Rails ≥ 7.0, un error que escapa del mensaje además se reporta a `Rails.error` (el mensaje se sigue rechazando sin requeue), y la caché de queries de ActiveRecord queda prendida durante cada mensaje. Se apagan con `config.consumer_rails_executor = false`. Detalle en [`docs/behavior/behavior.md`](../docs/behavior/behavior.md) y [`docs/config/configuracion.md`](../docs/config/configuracion.md).
|
|
23
27
|
>
|
|
24
28
|
> **Si venís de 4.x, dos breaking a mirar antes de subir:** `5.0.0` eliminó la constante pública `BugBunny::SecurityError` (un `rescue BugBunny::SecurityError` que sobreviva revienta con `NameError` y **enmascara la excepción original**) y `4.18.0` cambió el wrapping `Bunny::Exception` → `CommunicationError`. Detalle en `CHANGELOG.md`.
|
|
25
29
|
|
|
@@ -29,7 +33,7 @@ Gema Ruby: capa de routing RESTful sobre AMQP/RabbitMQ. Microservicios se comuni
|
|
|
29
33
|
|---|---|
|
|
30
34
|
| `BugBunny::Client` | `client.request(url, method: :get)` (RPC sync) · `client.publish(url, body:)` (fire-and-forget, 202) · `client.publish(url, confirmed: true, mandatory: true)` (publisher confirms) |
|
|
31
35
|
| `BugBunny::Resource` | ORM tipo AR: `self.exchange=` / `self.resource_name=` / `connection_pool=`; `find/where/create/save/destroy` |
|
|
32
|
-
| `BugBunny::Consumer` | `BugBunny::Consumer.subscribe(connection
|
|
36
|
+
| `BugBunny::Consumer` | `BugBunny::Consumer.subscribe(connection:, queue_name:, exchange_name:, routing_key:)` (loop bloqueante) · `BugBunny::Consumer.drain(...)` (mismos args; consume hasta que la cola queda quieta y retorna cuántos procesó — para correrlo como job, 5.2.0) |
|
|
33
37
|
| `BugBunny::Controller` | `before/around/after_action`, `rescue_from`, `render status:, json:` |
|
|
34
38
|
| `BugBunny.routes.draw` | `resources :x` · `namespace` · `member`/`collection` |
|
|
35
39
|
| `BugBunny.configure` | `host/port/username/password` · `rpc_timeout` (default 10) · `nack_raise`/`return_raise` (default `true`) · `on_return` |
|
|
@@ -56,20 +60,21 @@ client.publish('events', body: { type: 'x' }) # => { 'status' => 202 }
|
|
|
56
60
|
- `confirmed:true + mandatory:true` con `return_raise` (default `true`) → `PublishUnroutable` si no rutea.
|
|
57
61
|
- `BugBunny::Consumer.subscribe` requiere `connection:`. No correr el Consumer en threads de Puma (loop bloqueante).
|
|
58
62
|
- `exchange_options: { durable: true }` debe matchear la declaración del consumer, o `Bunny::PreconditionFailed`.
|
|
63
|
+
- **`drain` (5.2.0):** la conexión es **de quien llama** — `drain` cierra su canal, no la conexión; si la creás por corrida, cerrala (`ensure connection.close`) o cada corrida deja una abierta. Con un flujo sostenido más rápido que `drain_idle_timeout` **no retorna**: acotalo desde el job. Detalle en [`skill/references/consumer.md`](references/consumer.md) y [`docs/behavior/behavior.md`](../docs/behavior/behavior.md).
|
|
59
64
|
- **Errores de transporte (4.18+):** TCP fail, conn rota, canal cerrado → siempre `BugBunny::CommunicationError`. No rescatar `Bunny::TCPConnectionFailed`/`ConnectionClosedError` directo — quedó atrás de la frontera. La original sigue accesible vía `.cause`.
|
|
60
65
|
|
|
61
66
|
## Índice de artefactos (fuente de verdad)
|
|
62
67
|
|
|
63
|
-
El detalle vive en `docs/<capa>/` (modelo `dev-*`); esta skill **indexa y resume**, no duplica. Links relativos = version-locked (mismo tag del release, `v5.
|
|
68
|
+
El detalle vive en `docs/<capa>/` (modelo `dev-*`); esta skill **indexa y resume**, no duplica. Links relativos = version-locked (mismo tag del release, `v5.3.0`; `gemspec.files` incluye `docs/**`, así que estos archivos viajan dentro del `.gem` que ya tenés instalado).
|
|
64
69
|
|
|
65
70
|
| Capa | Artefacto | Estado |
|
|
66
71
|
|---|---|---|
|
|
67
72
|
| Glosario de dominio | [docs/glossary/glossary.md](../docs/glossary/glossary.md) | parcial, acreta por PR |
|
|
68
|
-
| Comportamiento (flujos) | [docs/behavior/behavior.md](../docs/behavior/behavior.md) | completa —
|
|
73
|
+
| Comportamiento (flujos) | [docs/behavior/behavior.md](../docs/behavior/behavior.md) | completa — 8 flujos |
|
|
69
74
|
| Configuración | [docs/config/configuracion.md](../docs/config/configuracion.md) | §a-§e/§i estructura + §f/§g/§h enrich — completa |
|
|
70
75
|
| Dependencias consumidas | [docs/consumed/rabbitmq.md](../docs/consumed/rabbitmq.md) | §a/§b/§d estructura + §c/§e enrich |
|
|
71
76
|
| Errores | [docs/errors/errors.md](../docs/errors/errors.md) | §a/§b/§d completas; §c política inferida (verificación humana pendiente) |
|
|
72
|
-
| Test | [docs/test/testing.md](../docs/test/testing.md) | §a-§h —
|
|
77
|
+
| Test | [docs/test/testing.md](../docs/test/testing.md) | §a-§h — 18 unit / 8 integration / 1 rails (`spec/rails/`, en su propio proceso) |
|
|
73
78
|
| Release | [docs/release/release.md](../docs/release/release.md) | completa (régimen gema: build→publish; §e/f/g n/a) |
|
|
74
79
|
| Datos | — | n/a — gema sin DB |
|
|
75
80
|
| Eventos | — | n/a — la gema **es** el transporte; no declara catálogo de eventos de dominio propio |
|
|
@@ -136,7 +141,8 @@ Por RFC-008 §2: no se fabrica la capa, no se borra contrato sin destino, no se
|
|
|
136
141
|
| `BugBunny::Producer` | Publica mensajes. Implementa tres modos: `#fire` (async), `#confirmed` (sync con `wait_for_confirms`) y `#rpc` (direct reply-to + `Concurrent::IVar`). |
|
|
137
142
|
| `BugBunny::Client` | API de alto nivel. Pool de conexiones y middleware stack (onion architecture). |
|
|
138
143
|
| `BugBunny::Consumer` | Subscribe loop con health check. Rutea mensajes via `BugBunny.routes`. |
|
|
139
|
-
| `BugBunny::ConsumerMiddleware::Stack` | Pipeline de middlewares antes de `process_message`. Thread-safe. |
|
|
144
|
+
| `BugBunny::ConsumerMiddleware::Stack` | Pipeline de middlewares antes de `process_message`. Thread-safe. `use` agrega al final; `prepend` pone al principio (envuelve a todos). |
|
|
145
|
+
| `BugBunny::ConsumerMiddleware::RailsExecutor` | Sólo en Rails: envuelve cada mensaje con `Rails.application.executor.wrap`, para que el estado por hilo (`CurrentAttributes`, conexión de AR) no pase al siguiente. Lo registra el Railtie primero; se apaga con `config.consumer_rails_executor = false`. |
|
|
140
146
|
| `BugBunny::Controller` | Base class tipo Rails. `before_action`, `around_action`, `after_action`, `rescue_from`, `render`. |
|
|
141
147
|
| `BugBunny::Resource` | ORM sobre AMQP. `find`, `where`, `create`, `save`, `destroy`. ActiveModel validations y callbacks. |
|
|
142
148
|
| `BugBunny::Routing::RouteSet` | DSL de rutas: `resources`, `namespace`, `member`, `collection`. |
|
|
@@ -144,7 +150,7 @@ Por RFC-008 §2: no se fabrica la capa, no se borra contrato sin destino, no se
|
|
|
144
150
|
| `BugBunny::Middleware::Stack` | Builder de middlewares client-side (onion architecture tipo Faraday). |
|
|
145
151
|
| BugBunny::Request | Value object del mensaje saliente con metadata AMQP completa. |
|
|
146
152
|
| BugBunny::OTel | Helpers para emitir campos siguiendo las OTel semantic conventions for messaging. |
|
|
147
|
-
| BugBunny::Railtie | Integración Rails: autoload de `app/rabbit`, fork safety (Puma, Spring). |
|
|
153
|
+
| BugBunny::Railtie | Integración Rails: autoload de `app/rabbit`, fork safety (Puma, Spring), executor de Rails alrededor de cada mensaje del Consumer. |
|
|
148
154
|
|
|
149
155
|
---
|
|
150
156
|
|
|
@@ -252,6 +258,10 @@ BugBunny.configure do |config|
|
|
|
252
258
|
config.health_check_interval = 60
|
|
253
259
|
config.health_check_file = 'tmp/bb_health'
|
|
254
260
|
|
|
261
|
+
# Consumer.drain (5.2.0): segundos sin entregas para dar la cola por vacía, y cada cuánto se chequea
|
|
262
|
+
config.drain_idle_timeout = 5
|
|
263
|
+
config.drain_poll_interval = 0.1
|
|
264
|
+
|
|
255
265
|
# Routing
|
|
256
266
|
config.controller_namespace = 'BugBunny::Controllers'
|
|
257
267
|
end
|
|
@@ -379,6 +389,9 @@ Cada slot del pool cachea su `Session` y `Producer` durante su vida útil. Esto
|
|
|
379
389
|
### ¿Cómo funciona fork safety?
|
|
380
390
|
`BugBunny::Railtie` registra hooks en `ActiveSupport::ForkTracker` (Rails 7.1+), `Puma.events.on_worker_boot` y `Spring.after_fork` para llamar `BugBunny.disconnect` y evitar sockets TCP heredados.
|
|
381
391
|
|
|
392
|
+
### ¿Por qué el estado de un mensaje no pasa al siguiente?
|
|
393
|
+
El Consumer procesa en el hilo de trabajo de Bunny, que Rails no conoce. En Rails, el Railtie registra `ConsumerMiddleware::RailsExecutor` al principio de la cadena (`prepend`), que envuelve cada mensaje con `Rails.application.executor.wrap`: al entrar y al salir se resetean los `CurrentAttributes`, y al salir la conexión de ActiveRecord vuelve al pool. Va primero para envolver también a los middlewares que cargan estado por hilo (el de tracing de ExisRay). **Cambios de conducta:** en Rails ≥ 7.0, un error que escapa del mensaje además se reporta a `Rails.error` con `handled: false` (el mensaje se sigue rechazando sin requeue); y la caché de queries de AR queda prendida durante cada mensaje (en el hilo de Bunny estaba apagada). Apagado: `config.consumer_rails_executor = false`.
|
|
394
|
+
|
|
382
395
|
---
|
|
383
396
|
|
|
384
397
|
## Antipatrones
|
|
@@ -428,7 +441,7 @@ Limitación de RSpec: `instance_double` valida que el método exista pero **no**
|
|
|
428
441
|
|
|
429
442
|
### Guard anti-RCE (403, no es excepción)
|
|
430
443
|
**Causa:** El mensaje intenta ejecutar un controlador que no hereda de `BugBunny::Controller`.
|
|
431
|
-
**Comportamiento:** El worker responde **403 Forbidden** + reject + log `event=consumer.security_violation` (`consumer.rb:
|
|
444
|
+
**Comportamiento:** El worker responde **403 Forbidden** + reject + log `event=consumer.security_violation` (`consumer.rb:375-381`); no levanta una excepción dedicada.
|
|
432
445
|
**Resolución:** Verificar la jerarquía de controladores y que `config.controller_namespace` coincida.
|
|
433
446
|
|
|
434
447
|
### BugBunny::RouteNotFoundError (404)
|
|
@@ -11,10 +11,36 @@ consumer = BugBunny::Consumer.subscribe(
|
|
|
11
11
|
exchange_type: 'topic',
|
|
12
12
|
exchange_opts: { durable: true },
|
|
13
13
|
queue_opts: { auto_delete: false },
|
|
14
|
-
block: true #
|
|
14
|
+
block: true # false retorna al instante y cierra el canal: no consume nada (#64)
|
|
15
15
|
)
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Drain (drenar y salir)
|
|
19
|
+
|
|
20
|
+
Para correr un consumidor **como job**: consume hasta que la cola queda quieta y retorna cuántos mensajes procesó (incluye los rechazados). Con la cola vacía retorna `0` sin esperar.
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
connection = BugBunny.create_connection
|
|
24
|
+
begin
|
|
25
|
+
processed_count = BugBunny::Consumer.drain(
|
|
26
|
+
connection: connection,
|
|
27
|
+
queue_name: 'my_app_queue',
|
|
28
|
+
exchange_name: 'my_exchange',
|
|
29
|
+
routing_key: 'users.*'
|
|
30
|
+
)
|
|
31
|
+
ensure
|
|
32
|
+
connection.close # drain cierra su canal, no la conexión: la conexión es de quien llama
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- Respeta `channel_prefetch`, igual que `subscribe`.
|
|
37
|
+
- Termina tras `drain_idle_timeout` segundos (default `5`) sin entregas y sin nada en proceso; lo chequea cada `drain_poll_interval` (default `0.1`).
|
|
38
|
+
- Un mensaje que llega dentro de esa ventana entra en esta vuelta; los posteriores, en la próxima corrida. Una entrega ya recibida al cancelar se procesa antes de volver; si igual no se ack-eara, vuelve a la cola (at-least-once).
|
|
39
|
+
- **Con un flujo sostenido no retorna**: si los mensajes llegan más seguido que `drain_idle_timeout`, la ventana nunca vence. Acotalo desde afuera (timeout del job).
|
|
40
|
+
- **Una entrega que falla sale de la cola**: si un middleware levanta antes del ack, se rechaza sin requeue y no traba el prefetch.
|
|
41
|
+
- **La conexión es de quien llama**: `drain` cierra su canal, no la conexión. Si la creaste para la corrida, cerrala (si no, cada corrida deja una abierta).
|
|
42
|
+
- **No** tiene loop de reconexión ni health check: si falla, lo reintenta el framework del job (Bunny sí recupera la conexión por su cuenta con `automatically_recover`).
|
|
43
|
+
|
|
18
44
|
## Flujo de Procesamiento
|
|
19
45
|
|
|
20
46
|
1. Escucha en la queue con `manual_ack: true`.
|
|
@@ -61,6 +87,15 @@ BugBunny.configuration.consumer_middlewares.use MyTracing::Middleware
|
|
|
61
87
|
BugBunny.configuration.consumer_middlewares.use MyAuth::Middleware
|
|
62
88
|
```
|
|
63
89
|
|
|
90
|
+
`use` agrega al final de la cadena; `prepend` pone al principio, envolviendo a todos.
|
|
91
|
+
|
|
92
|
+
### Executor de Rails (automático en Rails)
|
|
93
|
+
|
|
94
|
+
En Rails, el Railtie registra `BugBunny::ConsumerMiddleware::RailsExecutor` **primero**: cada mensaje corre dentro
|
|
95
|
+
de `Rails.application.executor.wrap`, así que los `CurrentAttributes` no pasan de un mensaje al siguiente y la
|
|
96
|
+
conexión de ActiveRecord vuelve al pool. Cambios de conducta: en Rails ≥ 7.0, un error que escapa del mensaje además
|
|
97
|
+
se reporta a `Rails.error`, y la caché de queries de AR queda prendida durante cada mensaje. Se apaga con `config.consumer_rails_executor = false` (desde `config/initializers`).
|
|
98
|
+
|
|
64
99
|
### Crear Middleware
|
|
65
100
|
|
|
66
101
|
```ruby
|
data/skill/references/errores.md
CHANGED
|
@@ -63,7 +63,7 @@ message, details } }`), parsealo en el boundary del servicio desde
|
|
|
63
63
|
|
|
64
64
|
### Guard anti-RCE (403, no es excepción)
|
|
65
65
|
**Causa:** Un mensaje intenta ejecutar un controlador que no hereda de `BugBunny::Controller`.
|
|
66
|
-
**Cuándo:** El consumer resuelve la clase (`constantize`) pero falla `controller_class < BugBunny::Controller` (`consumer.rb:
|
|
66
|
+
**Cuándo:** El consumer resuelve la clase (`constantize`) pero falla `controller_class < BugBunny::Controller` (`consumer.rb:375-381`).
|
|
67
67
|
**Comportamiento:** El worker **no levanta una excepción** — loguea `event=consumer.security_violation`, responde **403 Forbidden** al caller RPC y rechaza el mensaje sin requeue.
|
|
68
68
|
**Resolución:** Verificar que el controlador herede de `BugBunny::Controller` y que `config.controller_namespace` sea correcto.
|
|
69
69
|
|
data/skill/references/routing.md
CHANGED
|
@@ -69,7 +69,7 @@ El consumer resuelve el controlador concatenando:
|
|
|
69
69
|
|
|
70
70
|
Ejemplo: namespace `:admin`, controller `:reports` → `BugBunny::Controllers::Admin::ReportsController`
|
|
71
71
|
|
|
72
|
-
Valida que el controlador sea subclase de `BugBunny::Controller` (guard anti-RCE). Si no, el worker loguea `consumer.security_violation`, responde **403 Forbidden** y rechaza el mensaje sin requeue (`consumer.rb:
|
|
72
|
+
Valida que el controlador sea subclase de `BugBunny::Controller` (guard anti-RCE). Si no, el worker loguea `consumer.security_violation`, responde **403 Forbidden** y rechaza el mensaje sin requeue (`consumer.rb:375-381`) — no levanta una excepción dedicada.
|
|
73
73
|
|
|
74
74
|
## Route Object
|
|
75
75
|
|
data/skill/references/testing.md
CHANGED
|
@@ -131,7 +131,10 @@ TEST_POOL = ConnectionPool.new(size: 5) { BugBunny.create_connection }
|
|
|
131
131
|
## Ejecutar Tests
|
|
132
132
|
|
|
133
133
|
```bash
|
|
134
|
-
bundle exec
|
|
134
|
+
bundle exec rake # Todos: spec/ y spec/rails/ (cada una en su proceso)
|
|
135
|
+
bundle exec rspec # spec/, sin Rails (.rspec excluye spec/rails/ si no se la pide)
|
|
136
|
+
bundle exec rspec spec/rails # Solo el Railtie (igual que rake spec:rails)
|
|
137
|
+
bundle exec rake spec:rails # Solo el Railtie, con una app Rails mínima
|
|
135
138
|
bundle exec rspec spec/unit/ # Solo unit
|
|
136
139
|
bundle exec rspec spec/integration/ # Solo integration (requiere RabbitMQ)
|
|
137
140
|
bundle exec rspec spec/unit/session_spec.rb # Archivo específico
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'support/integration_helper'
|
|
5
|
+
|
|
6
|
+
module DrainSpec
|
|
7
|
+
# Controller que sólo cuenta cuántas veces se lo invocó.
|
|
8
|
+
class PingController < BugBunny::Controller
|
|
9
|
+
def self.handled_count
|
|
10
|
+
@handled_count ||= Concurrent::AtomicFixnum.new(0)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def index
|
|
14
|
+
self.class.handled_count.increment
|
|
15
|
+
render status: 200, json: { pong: true }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
RSpec.describe 'Consumer.drain', :integration do
|
|
21
|
+
let(:queue_name) { unique('drain_q') }
|
|
22
|
+
let(:exchange_name) { unique('drain_x') }
|
|
23
|
+
let(:client) { BugBunny::Client.new(pool: TEST_POOL) }
|
|
24
|
+
let(:admin_connection) { BugBunny.create_connection }
|
|
25
|
+
|
|
26
|
+
# Durable y no exclusiva: drain declara la cola con su propia conexión, y RabbitMQ 4
|
|
27
|
+
# rechaza las colas no durables y no exclusivas.
|
|
28
|
+
let(:queue_opts) { { durable: true, exclusive: false, auto_delete: false } }
|
|
29
|
+
|
|
30
|
+
let(:drain_args) do
|
|
31
|
+
{ queue_name: queue_name, exchange_name: exchange_name, exchange_type: 'topic',
|
|
32
|
+
routing_key: 'ping', queue_opts: queue_opts }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
before do
|
|
36
|
+
DrainSpec::PingController.handled_count.value = 0
|
|
37
|
+
BugBunny.configure do |config|
|
|
38
|
+
config.controller_namespace = 'DrainSpec'
|
|
39
|
+
config.drain_idle_timeout = 1
|
|
40
|
+
config.drain_poll_interval = 0.05
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
admin_channel = admin_connection.create_channel
|
|
44
|
+
effective_exchange_opts = BugBunny::Session::DEFAULT_EXCHANGE_OPTIONS.merge(BugBunny.configuration.exchange_options)
|
|
45
|
+
exchange = admin_channel.topic(exchange_name, effective_exchange_opts)
|
|
46
|
+
admin_channel.queue(queue_name, queue_opts).bind(exchange, routing_key: 'ping')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
after do
|
|
50
|
+
BugBunny.configure do |config|
|
|
51
|
+
config.controller_namespace = 'BugBunny::Controllers'
|
|
52
|
+
config.drain_idle_timeout = 5
|
|
53
|
+
config.drain_poll_interval = 0.1
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
cleanup_channel = admin_connection.create_channel
|
|
57
|
+
cleanup_channel.queue_delete(queue_name)
|
|
58
|
+
cleanup_channel.exchange_delete(exchange_name)
|
|
59
|
+
admin_connection.close
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def publish_ping
|
|
63
|
+
client.publish('ping', method: :get, exchange: exchange_name, exchange_type: 'topic', routing_key: 'ping')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def passive_queue
|
|
67
|
+
admin_connection.create_channel.queue(queue_name, queue_opts.merge(passive: true))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def messages_in_queue
|
|
71
|
+
passive_queue.message_count
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# La conexión es del llamador: drain cierra su canal, no la conexión.
|
|
75
|
+
def drain
|
|
76
|
+
connection = BugBunny.create_connection
|
|
77
|
+
BugBunny::Consumer.drain(connection: connection, **drain_args)
|
|
78
|
+
ensure
|
|
79
|
+
connection&.close
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'procesa todos los mensajes encolados, los ack-ea y retorna cuántos fueron' do
|
|
83
|
+
BugBunny.configure { |config| config.channel_prefetch = 3 }
|
|
84
|
+
5.times { publish_ping }
|
|
85
|
+
sleep 0.3
|
|
86
|
+
|
|
87
|
+
expect(drain).to eq(5)
|
|
88
|
+
expect(DrainSpec::PingController.handled_count.value).to eq(5)
|
|
89
|
+
expect(messages_in_queue).to eq(0)
|
|
90
|
+
ensure
|
|
91
|
+
BugBunny.configure { |config| config.channel_prefetch = 1 }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'con la cola vacía retorna 0 sin esperar la ventana de inactividad' do
|
|
95
|
+
started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
96
|
+
|
|
97
|
+
expect(drain).to eq(0)
|
|
98
|
+
expect(Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at).to be < 1
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Criterio 5: shutdown corre al volver y cierra el canal. Se mira el canal y no el
|
|
102
|
+
# `consumer_count`: ése queda en 0 por el `cancel` aunque falte el `ensure shutdown`, así
|
|
103
|
+
# que un test sobre él pasaría con el defecto intacto. El canal se toma antes: es el mismo
|
|
104
|
+
# que después usa drain.
|
|
105
|
+
it 'cierra su canal al volver, con la cola vacía y con mensajes' do
|
|
106
|
+
[0, 2].each do |pending|
|
|
107
|
+
pending.times { publish_ping }
|
|
108
|
+
sleep 0.3 if pending.positive?
|
|
109
|
+
|
|
110
|
+
connection = BugBunny.create_connection
|
|
111
|
+
consumer = BugBunny::Consumer.new(connection)
|
|
112
|
+
channel = consumer.session.channel
|
|
113
|
+
|
|
114
|
+
consumer.drain(**drain_args)
|
|
115
|
+
|
|
116
|
+
expect(channel).not_to be_open, "con #{pending} mensajes el canal quedó abierto"
|
|
117
|
+
ensure
|
|
118
|
+
connection&.close
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Review de #65: un middleware que levanta dejaba la entrega sin ack ni reject; con
|
|
123
|
+
# prefetch 1 trababa la cola y drain volvía "con éxito" sin haber sacado nada.
|
|
124
|
+
it 'una entrega cuyo middleware levanta sale de la cola y no traba el prefetch' do
|
|
125
|
+
exploding = Class.new(BugBunny::ConsumerMiddleware::Base) do
|
|
126
|
+
def call(*)
|
|
127
|
+
raise 'middleware roto'
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
BugBunny.consumer_middlewares.use exploding
|
|
131
|
+
BugBunny.configure { |config| config.channel_prefetch = 1 }
|
|
132
|
+
3.times { publish_ping }
|
|
133
|
+
sleep 0.3
|
|
134
|
+
|
|
135
|
+
expect(drain).to eq(3)
|
|
136
|
+
expect(messages_in_queue).to eq(0)
|
|
137
|
+
expect(DrainSpec::PingController.handled_count.value).to eq(0)
|
|
138
|
+
ensure
|
|
139
|
+
BugBunny.configuration.instance_variable_set(:@consumer_middlewares, BugBunny::ConsumerMiddleware::Stack.new)
|
|
140
|
+
BugBunny.configure { |config| config.channel_prefetch = 1 }
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Review de #65: la guarda `unless settled` de `settle_failed_delivery`. Si el error
|
|
144
|
+
# llega DESPUÉS del ack, rechazar el tag ya confirmado hace que el broker cierre el
|
|
145
|
+
# canal; sin la guarda, drain terminaba en Timeout::Error con mensajes en la cola.
|
|
146
|
+
it 'un middleware que levanta después del ack no rechaza la entrega ya resuelta' do
|
|
147
|
+
after_ack = Class.new(BugBunny::ConsumerMiddleware::Base) do
|
|
148
|
+
def call(*args)
|
|
149
|
+
@app.call(*args)
|
|
150
|
+
raise 'después del ack'
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
BugBunny.consumer_middlewares.use after_ack
|
|
154
|
+
BugBunny.configure { |config| config.channel_prefetch = 1 }
|
|
155
|
+
3.times { publish_ping }
|
|
156
|
+
sleep 0.3
|
|
157
|
+
|
|
158
|
+
expect(drain).to eq(3)
|
|
159
|
+
expect(messages_in_queue).to eq(0)
|
|
160
|
+
expect(DrainSpec::PingController.handled_count.value).to eq(3)
|
|
161
|
+
ensure
|
|
162
|
+
BugBunny.configuration.instance_variable_set(:@consumer_middlewares, BugBunny::ConsumerMiddleware::Stack.new)
|
|
163
|
+
BugBunny.configure { |config| config.channel_prefetch = 1 }
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'procesa en la misma vuelta un mensaje que llega dentro de la ventana de inactividad' do
|
|
167
|
+
publish_ping
|
|
168
|
+
sleep 0.3
|
|
169
|
+
|
|
170
|
+
drain_thread = Thread.new { drain }
|
|
171
|
+
sleep 0.5
|
|
172
|
+
publish_ping
|
|
173
|
+
|
|
174
|
+
expect(drain_thread.value).to eq(2)
|
|
175
|
+
expect(messages_in_queue).to eq(0)
|
|
176
|
+
end
|
|
177
|
+
end
|
data/spec/rails/app.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# App Rails mínima para probar el Railtie de BugBunny con Rails de verdad (ActiveRecord sobre SQLite
|
|
4
|
+
# en memoria).
|
|
5
|
+
#
|
|
6
|
+
# Rails se inicializa una vez por proceso, así que estos specs corren en su propio proceso
|
|
7
|
+
# (`rake spec:rails`): la suite de `spec/` sigue probando la gema fuera de Rails. Para bootear con
|
|
8
|
+
# otra configuración, el spec corre este archivo solo, en un subproceso (`ruby spec/rails/app.rb`),
|
|
9
|
+
# y lee la cadena de middlewares que imprime.
|
|
10
|
+
#
|
|
11
|
+
# `BUG_BUNNY_SPEC_EXECUTOR=off` bootea con `config.consumer_rails_executor = false`.
|
|
12
|
+
# `BUG_BUNNY_SPEC_CONFIGURE=none` bootea sin llamar a `BugBunny.configure` ni registrar otros middlewares:
|
|
13
|
+
# la configuración queda la de default.
|
|
14
|
+
|
|
15
|
+
ENV['RAILS_ENV'] = 'test'
|
|
16
|
+
ENV['DATABASE_URL'] = 'sqlite3::memory:'
|
|
17
|
+
|
|
18
|
+
require 'bundler/setup'
|
|
19
|
+
require 'logger'
|
|
20
|
+
require 'rails'
|
|
21
|
+
require 'active_record/railtie'
|
|
22
|
+
require 'bug_bunny'
|
|
23
|
+
|
|
24
|
+
module BugBunnyRailsSpec
|
|
25
|
+
# La app: sin archivos de configuración propios, todo acá.
|
|
26
|
+
class Application < Rails::Application
|
|
27
|
+
config.root = __dir__
|
|
28
|
+
config.eager_load = false
|
|
29
|
+
config.logger = Logger.new(nil)
|
|
30
|
+
config.secret_key_base = 'bug_bunny-rails-spec'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Lo que un mensaje deja por hilo: lo que los specs miran pasar (o no) al siguiente.
|
|
34
|
+
class LeftoverState < ActiveSupport::CurrentAttributes
|
|
35
|
+
attribute :value
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Contexto de traza, como el `ExisRay::Tracer` de ExisRay: un `CurrentAttributes`.
|
|
39
|
+
class TraceContext < ActiveSupport::CurrentAttributes
|
|
40
|
+
attribute :trace_id
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Un middleware que carga estado por hilo antes de procesar el mensaje y lo limpia al salir, como
|
|
44
|
+
# el de tracing de ExisRay. Se registra ANTES de que el Railtie de BugBunny registre el suyo: es el
|
|
45
|
+
# orden que hace falta para ver si el executor lo borra.
|
|
46
|
+
class TracingMiddleware < BugBunny::ConsumerMiddleware::Base
|
|
47
|
+
def call(delivery_info, properties, body)
|
|
48
|
+
TraceContext.trace_id = 'from-tracing'
|
|
49
|
+
@app.call(delivery_info, properties, body)
|
|
50
|
+
ensure
|
|
51
|
+
TraceContext.reset
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
unless ENV['BUG_BUNNY_SPEC_CONFIGURE'] == 'none'
|
|
57
|
+
BugBunny.configure do |config|
|
|
58
|
+
config.logger = Logger.new(nil)
|
|
59
|
+
# El `respond_to?` deja correr estos specs contra una versión de la gema sin la opción, para ver
|
|
60
|
+
# que fallan sin el cambio.
|
|
61
|
+
if config.respond_to?(:consumer_rails_executor=)
|
|
62
|
+
config.consumer_rails_executor = ENV['BUG_BUNNY_SPEC_EXECUTOR'] != 'off'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
BugBunny.consumer_middlewares.use(BugBunnyRailsSpec::TracingMiddleware)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
BugBunnyRailsSpec::Application.initialize!
|
|
69
|
+
|
|
70
|
+
puts BugBunny.consumer_middlewares.instance_variable_get(:@middlewares).map(&:name) if $PROGRAM_NAME == __FILE__
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'rails_helper'
|
|
4
|
+
require 'open3'
|
|
5
|
+
|
|
6
|
+
# Cada mensaje del Consumer corre dentro del executor de Rails (sequre/bug_bunny#70).
|
|
7
|
+
#
|
|
8
|
+
# Las entregas se procesan en un hilo propio, como el hilo de trabajo de Bunny: Rails no lo conoce.
|
|
9
|
+
RSpec.describe 'BugBunny::ConsumerMiddleware::RailsExecutor' do
|
|
10
|
+
let(:channel) do
|
|
11
|
+
double('channel').tap do |ch|
|
|
12
|
+
allow(ch).to receive(:ack)
|
|
13
|
+
allow(ch).to receive(:reject)
|
|
14
|
+
allow(ch).to receive(:open?).and_return(true)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:consumer) do
|
|
19
|
+
session = instance_double(BugBunny::Session, channel: channel, close: nil)
|
|
20
|
+
described_consumer = BugBunny::Consumer.new(double('connection'))
|
|
21
|
+
described_consumer.instance_variable_set(:@session, session)
|
|
22
|
+
described_consumer
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
let(:properties) do
|
|
26
|
+
double('properties', type: 'probe/show', headers: { 'x-http-method' => 'GET' },
|
|
27
|
+
correlation_id: 'corr-1', reply_to: nil, content_type: 'application/json')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Lo que hace la acción del controller en cada entrega.
|
|
31
|
+
let(:on_message) { -> {} }
|
|
32
|
+
|
|
33
|
+
before do
|
|
34
|
+
allow(BugBunny.routes).to receive(:recognize)
|
|
35
|
+
.and_return({ controller: 'probe', action: 'show', params: {}, namespace: nil })
|
|
36
|
+
|
|
37
|
+
handler = on_message
|
|
38
|
+
stub_const('BugBunny::Controllers::ProbeController', Class.new(BugBunny::Controller) do
|
|
39
|
+
define_method(:show) do
|
|
40
|
+
handler.call
|
|
41
|
+
render status: 200, json: {}
|
|
42
|
+
end
|
|
43
|
+
end)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Procesa las entregas en orden, en un hilo propio (como el de Bunny).
|
|
47
|
+
def deliver_on_a_bunny_like_thread(*tags)
|
|
48
|
+
Thread.new do
|
|
49
|
+
tags.each do |tag|
|
|
50
|
+
delivery_info = double('delivery_info', exchange: 'x', routing_key: 'probe', delivery_tag: tag,
|
|
51
|
+
redelivered?: false)
|
|
52
|
+
yield(:before, tag) if block_given?
|
|
53
|
+
consumer.send(:handle_delivery, delivery_info, properties, '{}')
|
|
54
|
+
yield(:after, tag) if block_given?
|
|
55
|
+
end
|
|
56
|
+
end.join
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'queda primero en la cadena, antes del middleware de tracing registrado antes que él' do
|
|
60
|
+
middlewares = BugBunny.consumer_middlewares.instance_variable_get(:@middlewares).map(&:name)
|
|
61
|
+
|
|
62
|
+
expect(middlewares).to eq(%w[BugBunny::ConsumerMiddleware::RailsExecutor BugBunnyRailsSpec::TracingMiddleware])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe 'el estado por hilo no pasa de un mensaje al siguiente' do
|
|
66
|
+
let(:seen) { [] }
|
|
67
|
+
let(:on_message) do
|
|
68
|
+
lambda do
|
|
69
|
+
seen << BugBunnyRailsSpec::LeftoverState.value
|
|
70
|
+
BugBunnyRailsSpec::LeftoverState.value = 'left by the previous message'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'el segundo mensaje arranca sin lo que el primero dejó en un CurrentAttributes' do
|
|
75
|
+
deliver_on_a_bunny_like_thread(1, 2)
|
|
76
|
+
|
|
77
|
+
expect(seen).to eq([nil, nil])
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe 'la conexión de ActiveRecord' do
|
|
82
|
+
# Si el hilo tiene una conexión tomada del pool (en Rails 8.1, `active_connection?` devuelve la
|
|
83
|
+
# conexión, o nil).
|
|
84
|
+
def connection_leased?
|
|
85
|
+
ActiveRecord::Base.connection_pool.active_connection?.present?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
let(:inside) { [] }
|
|
89
|
+
let(:on_message) do
|
|
90
|
+
lambda do
|
|
91
|
+
ActiveRecord::Base.connection.execute('SELECT 1')
|
|
92
|
+
inside << connection_leased?
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'vuelve al pool al terminar el mensaje que la usó' do
|
|
97
|
+
after = []
|
|
98
|
+
deliver_on_a_bunny_like_thread(1) do |moment, _tag|
|
|
99
|
+
after << connection_leased? if moment == :after
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
expect(inside).to eq([true]) # el mensaje la usó
|
|
103
|
+
expect(after).to eq([false]) # y al terminar ya no la tiene el hilo
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe 'un middleware que carga estado antes que el executor' do
|
|
108
|
+
let(:seen) { [] }
|
|
109
|
+
let(:on_message) { -> { seen << BugBunnyRailsSpec::TraceContext.trace_id } }
|
|
110
|
+
|
|
111
|
+
it 'conserva ese estado dentro del mensaje: el executor lo envuelve y no lo borra' do
|
|
112
|
+
deliver_on_a_bunny_like_thread(1)
|
|
113
|
+
|
|
114
|
+
expect(seen).to eq(['from-tracing'])
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe 'un error que escapa del procesamiento del mensaje' do
|
|
119
|
+
let(:reports) { [] }
|
|
120
|
+
let(:subscriber) do
|
|
121
|
+
collected = reports
|
|
122
|
+
Class.new do
|
|
123
|
+
define_method(:report) { |error, handled:, **| collected << [error.message, handled] }
|
|
124
|
+
end.new
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
before { Rails.error.subscribe(subscriber) }
|
|
128
|
+
after { Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe) } # no existe en Rails 7.0
|
|
129
|
+
|
|
130
|
+
it 'termina en un reject sin requeue, como hoy, y además se reporta a Rails.error' do
|
|
131
|
+
allow(consumer).to receive(:process_message).and_raise(RuntimeError, 'boom')
|
|
132
|
+
|
|
133
|
+
deliver_on_a_bunny_like_thread(7)
|
|
134
|
+
|
|
135
|
+
expect(channel).to have_received(:reject).with(7, false)
|
|
136
|
+
expect(reports).to eq([['boom', false]])
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe 'config.consumer_rails_executor' do
|
|
141
|
+
# Rails se inicializa una vez por proceso: la app se bootea de nuevo en un subproceso.
|
|
142
|
+
# Las líneas de stdout que nombran un middleware: un warning del entorno no las rompe.
|
|
143
|
+
def middlewares_after_boot(env)
|
|
144
|
+
app = File.expand_path('app.rb', __dir__)
|
|
145
|
+
stdout, stderr, status = Open3.capture3(env, RbConfig.ruby, app)
|
|
146
|
+
raise "la app no booteó:\n#{stderr}" unless status.success?
|
|
147
|
+
|
|
148
|
+
stdout.lines.map(&:strip).grep(/\ABugBunny/)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'con false, no registra el middleware' do
|
|
152
|
+
expect(middlewares_after_boot('BUG_BUNNY_SPEC_EXECUTOR' => 'off')).to eq(['BugBunnyRailsSpec::TracingMiddleware'])
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'con true, lo registra primero' do
|
|
156
|
+
expect(middlewares_after_boot('BUG_BUNNY_SPEC_EXECUTOR' => 'on'))
|
|
157
|
+
.to eq(%w[BugBunny::ConsumerMiddleware::RailsExecutor BugBunnyRailsSpec::TracingMiddleware])
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it 'sin BugBunny.configure previo, bootea y lo registra: la opción ausente vale su default' do
|
|
161
|
+
expect(middlewares_after_boot('BUG_BUNNY_SPEC_CONFIGURE' => 'none'))
|
|
162
|
+
.to eq(['BugBunny::ConsumerMiddleware::RailsExecutor'])
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -11,7 +11,15 @@ RSpec.describe BugBunny::Configuration do
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# Restaura la configuración de spec_helper (host, credenciales) y no una con defaults:
|
|
15
|
+
# si no, los specs de integración que corren después se conectan como `guest` y se
|
|
16
|
+
# saltean como "RabbitMQ no disponible" en vez de correr.
|
|
17
|
+
around do |example|
|
|
18
|
+
original_configuration = BugBunny.configuration
|
|
19
|
+
example.run
|
|
20
|
+
ensure
|
|
21
|
+
BugBunny.configuration = original_configuration
|
|
22
|
+
end
|
|
15
23
|
|
|
16
24
|
describe 'defaults' do
|
|
17
25
|
it 'pasan validate! sin ninguna configuración adicional' do
|
|
@@ -124,6 +132,24 @@ RSpec.describe BugBunny::Configuration do
|
|
|
124
132
|
end
|
|
125
133
|
end
|
|
126
134
|
|
|
135
|
+
describe 'drain_idle_timeout' do
|
|
136
|
+
it 'levanta ConfigurationError si es 0' do
|
|
137
|
+
expect { configure_with(drain_idle_timeout: 0) }
|
|
138
|
+
.to raise_error(BugBunny::ConfigurationError, /drain_idle_timeout must be in/)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
describe 'drain_poll_interval' do
|
|
143
|
+
it 'acepta fracciones de segundo' do
|
|
144
|
+
expect { configure_with(drain_poll_interval: 0.05) }.not_to raise_error
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'levanta ConfigurationError si es 0' do
|
|
148
|
+
expect { configure_with(drain_poll_interval: 0) }
|
|
149
|
+
.to raise_error(BugBunny::ConfigurationError, /drain_poll_interval must be in/)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
127
153
|
describe 'configuración válida completa' do
|
|
128
154
|
it 'acepta todos los atributos con valores correctos' do
|
|
129
155
|
expect do
|
|
@@ -162,6 +188,12 @@ RSpec.describe BugBunny::Configuration do
|
|
|
162
188
|
end
|
|
163
189
|
end
|
|
164
190
|
|
|
191
|
+
describe 'consumer_rails_executor flag' do
|
|
192
|
+
it 'tiene default true (el Railtie envuelve cada mensaje con el executor de Rails)' do
|
|
193
|
+
expect(BugBunny::Configuration.new.consumer_rails_executor).to be(true)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
165
197
|
describe 'nack_raise flag' do
|
|
166
198
|
it 'tiene default true (raise PublishNacked en NACK)' do
|
|
167
199
|
expect(BugBunny::Configuration.new.nack_raise).to be(true)
|