Skip to content

Possible regression in buffer between 7.0.0-beta.4 and 7.0.0-beta.5 #6035

Closed
@OliverJAsh

Description

Bug Report

Current Behavior
Reduced test case: https://github.com/OliverJAsh/rxjs-v7-buffer-regression

I have the following operator:

import * as RxJS from "rxjs";
import * as RxJSOperators from "rxjs/operators";

// Buffer the values and emit only after a particular time span has passed without another source
// emission.
// Like `bufferTime`, but uses debouncing instead of throttling.
// https://stackoverflow.com/questions/50515357/debounce-and-buffer-an-rxjs-subscription/50519552#50519552
export const bufferDebounce = (ms: number) => <T>(
  source: RxJS.Observable<T>
): RxJS.Observable<T[]> =>
  // The observable will have multiple subscribers, because it is used by both `buffer` and
  // `debounceTime`. We want to share the execution.
  source.pipe(
    RxJSOperators.publish((published) =>
      published.pipe(
        RxJSOperators.buffer(published.pipe(RxJSOperators.debounceTime(ms)))
      )
    )
  );

https://github.com/OliverJAsh/rxjs-v7-buffer-regression/blob/42be6f30c5afa433abebd9d98f09b9da15d3efb2/bufferDebounce.ts#L1-L19

This test passes in v6 and v7.0.0-beta.4 but fails in v7.0.0-beta.5 and above:

  it(
    "works with observable that emits and completes immediately",
    marbles((m) => {
      const source$ = m.cold("(a|)");
      const ms = m.time("     |");
      const expected = "      (1|)";

      const actual$ = source$.pipe(bufferDebounce(ms));
      m.expect(actual$).toBeObservable(expected, { 1: ["a"] });
    })
  );

https://github.com/OliverJAsh/rxjs-v7-buffer-regression/blob/42be6f30c5afa433abebd9d98f09b9da15d3efb2/test.js#L53-L63

The test fails with:

  ● bufferDebounce › works with observable that emits and completes immediately

    expect(received).toStrictEqual(expected) // deep equality

    - Expected  - 10
    + Received  +  0

      Array [
        Object {
          "frame": 0,
          "notification": Object {
            "error": undefined,
    -       "kind": "N",
    -       "value": Array [
    -         "a",
    -       ],
    -     },
    -   },
    -   Object {
    -     "frame": 0,
    -     "notification": Object {
    -       "error": undefined,
            "kind": "C",
            "value": undefined,
          },
        },
      ]

I believe this is due to #5654 but I'm not sure if this is intentional.

Expected behavior
The test passes like it did before v7.0.0-beta.5.

Reproduction
See above

Activity

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

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions