Skip to content

fix(base): keep prefetchCount default when config.channel is empty - #54

Open
arsalan507 wants to merge 1 commit into
bitrix24:mainfrom
arsalan507:fix/prefetch-default-merge
Open

fix(base): keep prefetchCount default when config.channel is empty#54
arsalan507 wants to merge 1 commit into
bitrix24:mainfrom
arsalan507:fix/prefetch-default-merge

Conversation

@arsalan507

Copy link
Copy Markdown

Summary

Fixes #30.

RabbitMQBase's constructor built the merged config as:

this.config = {
  channel: { prefetchCount: 1 },
  ...config
}

Because ...config is a top-level spread, any caller-supplied channel key — even a present-but-empty channel: {} — replaces the default object wholesale instead of merging into it. prefetchCount is silently dropped, and channel.prefetch(this.config.channel!.prefetchCount!) in Consumer.connect() ends up calling channel.prefetch(undefined).

Fix

Merge channel key-by-key instead of spreading the whole config over the default:

this.config = {
  ...config,
  channel: { prefetchCount: 1, ...config.channel }
}

Now the default only fills in keys the caller didn't set, matching the merge convention already used for queue arguments in registerQueue().

Test plan

  • Added a regression test (tests/consumer.test.ts) that constructs a consumer with channel: {} and asserts channel.prefetch is called with the default 1. Verified it fails against the pre-fix code (channel.prefetch called with undefined) and passes after the fix.
  • Added a companion test asserting an explicit prefetchCount still overrides the default.
  • pnpm lint, pnpm typecheck, pnpm test (77 passing), pnpm build all green.

The constructor merged the default channel object with the caller's
config via `{ channel: { prefetchCount: 1 }, ...config }`. Any
caller-supplied `channel` key, even an empty `{}`, replaced the
default object wholesale via the top-level spread, silently dropping
prefetchCount and leaving `channel.prefetch(undefined)` on connect.

Merge `channel` key-by-key instead, so the default only fills in keys
the caller didn't set.

Fixes bitrix24#30
@arsalan507

Copy link
Copy Markdown
Author

Friendly ping — the CI runs on #54, #55 and #56 are all sitting at action_required (first-time-contributor workflow approval), so the required ci check can't report. If you approve the workflow runs they should go green on their own; each PR is scoped to a single issue (#30, #27, #28) with a regression test verified failing before the fix and passing after. Happy to rebase or split further if that's easier to review.

@arsalan507

Copy link
Copy Markdown
Author

Hi Igor — thanks again for the #385 review, and for the GB9 catch. I'd have carried that mislabelled fixture forward otherwise.

While you're in this corner of things: #54, #55 and #56 here are still waiting on the first-time-contributor workflow approval, so CI has never actually run on any of them. There's nothing to review yet — it's one click on "Approve and run workflows" and they'll either go green or tell us something useful.

They're small and independent: #54 restores the prefetchCount default when a caller passes channel: {}, #55 stops disconnect() re-arming the reconnect loop, #56 attaches the missing 'error' listeners on connections and channels. Each has a regression test that fails on main.

No rush if this repo isn't a priority right now — just flagging that they're stuck on the gate rather than on anything I can do from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(base): passing channel: {} silently disables prefetch — shallow config merge drops the prefetchCount default

1 participant