Skip to content

Commit

Permalink
Merge branch 'main' into renovate/non-major
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Sep 29, 2023
2 parents 61ee0ef + d4724e1 commit 2161d2d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ jobs:
node: [lts/*]
# It makes sense to also test the oldest, and latest, versions of Node.js, on ubuntu-only since it's the fastest CI runner
include:
- os: ubuntu-latest
# Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
node: lts/-2
- os: ubuntu-latest
# Also test the previous LTS release
node: lts/-1
Expand Down
11 changes: 9 additions & 2 deletions src/commands/rpoplpush.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ export function rpoplpush(source, destination) {
const newSource = this.data.get(source)
const item = newSource.pop()

const newDest = this.data.get(destination)
let newDest = newSource // Operate on the same list
if (source !== destination) {
// Operate on two different lists
newDest = this.data.get(destination)
}

newDest.unshift(item)

this.data.set(source, newSource)
this.data.set(destination, newDest)
if (newSource !== newDest) {
this.data.set(destination, newDest)
}

return item
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/xread.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function xread(option, ...args) {
// [["stream1", "id1"], ["stream2", "id2"]]
const half = Math.ceil(rest.length / 2)
const streamsHalf = rest.slice(0, half)
const toPoll = streamsHalf.map((ele, index) => [ele, rest[half+index]])
const toPoll = streamsHalf.map((ele, index) => [ele, rest[half + index]])

const pollStream = (stream, id, count = 1) => {
const data = this.data.get(stream)
Expand Down
18 changes: 18 additions & 0 deletions test/integration/commands/rpoplpush.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,23 @@ runTwinSuite('rpoplpush', (command, equals) => {
)
}
)

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should rotate the list if the source and destination are the same',
async () => {
const redis = new Redis({
data: {
foo: ['1', '2'],
},
})

const result = await redis[command]('foo', 'foo', 'LEFT', 'RIGHT')
expect(result).toBe('2')

const list = await redis.lrange('foo', 0, -1)
expect(list).toEqual(['2', '1'])
}
)
})
})
54 changes: 29 additions & 25 deletions test/integration/commands/xread.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,33 +177,37 @@ describe('xread', () => {
})
})

it('should block until data is provided and return', () => {
const redis = new Redis()
const before = performance.now()
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should block until data is provided and return',
() => {
const redis = new Redis()
const before = performance.now()

setTimeout(() => {
return redis.xadd('empty-stream-2', '*', 'key', 'val')
}, 100)
setTimeout(() => {
return redis.xadd('empty-stream-2', '*', 'key', 'val')
}, 100)

return redis
.xread(
'BLOCK',
'500',
'STREAMS',
'empty-stream',
'empty-stream-2',
'$',
'$'
)
.then(row => {
const after = performance.now()
expect(after - before >= 100).toBe(true)
expect(row).toEqual([
['empty-stream-2', [['1-0', ['key', 'val']]]],
['empty-stream', []],
])
})
})
return redis
.xread(
'BLOCK',
'500',
'STREAMS',
'empty-stream',
'empty-stream-2',
'$',
'$'
)
.then(row => {
const after = performance.now()
expect(after - before >= 100).toBe(true)
expect(row).toEqual([
['empty-stream-2', [['1-0', ['key', 'val']]]],
['empty-stream', []],
])
})
}
)

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
Expand Down

0 comments on commit 2161d2d

Please sign in to comment.