Skip to content
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

rpoplpush should rotate the list when source and destination are the same #1320

Closed
mgrunberg opened this issue Sep 18, 2023 · 0 comments · Fixed by #1321
Closed

rpoplpush should rotate the list when source and destination are the same #1320

mgrunberg opened this issue Sep 18, 2023 · 0 comments · Fixed by #1321

Comments

@mgrunberg
Copy link
Contributor

When same source and destination are provided rpoplpush should rotate the list. Instead, it is prepending the last element.

Code example:

const Redis = require("ioredis");
const RedisMock = require("ioredis-mock");
const assert = require("assert");

const redis = new Redis();
const redisMock = new RedisMock();

const testEquality = async () => {
  await redis.rpush("list", 1);
  await redis.rpush("list", 2);
  await redis.rpush("list", 3);
  await redisMock.rpush("list", 1);
  await redisMock.rpush("list", 2);
  await redisMock.rpush("list", 3);

  const pop = await redis.rpoplpush("list", "list");
  const popMock = await redisMock.rpoplpush("list", "list");

  const list = await redis.lrange("list", 0, -1);
  const listMock = await redisMock.lrange("list", 0, -1);

  await redis.flushall();
  await redisMock.flushall();
  await redis.quit();
  await redisMock.quit();

  assert(
    pop === popMock,
    `expected <${popMock.constructor.name}>(${popMock}) to equal <${pop.constructor.name}>(${pop})`
  );
  assert(
    list === listMock,
    `expected <${listMock.constructor.name}>(${listMock}) to equal <${list.constructor.name}>(${list})`
  );
  return "Success";
};

testEquality().then(console.log).catch(console.error);

Output:

AssertionError [ERR_ASSERTION]: expected <Array>(3,1,2,3) to equal <Array>(3,1,2)
    at testEquality (/home/matias/dev/workspace/ioredis-mock-example/index.js:31:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant